1111namespace chillerlan \QRCodeTest \Data ;
1212
1313use 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 ;
1617
1718/**
1819 * Tests the ECI class
1920 */
20- final class ECITest extends DataInterfaceTestAbstract {
21+ final class ECITest extends TestCase {
2122
22- protected string $ FQN = ECI ::class ;
23+ protected QRData $ QRData ;
2324 protected string $ testdata = '无可奈何燃花作香 ' ;
2425 private int $ testCharset = ECICharset::GB18030 ;
2526
27+ protected function setUp ():void {
28+ $ this ->QRData = new QRData (new QROptions );
29+ }
30+
2631 private function getDataSegments ():array {
2732 return [
28- new $ this -> FQN ($ this ->testCharset ),
33+ new ECI ($ this ->testCharset ),
2934 new Byte (mb_convert_encoding ($ this ->testdata , ECICharset::MB_ENCODINGS [$ this ->testCharset ], mb_internal_encoding ())),
3035 ];
3136 }
3237
33- public static function stringValidateProvider ():array {
34- return [];
35- }
36-
3738 /** @inheritDoc */
3839 public function testDataModeInstance ():void {
39- $ datamode = new $ this -> FQN ($ this ->testCharset );
40+ $ datamode = new ECI ($ this ->testCharset );
4041
4142 $ this ::assertInstanceOf (QRDataModeInterface::class, $ datamode );
4243 }
4344
4445 /**
45- * @inheritDoc
46- * @dataProvider maskPatternProvider
46+ * returns versions within the version breakpoints 1-9, 10-26 and 27-40
4747 */
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 ]];
6950 }
7051
7152 /**
@@ -86,28 +67,15 @@ public function testDecodeSegment(int $version):void{
8667 // read the first 4 bits
8768 $ this ::assertSame ($ segments [0 ]::DATAMODE , $ bitBuffer ->read (4 ));
8869 // 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 ));
10371 }
10472
10573 /** @inheritDoc */
10674 public function testInvalidDataException ():void {
10775 $ this ->expectException (QRCodeDataException::class);
10876 $ this ->expectExceptionMessage ('invalid encoding id: ' );
10977 /** @phan-suppress-next-line PhanNoopNew */
110- new $ this -> FQN (-1 );
78+ new ECI (-1 );
11179 }
11280
11381 /**
@@ -120,7 +88,7 @@ public function testInvalidDataOnEmptyException():void{
12088 $ this ->expectException (QRCodeDataException::class);
12189 $ this ->expectExceptionMessage ('invalid encoding id: ' );
12290 /** @phan-suppress-next-line PhanNoopNew */
123- new $ this -> FQN (1000000 );
91+ new ECI (1000000 );
12492 }
12593
12694 public static function eciCharsetIdProvider ():array {
@@ -139,12 +107,11 @@ public static function eciCharsetIdProvider():array{
139107 */
140108 public function testReadWrite (int $ id , int $ lengthInBits ):void {
141109 $ bitBuffer = new BitBuffer ;
142- $ eci = (new $ this -> FQN ($ id ))->write ($ bitBuffer , 1 );
110+ $ eci = (new ECI ($ id ))->write ($ bitBuffer , 1 );
143111
144112 $ this ::assertSame ($ lengthInBits , $ eci ->getLengthInBits ());
145113 $ 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 ());
148115 }
149116
150117 /**
@@ -163,8 +130,7 @@ public function testDecodeECISegmentFollowedByInvalidModeException():void{
163130 $ segments [1 ] = new Number ('1 ' );
164131 $ bitBuffer = (new QRData ($ options , $ segments ))->getBitBuffer ();
165132 $ this ::assertSame (Mode::ECI , $ bitBuffer ->read (4 ));
166- /** @noinspection PhpUndefinedMethodInspection */
167- $ this ->FQN ::decodeSegment ($ bitBuffer , $ options ->version );
133+ ECI ::decodeSegment ($ bitBuffer , $ options ->version );
168134 }
169135
170136 public function unknownEncodingDataProvider ():array {
@@ -183,11 +149,10 @@ public function testConvertUnknownEncoding(int $id, string $data):void{
183149 $ options = new QROptions ;
184150 $ options ->version = 5 ;
185151
186- $ segments = [new $ this -> FQN ($ id ), new Byte ($ data )];
152+ $ segments = [new ECI ($ id ), new Byte ($ data )];
187153 $ bitBuffer = (new QRData ($ options , $ segments ))->getBitBuffer ();
188154 $ 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 ));
191156 }
192157
193158}
0 commit comments