11
11
namespace chillerlan \QRCodeTest \Data ;
12
12
13
13
use chillerlan \QRCode \QROptions ;
14
- use chillerlan \QRCode \Common \{BitBuffer , ECICharset , MaskPattern , Mode };
15
- use chillerlan \QRCode \Data \{Byte , ECI , Number , QRCodeDataException , QRData , QRDataModeInterface , QRMatrix };
14
+ use chillerlan \QRCode \Common \{BitBuffer , ECICharset , Mode };
15
+ use chillerlan \QRCode \Data \{Byte , ECI , Number , QRCodeDataException , QRData , QRDataModeInterface };
16
+ use PHPUnit \Framework \TestCase ;
16
17
17
18
/**
18
19
* Tests the ECI class
19
20
*/
20
- final class ECITest extends DataInterfaceTestAbstract {
21
+ final class ECITest extends TestCase {
21
22
22
- protected string $ FQN = ECI ::class ;
23
+ protected QRData $ QRData ;
23
24
protected string $ testdata = '无可奈何燃花作香 ' ;
24
25
private int $ testCharset = ECICharset::GB18030 ;
25
26
27
+ protected function setUp ():void {
28
+ $ this ->QRData = new QRData (new QROptions );
29
+ }
30
+
26
31
private function getDataSegments ():array {
27
32
return [
28
- new $ this -> FQN ($ this ->testCharset ),
33
+ new ECI ($ this ->testCharset ),
29
34
new Byte (mb_convert_encoding ($ this ->testdata , ECICharset::MB_ENCODINGS [$ this ->testCharset ], mb_internal_encoding ())),
30
35
];
31
36
}
32
37
33
- public static function stringValidateProvider ():array {
34
- return [];
35
- }
36
-
37
38
/** @inheritDoc */
38
39
public function testDataModeInstance ():void {
39
- $ datamode = new $ this -> FQN ($ this ->testCharset );
40
+ $ datamode = new ECI ($ this ->testCharset );
40
41
41
42
$ this ::assertInstanceOf (QRDataModeInterface::class, $ datamode );
42
43
}
43
44
44
45
/**
45
- * @inheritDoc
46
- * @dataProvider maskPatternProvider
46
+ * returns versions within the version breakpoints 1-9, 10-26 and 27-40
47
47
*/
48
- public function testInitMatrix (int $ maskPattern ):void {
49
- $ segments = $ this ->getDataSegments ();
50
-
51
- $ this ->QRData ->setData ($ segments );
52
-
53
- $ matrix = $ this ->QRData ->writeMatrix (new MaskPattern ($ maskPattern ));
54
-
55
- $ this ::assertInstanceOf (QRMatrix::class, $ matrix );
56
- $ this ::assertSame ($ maskPattern , $ matrix ->maskPattern ()->getPattern ());
57
- }
58
-
59
- /** @inheritDoc */
60
- public function testGetMinimumVersion ():void {
61
- /** @noinspection PhpUnitTestFailedLineInspection */
62
- $ this ::markTestSkipped ('N/A (ECI mode) ' );
63
- }
64
-
65
- /** @inheritDoc */
66
- public function testBinaryStringInvalid ():void {
67
- /** @noinspection PhpUnitTestFailedLineInspection */
68
- $ this ::markTestSkipped ('N/A (ECI mode) ' );
48
+ public static function versionBreakpointProvider ():array {
49
+ return ['1-9 ' => [7 ], '10-26 ' => [15 ], '27-40 ' => [30 ]];
69
50
}
70
51
71
52
/**
@@ -86,28 +67,15 @@ public function testDecodeSegment(int $version):void{
86
67
// read the first 4 bits
87
68
$ this ::assertSame ($ segments [0 ]::DATAMODE , $ bitBuffer ->read (4 ));
88
69
// decode the data
89
- /** @noinspection PhpUndefinedMethodInspection */
90
- $ this ::assertSame ($ this ->testdata , $ this ->FQN ::decodeSegment ($ bitBuffer , $ options ->version ));
91
- }
92
-
93
- /** @inheritDoc */
94
- public function testGetMinimumVersionException ():void {
95
- /** @noinspection PhpUnitTestFailedLineInspection */
96
- $ this ::markTestSkipped ('N/A (ECI mode) ' );
97
- }
98
-
99
- /** @inheritDoc */
100
- public function testCodeLengthOverflowException ():void {
101
- /** @noinspection PhpUnitTestFailedLineInspection */
102
- $ this ::markTestSkipped ('N/A (ECI mode) ' );
70
+ $ this ::assertSame ($ this ->testdata , ECI ::decodeSegment ($ bitBuffer , $ options ->version ));
103
71
}
104
72
105
73
/** @inheritDoc */
106
74
public function testInvalidDataException ():void {
107
75
$ this ->expectException (QRCodeDataException::class);
108
76
$ this ->expectExceptionMessage ('invalid encoding id: ' );
109
77
/** @phan-suppress-next-line PhanNoopNew */
110
- new $ this -> FQN (-1 );
78
+ new ECI (-1 );
111
79
}
112
80
113
81
/**
@@ -120,7 +88,7 @@ public function testInvalidDataOnEmptyException():void{
120
88
$ this ->expectException (QRCodeDataException::class);
121
89
$ this ->expectExceptionMessage ('invalid encoding id: ' );
122
90
/** @phan-suppress-next-line PhanNoopNew */
123
- new $ this -> FQN (1000000 );
91
+ new ECI (1000000 );
124
92
}
125
93
126
94
public static function eciCharsetIdProvider ():array {
@@ -139,12 +107,11 @@ public static function eciCharsetIdProvider():array{
139
107
*/
140
108
public function testReadWrite (int $ id , int $ lengthInBits ):void {
141
109
$ bitBuffer = new BitBuffer ;
142
- $ eci = (new $ this -> FQN ($ id ))->write ($ bitBuffer , 1 );
110
+ $ eci = (new ECI ($ id ))->write ($ bitBuffer , 1 );
143
111
144
112
$ this ::assertSame ($ lengthInBits , $ eci ->getLengthInBits ());
145
113
$ this ::assertSame (Mode::ECI , $ bitBuffer ->read (4 ));
146
- /** @noinspection PhpUndefinedMethodInspection */
147
- $ this ::assertSame ($ id , $ this ->FQN ::parseValue ($ bitBuffer )->getID ());
114
+ $ this ::assertSame ($ id , ECI ::parseValue ($ bitBuffer )->getID ());
148
115
}
149
116
150
117
/**
@@ -163,8 +130,7 @@ public function testDecodeECISegmentFollowedByInvalidModeException():void{
163
130
$ segments [1 ] = new Number ('1 ' );
164
131
$ bitBuffer = (new QRData ($ options , $ segments ))->getBitBuffer ();
165
132
$ this ::assertSame (Mode::ECI , $ bitBuffer ->read (4 ));
166
- /** @noinspection PhpUndefinedMethodInspection */
167
- $ this ->FQN ::decodeSegment ($ bitBuffer , $ options ->version );
133
+ ECI ::decodeSegment ($ bitBuffer , $ options ->version );
168
134
}
169
135
170
136
public function unknownEncodingDataProvider ():array {
@@ -183,11 +149,10 @@ public function testConvertUnknownEncoding(int $id, string $data):void{
183
149
$ options = new QROptions ;
184
150
$ options ->version = 5 ;
185
151
186
- $ segments = [new $ this -> FQN ($ id ), new Byte ($ data )];
152
+ $ segments = [new ECI ($ id ), new Byte ($ data )];
187
153
$ bitBuffer = (new QRData ($ options , $ segments ))->getBitBuffer ();
188
154
$ this ::assertSame (Mode::ECI , $ bitBuffer ->read (4 ));
189
- /** @noinspection PhpUndefinedMethodInspection */
190
- $ this ::assertSame ($ data , $ this ->FQN ::decodeSegment ($ bitBuffer , $ options ->version ));
155
+ $ this ::assertSame ($ data , ECI ::decodeSegment ($ bitBuffer , $ options ->version ));
191
156
}
192
157
193
158
}
0 commit comments