Skip to content

Commit

Permalink
Make imagebmp_basic.phpt more resilient (GH-17265)
Browse files Browse the repository at this point in the history
Checking for the exact output of most image formats is brittle; even an
otherwise change to some header field causes the output to change, even
if the image would be visually identical.

Checking for an (MD5) hash is even worse, since if the tests fails, we
have no clue for what reason.

Thus we compare the generated image against an pre-generated PNG, using
a test helper which will output a simple image diff in case of test
failure.
  • Loading branch information
cmb69 authored Dec 25, 2024
1 parent 1331444 commit c1c6520
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions ext/gd/tests/imagebmp_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
imageline($im, 10,10, 89,89, $white);

// write the md5 hash of its BMP representation
ob_start();
imagebmp($im);
echo md5(ob_get_clean());
require __DIR__ . "/func.inc";
test_image_equals_file(__DIR__ . "/imagebmp_basic.png", $im);
?>
--EXPECT--
d49124076771822b09fa72e168c0de56
The images are equal.
Binary file added ext/gd/tests/imagebmp_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c1c6520

Please sign in to comment.