Skip to content

Commit 72c01a0

Browse files
committed
fix: base.php
1 parent 6fa5f60 commit 72c01a0

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

tests/Base.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,19 @@ public function testHTTPSuccess(): void
204204

205205
echo \implode("\n", $output);
206206

207-
# Some languages deserialize JSON with sorted keys, other not.
208-
# We use this custom assertion to normalise the lines with JSON before comparison.
209-
$this->assertEqualsWithJsonLines($this->expectedOutput, $output);
207+
$this->assertEquals([], \array_diff(
208+
$this->normalizeConsoleLines($output),
209+
$this->normalizeConsoleLines($this->expectedOutput)
210+
));
210211
}
211212

212-
private function assertEqualsWithJsonLines($expectedLines, $actualLines)
213-
{
214-
for ($i = 0; $i < \count($expectedLines); $i++) {
215-
$this->assertArrayHasKey($i, $actualLines, "Missing line {$i}: {$expectedLines[$i]}");
216-
217-
$expectedLine = $expectedLines[$i];
218-
$actualLine = $actualLines[$i];
219-
220-
if (\str_starts_with($expectedLine, '{')) {
221-
$this->assertEquals(\json_decode($expectedLine), \json_decode($actualLine));
222-
} else {
223-
$this->assertEquals($expectedLine, $actualLine);
213+
private function normalizeConsoleLines($lines) {
214+
return \array_map(function (string $line) {
215+
if (\str_starts_with($line, '{')) {
216+
return \json_decode($line);
224217
}
225-
}
218+
return $line;
219+
}, $lines);
226220
}
227221

228222
private function rmdirRecursive($dir): void

0 commit comments

Comments
 (0)