Skip to content

Commit b902053

Browse files
committed
Speed up samples tests by not comparing individual pixels but image content directly
1 parent 75b7951 commit b902053

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

tests/Samples/SamplesTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,18 @@ private static function assertImage(string $expectedImagePath, string $actualIma
7575
throw new RuntimeException(sprintf('Unable to load actual image "%s"', $imageName));
7676
}
7777

78-
static::assertSame(imagesx($expectedImage), imagesx($actualImage), $imageName);
79-
static::assertSame(imagesy($expectedImage), imagesy($actualImage), $imageName);
80-
for ($x = 0; $x < imagesx($expectedImage); $x++) {
81-
for ($y = 0; $y < imagesy($expectedImage); $y++) {
82-
static::assertSame(
83-
imagecolorat($expectedImage, $x, $y),
84-
imagecolorat($actualImage, $x, $y),
85-
$imageName,
86-
);
87-
}
88-
}
78+
ob_start();
79+
imagepng($expectedImage, null, 9);
80+
$normalizedExpected = ob_get_clean();
81+
82+
ob_start();
83+
imagepng($actualImage, null, 9);
84+
$normalizedActual = ob_get_clean();
85+
86+
static::assertSame(
87+
$normalizedExpected,
88+
$normalizedActual,
89+
$imageName,
90+
);
8991
}
9092
}

0 commit comments

Comments
 (0)