Skip to content

Commit

Permalink
Fix: Assert that composer.lock is updated after normalization when ne…
Browse files Browse the repository at this point in the history
…cessary
  • Loading branch information
localheinz committed Dec 24, 2018
1 parent 591535d commit 543bb46
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/Integration/NormalizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 543bb46

Please sign in to comment.