1
1
<?php
2
2
/**
3
- * Class QRCodeReaderTest
3
+ * Class QRCodeReaderTestAbstract
4
4
*
5
5
* @created 17.01.2021
6
6
* @author Smiley <[email protected] >
16
16
use Exception , Generator ;
17
17
use chillerlan \QRCode \Common \{EccLevel , Mode , Version };
18
18
use chillerlan \QRCode \{QRCode , QROptions };
19
- use chillerlan \QRCode \Decoder \{GDLuminanceSource , IMagickLuminanceSource };
20
19
use PHPUnit \Framework \TestCase ;
21
- use function extension_loaded , range , sprintf , str_repeat , substr ;
20
+ use function range , sprintf , str_repeat , substr ;
22
21
23
22
/**
24
23
* Tests the QR Code reader
25
24
*/
26
- final class QRCodeReaderTest extends TestCase{
25
+ abstract class QRCodeReaderTestAbstract extends TestCase{
27
26
28
27
// https://www.bobrosslipsum.com/
29
28
protected const loremipsum = 'Just let this happen. We just let this flow right out of our minds. '
@@ -35,9 +34,11 @@ final class QRCodeReaderTest extends TestCase{
35
34
.'to upset the critics. We \'ll lay all these little funky little things in there. ' ;
36
35
37
36
protected SettingsContainerInterface $ options ;
37
+ protected string $ FQN ;
38
38
39
39
protected function setUp ():void {
40
40
$ this ->options = new QROptions ;
41
+ $ this ->options ->readerUseImagickIfAvailable = false ;
41
42
}
42
43
43
44
public function qrCodeProvider ():array {
@@ -68,33 +69,16 @@ public function qrCodeProvider():array{
68
69
/**
69
70
* @dataProvider qrCodeProvider
70
71
*/
71
- public function testReaderGD (string $ img , string $ expected , bool $ grayscale ):void {
72
+ public function testReader (string $ img , string $ expected , bool $ grayscale ):void {
72
73
73
74
if ($ grayscale ){
74
75
$ this ->options ->readerGrayscale = true ;
75
76
$ this ->options ->readerIncreaseContrast = true ;
76
77
}
77
78
79
+ /** @noinspection PhpUndefinedMethodInspection */
78
80
$ this ::assertSame ($ expected , (string )(new QRCode )
79
- ->readFromSource (GDLuminanceSource::fromFile (__DIR__ .'/samples/ ' .$ img , $ this ->options )));
80
- }
81
-
82
- /**
83
- * @dataProvider qrCodeProvider
84
- */
85
- public function testReaderImagick (string $ img , string $ expected , bool $ grayscale ):void {
86
-
87
- if (!extension_loaded ('imagick ' )){
88
- $ this ::markTestSkipped ('imagick not installed ' );
89
- }
90
-
91
- if ($ grayscale ){
92
- $ this ->options ->readerGrayscale = true ;
93
- $ this ->options ->readerIncreaseContrast = true ;
94
- }
95
-
96
- $ this ::assertSame ($ expected , (string )(new QRCode )
97
- ->readFromSource (IMagickLuminanceSource::fromFile (__DIR__ .'/samples/ ' .$ img , $ this ->options )));
81
+ ->readFromSource ($ this ->FQN ::fromFile (__DIR__ .'/samples/ ' .$ img , $ this ->options )));
98
82
}
99
83
100
84
public function testReaderMultiSegment ():void {
@@ -136,17 +120,16 @@ public function dataTestProvider():Generator{
136
120
* @dataProvider dataTestProvider
137
121
*/
138
122
public function testReadData (Version $ version , EccLevel $ ecc , string $ expected ):void {
139
- $ this ->options ->outputType = QRCode::OUTPUT_IMAGE_PNG ;
140
- # $this->options->imageTransparent = false;
141
- $ this ->options ->eccLevel = $ ecc ->getLevel ();
142
- $ this ->options ->version = $ version ->getVersionNumber ();
143
- $ this ->options ->imageBase64 = false ;
144
- $ this ->options ->readerUseImagickIfAvailable = true ;
123
+ $ this ->options ->outputType = QRCode::OUTPUT_IMAGE_PNG ;
124
+ $ this ->options ->imageTransparent = false ;
125
+ $ this ->options ->eccLevel = $ ecc ->getLevel ();
126
+ $ this ->options ->version = $ version ->getVersionNumber ();
127
+ $ this ->options ->imageBase64 = false ;
145
128
// what's interesting is that a smaller scale seems to produce fewer reader errors???
146
129
// usually from version 20 up, independend of the luminance source
147
130
// scale 1-2 produces none, scale 3: 1 error, scale 4: 6 errors, scale 5: 5 errors, scale 10: 10 errors
148
131
// @see \chillerlan\QRCode\Detector\GridSampler::checkAndNudgePoints()
149
- $ this ->options ->scale = 2 ;
132
+ $ this ->options ->scale = 2 ;
150
133
151
134
try {
152
135
$ qrcode = new QRCode ($ this ->options );
0 commit comments