Skip to content

Commit 799cefa

Browse files
committed
test: use specific snapshot matchers to avoid platform discrepancies
1 parent 1e00ebd commit 799cefa

24 files changed

Lines changed: 123 additions & 45 deletions

.github/workflows/ci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ jobs:
3636
extensions: iconv, imagick, gd
3737
coverage: xdebug
3838

39+
- name: Setup Node
40+
uses: actions/setup-node@v6
41+
with:
42+
node-version: 24
43+
3944
- name: Get composer cache directory
4045
id: composer-cache
4146
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
@@ -47,9 +52,12 @@ jobs:
4752
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
4853
restore-keys: ${{ runner.os }}-composer-
4954

50-
- name: Install dependencies
55+
- name: Install PHP dependencies
5156
run: composer install --no-progress --prefer-dist --optimize-autoloader
5257

58+
- name: Install Node dependencies
59+
run: npm install
60+
5361
- name: Test with phpunit
5462
run: vendor/bin/phpunit --coverage-clover clover.xml
5563

@@ -58,7 +66,7 @@ jobs:
5866
with:
5967
token: ${{ secrets.CODECOV_TOKEN }}
6068
files: ./clover.xml
61-
69+
6270
release:
6371
needs: [lint, test]
6472
runs-on: ubuntu-latest

.github/workflows/pull-request.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
matrix:
2626
operating-system: [ubuntu-latest]
27-
php-versions: ['8.1', '8.2', '8.3']
27+
php-versions: ['8.1', '8.2', '8.3', '8.4']
2828
runs-on: ${{ matrix.operating-system }}
2929
steps:
3030
- uses: actions/checkout@v4
@@ -36,6 +36,11 @@ jobs:
3636
extensions: iconv, imagick
3737
coverage: xdebug
3838

39+
- name: Setup Node
40+
uses: actions/setup-node@v6
41+
with:
42+
node-version: 24
43+
3944
- name: Get composer cache directory
4045
id: composer-cache
4146
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
@@ -47,9 +52,12 @@ jobs:
4752
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
4853
restore-keys: ${{ runner.os }}-composer-
4954

50-
- name: Install dependencies
55+
- name: Install PHP dependencies
5156
run: composer install --no-progress --prefer-dist --optimize-autoloader
5257

58+
- name: Install Node dependencies
59+
run: npm install
60+
5361
- name: Test with phpunit
5462
run: vendor/bin/phpunit --coverage-clover clover.xml
5563

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/composer.lock
22
/vendor
3+
/node_modules
34
/.phpunit.result.cache
45
/.phpunit.cache

Dockerfile

Lines changed: 0 additions & 8 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017, Ben Scholzen 'DASPRiD'
1+
Copyright (c) 2017-present, Ben Scholzen 'DASPRiD'
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,8 @@ $renderer = new GDLibRenderer(400);
5555
$writer = new Writer($renderer);
5656
$writer->writeFile('Hello World!', 'qrcode.png');
5757
```
58+
59+
## Development
60+
61+
To run unit tests, you need to have [Node.js](https://nodejs.org/en) and the pixelmatch library installed. Running
62+
`npm install` will install this for you.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"require-dev": {
3333
"phpunit/phpunit": "^10.5.11 || ^11.0.4",
3434
"spatie/phpunit-snapshot-assertions": "^5.1.5",
35+
"spatie/pixelmatch-php": "^1.2.0",
3536
"squizlabs/php_codesniffer": "^3.9",
3637
"phly/keep-a-changelog": "^2.12"
3738
},

package-lock.json

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "baconqrcode",
3+
"private": true,
4+
"dependencies": {
5+
"pixelmatch": "^7.1.0"
6+
}
7+
}

test/Integration/GDLibRenderingTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,14 @@
55
namespace BaconQrCodeTest\Integration;
66

77
use BaconQrCode\Exception\InvalidArgumentException;
8-
use BaconQrCode\Exception\RuntimeException;
98
use BaconQrCode\Renderer\Color\Alpha;
109
use BaconQrCode\Renderer\Color\Rgb;
11-
use BaconQrCode\Renderer\Eye\EyeInterface;
12-
use BaconQrCode\Renderer\Eye\SimpleCircleEye;
13-
use BaconQrCode\Renderer\Eye\SquareEye;
1410
use BaconQrCode\Renderer\GDLibRenderer;
15-
use BaconQrCode\Renderer\ImageRenderer;
1611
use BaconQrCode\Renderer\Image\GDImageBackEnd;
17-
use BaconQrCode\Renderer\Module\DotsModule;
18-
use BaconQrCode\Renderer\Module\RoundnessModule;
1912
use BaconQrCode\Renderer\RendererStyle\EyeFill;
2013
use BaconQrCode\Renderer\RendererStyle\Fill;
2114
use BaconQrCode\Renderer\RendererStyle\Gradient;
2215
use BaconQrCode\Renderer\RendererStyle\GradientType;
23-
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
2416
use BaconQrCode\Writer;
2517
use PHPUnit\Framework\Attributes\Group;
2618
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
@@ -40,7 +32,7 @@ public function testGenericQrCode(): void
4032
$tempName = tempnam(sys_get_temp_dir(), 'test') . '.png';
4133
$writer->writeFile('Hello World!', $tempName);
4234

43-
$this->assertMatchesFileSnapshot($tempName);
35+
$this->assertMatchesImageSnapshot($tempName);
4436
unlink($tempName);
4537
}
4638

@@ -64,7 +56,7 @@ public function testDifferentColorsQrCode(): void
6456
$tempName = tempnam(sys_get_temp_dir(), 'test') . '.png';
6557
$writer->writeFile('Hello World!', $tempName);
6658

67-
$this->assertMatchesFileSnapshot($tempName);
59+
$this->assertMatchesImageSnapshot($tempName);
6860
unlink($tempName);
6961
}
7062

0 commit comments

Comments
 (0)