Skip to content

Commit

Permalink
Fix: Normalize lock file in tests to account for different plugin API
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Apr 26, 2020
1 parent 6d4af4c commit b829d43
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
19 changes: 17 additions & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
<code>$composerFile</code>
<code>$diff</code>
</MixedArgument>
<MixedAssignment occurrences="7">
<code>$composerFile</code>
<MixedAssignment occurrences="6">
<code>$composerFile</code>
<code>$composer</code>
<code>$locker</code>
Expand All @@ -45,9 +44,25 @@
<code>isLocked</code>
<code>diff</code>
</MixedMethodCall>
<PossiblyInvalidArgument occurrences="8">
<code>$composerFile</code>
<code>$composerFile</code>
<code>$composerFile</code>
<code>$composerFile</code>
<code>$composerFile</code>
<code>$composerFile</code>
<code>$composerFile</code>
<code>$composerFile</code>
</PossiblyInvalidArgument>
</file>
<file src="test/Integration/Command/NormalizeCommandTest.php">
<MixedArgumentTypeCoercion occurrences="2"/>
<MixedArrayAccess occurrences="1">
<code>$decoded['plugin-api-version']</code>
</MixedArrayAccess>
<MixedAssignment occurrences="1">
<code>$decoded</code>
</MixedAssignment>
<MixedInferredReturnType occurrences="3">
<code>\Generator&lt;array&lt;CommandInvocation&gt;&gt;</code>
<code>\Generator&lt;array{0: CommandInvocation, 1: string}&gt;</code>
Expand Down
29 changes: 25 additions & 4 deletions test/Integration/Command/NormalizeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,8 @@ private static function assertComposerLockFileModified(State $expected, State $a
self::assertComposerLockFileExists($actual);

self::assertJsonStringNotEqualsJsonString(
$expected->composerLockFile()->contents(),
$actual->composerLockFile()->contents(),
self::normalizeLockFileContents($expected->composerLockFile()->contents()),
self::normalizeLockFileContents($actual->composerLockFile()->contents()),
'Failed asserting that initial composer.lock has been modified.'
);
}
Expand All @@ -1071,12 +1071,33 @@ private static function assertComposerLockFileNotModified(State $expected, State
self::assertComposerLockFileExists($actual);

self::assertJsonStringEqualsJsonString(
$expected->composerLockFile()->contents(),
$actual->composerLockFile()->contents(),
self::normalizeLockFileContents($expected->composerLockFile()->contents()),
self::normalizeLockFileContents($actual->composerLockFile()->contents()),
'Failed asserting that initial composer.lock has not been modified.'
);
}

private static function normalizeLockFileContents(string $contents): string
{
$decoded = \json_decode(
$contents,
true
);

unset($decoded['plugin-api-version']);

$normalized = \json_encode(
$decoded,
\JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_PRESERVE_ZERO_FRACTION
);

if (!\is_string($normalized)) {
throw new \RuntimeException('Failed normalizing contents of lock file.');
}

return $normalized;
}

private static function clearTemporaryDirectory(): void
{
$fileSystem = new Filesystem\Filesystem();
Expand Down

0 comments on commit b829d43

Please sign in to comment.