mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 08:58:35 +00:00
Improve QR code image testing with pixel-level comparison
Co-authored-by: jakeb994 <jakeb994@gmail.com>
This commit is contained in:
parent
6ca9cbf3d7
commit
b1199c8cdd
2 changed files with 29 additions and 4 deletions
|
|
@ -347,7 +347,7 @@ trait AvatarsBase
|
|||
$this->assertEquals(400, $image->getImageWidth());
|
||||
$this->assertEquals(400, $image->getImageHeight());
|
||||
$this->assertEquals('PNG', $image->getImageFormat());
|
||||
$this->assertEquals(9086, strlen($response['body']));
|
||||
\Appwrite\Tests\ImageAssertions::assertSamePixels(__DIR__ . '/../../../resources/qr/qr-default.png', $response['body']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
|
|
@ -365,7 +365,7 @@ trait AvatarsBase
|
|||
$this->assertEquals(200, $image->getImageWidth());
|
||||
$this->assertEquals(200, $image->getImageHeight());
|
||||
$this->assertEquals('PNG', $image->getImageFormat());
|
||||
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200.png')), strlen($response['body']));
|
||||
\Appwrite\Tests\ImageAssertions::assertSamePixels(__DIR__ . '/../../../resources/qr/qr-size-200.png', $response['body']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
|
|
@ -384,7 +384,7 @@ trait AvatarsBase
|
|||
$this->assertEquals(200, $image->getImageWidth());
|
||||
$this->assertEquals(200, $image->getImageHeight());
|
||||
$this->assertEquals('PNG', $image->getImageFormat());
|
||||
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png')), strlen($response['body']));
|
||||
\Appwrite\Tests\ImageAssertions::assertSamePixels(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png', $response['body']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
|
|
@ -400,7 +400,7 @@ trait AvatarsBase
|
|||
$this->assertEquals(200, $image->getImageWidth());
|
||||
$this->assertEquals(200, $image->getImageHeight());
|
||||
$this->assertEquals('PNG', $image->getImageFormat());
|
||||
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png')), strlen($response['body']));
|
||||
\Appwrite\Tests\ImageAssertions::assertSamePixels(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png', $response['body']);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('attachment; filename="qr.png"', $response['headers']['content-disposition']);
|
||||
|
|
|
|||
25
tests/extensions/ImageAssertions.php
Normal file
25
tests/extensions/ImageAssertions.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
final class ImageAssertions
|
||||
{
|
||||
public static function assertSamePixels(string $expectedImagePath, string $actualImageBlob): void
|
||||
{
|
||||
$expected = new \Imagick($expectedImagePath);
|
||||
$actual = new \Imagick();
|
||||
$actual->readImageBlob($actualImageBlob);
|
||||
|
||||
foreach ([$expected, $actual] as $image) {
|
||||
// Normalize to PNG and strip metadata to avoid nondeterministic chunks
|
||||
$image->setImageFormat('PNG');
|
||||
$image->stripImage();
|
||||
// Exclude time and profile chunks that vary between builds
|
||||
$image->setOption('png:exclude-chunks', 'date,time,iCCP,sRGB,gAMA,cHRM');
|
||||
}
|
||||
|
||||
Assert::assertSame($expected->getImageSignature(), $actual->getImageSignature());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue