From 543bb46c3ca8361bf65ef5cf22c5fd4a5b4e6c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 24 Dec 2018 10:52:15 +0100 Subject: [PATCH] Fix: Assert that composer.lock is updated after normalization when necessary --- test/Integration/NormalizeTest.php | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/test/Integration/NormalizeTest.php b/test/Integration/NormalizeTest.php index e9588cc1..ae58139f 100644 --- a/test/Integration/NormalizeTest.php +++ b/test/Integration/NormalizeTest.php @@ -709,6 +709,56 @@ public function testSucceedsWhenComposerJsonIsPresentAndValidAndComposerLockIsPr self::assertComposerLockFileNotModified($initialState, $currentState); } + /** + * @dataProvider providerCommandInvocation + * + * @param CommandInvocation $commandInvocation + */ + public function testSucceedsWhenComposerJsonIsPresentAndValidAndComposerLockIsPresentAndFreshBeforeAndComposerJsonIsNotYetNormalizedAndComposerLockIsNotFreshAfter(CommandInvocation $commandInvocation): void + { + $scenario = $this->createScenario( + $commandInvocation, + __DIR__ . '/../Fixture/json/valid/lock/present/lock/fresh-before/json/not-yet-normalized/lock/not-fresh-after' + ); + + $initialState = $scenario->initialState(); + + self::assertComposerJsonFileExists($initialState); + self::assertComposerLockFileExists($initialState); + self::assertComposerLockFileFresh($initialState); + + $application = $this->createApplication(new NormalizeCommand( + new Factory(), + new ComposerJsonNormalizer(), + new Formatter(), + new Differ() + )); + + $input = new Console\Input\ArrayInput($scenario->consoleParameters()); + + $output = new Console\Output\BufferedOutput(); + + $exitCode = $application->run( + $input, + $output + ); + + self::assertExitCodeSame(0, $exitCode); + + $expected = \sprintf( + 'Successfully normalized %s.', + $scenario->composerJsonFileReference() + ); + + self::assertContains($expected, $output->fetch()); + + $currentState = $scenario->currentState(); + + self::assertComposerJsonFileModified($initialState, $currentState); + self::assertComposerLockFileModified($initialState, $currentState); + self::assertComposerLockFileFresh($currentState); + } + /** * @dataProvider providerCommandInvocation * @@ -989,6 +1039,17 @@ private static function assertComposerLockFileNotFresh(State $state): void )); } + private static function assertComposerLockFileModified(State $expected, State $actual): void + { + self::assertComposerLockFileExists($actual); + + self::assertJsonStringNotEqualsJsonString( + $expected->composerLockFile()->contents(), + $actual->composerLockFile()->contents(), + 'Failed asserting that initial composer.lock has been modified.' + ); + } + private static function assertComposerLockFileNotModified(State $expected, State $actual): void { self::assertComposerLockFileExists($actual);