Skip to content

Commit 3fac6cf

Browse files
committed
🚿 deprecate QRCode::is* string validation in favor of $datamode::validateString(), move tests
1 parent 7963d9f commit 3fac6cf

File tree

8 files changed

+68
-42
lines changed

8 files changed

+68
-42
lines changed

src/QRCode.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,27 +221,39 @@ protected function initCustomOutputInterface():QROutputInterface{
221221

222222
/**
223223
* checks if a string qualifies as numeric (convenience method)
224+
*
225+
* @deprecated
226+
* @codeCoverageIgnore
224227
*/
225228
public function isNumber(string $string):bool{
226229
return Number::validateString($string);
227230
}
228231

229232
/**
230233
* checks if a string qualifies as alphanumeric (convenience method)
234+
*
235+
* @deprecated
236+
* @codeCoverageIgnore
231237
*/
232238
public function isAlphaNum(string $string):bool{
233239
return AlphaNum::validateString($string);
234240
}
235241

236242
/**
237243
* checks if a string qualifies as Kanji (convenience method)
244+
*
245+
* @deprecated
246+
* @codeCoverageIgnore
238247
*/
239248
public function isKanji(string $string):bool{
240249
return Kanji::validateString($string);
241250
}
242251

243252
/**
244253
* a dummy (convenience method)
254+
*
255+
* @deprecated
256+
* @codeCoverageIgnore
245257
*/
246258
public function isByte(string $string):bool{
247259
return Byte::validateString($string);

tests/Data/AlphaNumTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ final class AlphaNumTest extends DatainterfaceTestAbstract{
2020
protected string $FQN = AlphaNum::class;
2121
protected string $testdata = '0 $%*+-./:';
2222

23+
/**
24+
* isAlphaNum() should pass on the 45 defined characters and fail on anything else (e.g. lowercase)
25+
*/
26+
public function stringValidateProvider():array{
27+
return [
28+
['ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:', true],
29+
['abc', false],
30+
];
31+
}
32+
2333
}

tests/Data/ByteTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,22 @@ final class ByteTest extends DatainterfaceTestAbstract{
2020
protected string $FQN = Byte::class;
2121
protected string $testdata = '[¯\_(ツ)_/¯]';
2222

23+
/**
24+
* isByte() passses any binary string and only fails on empty strings
25+
*/
26+
public function stringValidateProvider():array{
27+
return [
28+
["\x01\x02\x03", true],
29+
[' ', true], // not empty!
30+
['', false],
31+
];
32+
}
33+
2334
/**
2435
* @inheritDoc
2536
*/
2637
public function testInvalidDataException():void{
27-
$this->markTestSkipped('N/A');
38+
$this::markTestSkipped('N/A');
2839
}
2940

3041
}

tests/Data/DatainterfaceTestAbstract.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public function testGetMinimumVersion():void{
7575
$this::assertSame(1, $getMinimumVersion->invoke($this->QRData));
7676
}
7777

78+
abstract public function stringValidateProvider():array;
79+
80+
/**
81+
* @dataProvider stringValidateProvider
82+
*/
83+
public function testValidateString(string $string, bool $expected):void{
84+
/** @noinspection PhpUndefinedMethodInspection */
85+
$this::assertSame($expected, $this->FQN::validateString($string));
86+
}
87+
7888
/**
7989
* Tests if an exception is thrown when the data exceeds the maximum version while auto detecting
8090
*/

tests/Data/KanjiTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,16 @@ final class KanjiTest extends DatainterfaceTestAbstract{
2020
protected string $FQN = Kanji::class;
2121
protected string $testdata = '茗荷茗荷茗荷茗荷茗荷';
2222

23+
/**
24+
* isKanji() should pass on Kanji/SJIS characters and fail on everything else
25+
*/
26+
public function stringValidateProvider():array{
27+
return [
28+
['茗荷', true],
29+
['Ã', false],
30+
['ABC', false],
31+
['123', false],
32+
];
33+
}
34+
2335
}

tests/Data/NumberTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ final class NumberTest extends DatainterfaceTestAbstract{
2020
protected string $FQN = Number::class;
2121
protected string $testdata = '0123456789';
2222

23+
/**
24+
* isNumber() should pass on any number and fail on anything else
25+
*/
26+
public function stringValidateProvider():array{
27+
return [
28+
['0123456789', true],
29+
['ABC123', false],
30+
];
31+
}
32+
2333
}

tests/Data/QRMatrixTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function testSetSeparators(int $version):void{
146146
public function testSetAlignmentPattern(int $version):void{
147147

148148
if($version === 1){
149-
$this->markTestSkipped('N/A (Version 1 has no alignment pattern)');
149+
$this::markTestSkipped('N/A (Version 1 has no alignment pattern)');
150150
}
151151

152152
$matrix = $this
@@ -208,7 +208,7 @@ public function testSetTimingPattern(int $version):void{
208208
public function testSetVersionNumber(int $version):void{
209209

210210
if($version < 7){
211-
$this->markTestSkipped('N/A (Version < 7)');
211+
$this::markTestSkipped('N/A (Version < 7)');
212212
}
213213

214214
$matrix = $this->getMatrix($version)->setVersionNumber();

tests/QRCodeTest.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,6 @@ protected function setUp():void{
3131
$this->options = new QROptions;
3232
}
3333

34-
/**
35-
* isNumber() should pass on any number and fail on anything else
36-
*/
37-
public function testIsNumber():void{
38-
$this::assertTrue($this->qrcode->isNumber('0123456789'));
39-
40-
$this::assertFalse($this->qrcode->isNumber('ABC123'));
41-
}
42-
43-
/**
44-
* isAlphaNum() should pass on the 45 defined characters and fail on anything else (e.g. lowercase)
45-
*/
46-
public function testIsAlphaNum():void{
47-
$this::assertTrue($this->qrcode->isAlphaNum('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'));
48-
49-
$this::assertFalse($this->qrcode->isAlphaNum('abc'));
50-
}
51-
52-
/**
53-
* isKanji() should pass on Kanji/SJIS characters and fail on everything else
54-
*/
55-
public function testIsKanji():void{
56-
$this::assertTrue($this->qrcode->isKanji('茗荷'));
57-
58-
$this::assertFalse($this->qrcode->isKanji('Ã'));
59-
$this::assertFalse($this->qrcode->isKanji('ABC'));
60-
$this::assertFalse($this->qrcode->isKanji('123'));
61-
}
62-
63-
/**
64-
* isByte() passses any binary string and only fails on empty strings
65-
*/
66-
public function testIsByte():void{
67-
$this::assertTrue($this->qrcode->isByte("\x01\x02\x03"));
68-
$this::assertTrue($this->qrcode->isByte(' ')); // not empty!
69-
70-
$this::assertFalse($this->qrcode->isByte(''));
71-
}
72-
7334
/**
7435
* tests if an exception is thrown when an invalid (built-in) output type is specified
7536
*/

0 commit comments

Comments
 (0)