Просмотр исходного кода

:shower: deprecate QRCode::is* string validation in favor of $datamode::validateString(), move tests

codemasher 4 лет назад
Родитель
Сommit
3fac6cf89b

+ 12 - 0
src/QRCode.php

@@ -221,6 +221,9 @@ class QRCode{
 
 	/**
 	 * checks if a string qualifies as numeric (convenience method)
+	 *
+	 * @deprecated
+	 * @codeCoverageIgnore
 	 */
 	public function isNumber(string $string):bool{
 		return Number::validateString($string);
@@ -228,6 +231,9 @@ class QRCode{
 
 	/**
 	 * checks if a string qualifies as alphanumeric (convenience method)
+	 *
+	 * @deprecated
+	 * @codeCoverageIgnore
 	 */
 	public function isAlphaNum(string $string):bool{
 		return AlphaNum::validateString($string);
@@ -235,6 +241,9 @@ class QRCode{
 
 	/**
 	 * checks if a string qualifies as Kanji (convenience method)
+	 *
+	 * @deprecated
+	 * @codeCoverageIgnore
 	 */
 	public function isKanji(string $string):bool{
 		return Kanji::validateString($string);
@@ -242,6 +251,9 @@ class QRCode{
 
 	/**
 	 * a dummy (convenience method)
+	 *
+	 * @deprecated
+	 * @codeCoverageIgnore
 	 */
 	public function isByte(string $string):bool{
 		return Byte::validateString($string);

+ 10 - 0
tests/Data/AlphaNumTest.php

@@ -20,4 +20,14 @@ final class AlphaNumTest extends DatainterfaceTestAbstract{
 	protected string $FQN      = AlphaNum::class;
 	protected string $testdata = '0 $%*+-./:';
 
+	/**
+	 * isAlphaNum() should pass on the 45 defined characters and fail on anything else (e.g. lowercase)
+	 */
+	public function stringValidateProvider():array{
+		return [
+			['ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:', true],
+			['abc', false],
+		];
+	}
+
 }

+ 12 - 1
tests/Data/ByteTest.php

@@ -20,11 +20,22 @@ final class ByteTest extends DatainterfaceTestAbstract{
 	protected string $FQN      = Byte::class;
 	protected string $testdata = '[¯\_(ツ)_/¯]';
 
+	/**
+	 * isByte() passses any binary string and only fails on empty strings
+	 */
+	public function stringValidateProvider():array{
+		return [
+			["\x01\x02\x03", true],
+			['            ', true], // not empty!
+			['', false],
+		];
+	}
+
 	/**
 	 * @inheritDoc
 	 */
 	public function testInvalidDataException():void{
-		$this->markTestSkipped('N/A');
+		$this::markTestSkipped('N/A');
 	}
 
 }

+ 10 - 0
tests/Data/DatainterfaceTestAbstract.php

@@ -75,6 +75,16 @@ abstract class DatainterfaceTestAbstract extends TestCase{
 		$this::assertSame(1, $getMinimumVersion->invoke($this->QRData));
 	}
 
+	abstract public function stringValidateProvider():array;
+
+	/**
+	 * @dataProvider stringValidateProvider
+	 */
+	public function testValidateString(string $string, bool $expected):void{
+		/** @noinspection PhpUndefinedMethodInspection */
+		$this::assertSame($expected, $this->FQN::validateString($string));
+	}
+
 	/**
 	 * Tests if an exception is thrown when the data exceeds the maximum version while auto detecting
 	 */

+ 12 - 0
tests/Data/KanjiTest.php

@@ -20,4 +20,16 @@ final class KanjiTest extends DatainterfaceTestAbstract{
 	protected string $FQN      = Kanji::class;
 	protected string $testdata = '茗荷茗荷茗荷茗荷茗荷';
 
+	/**
+	 * isKanji() should pass on Kanji/SJIS characters and fail on everything else
+	 */
+	public function stringValidateProvider():array{
+		return [
+			['茗荷', true],
+			['Ã', false],
+			['ABC', false],
+			['123', false],
+		];
+	}
+
 }

+ 10 - 0
tests/Data/NumberTest.php

@@ -20,4 +20,14 @@ final class NumberTest extends DatainterfaceTestAbstract{
 	protected string $FQN      = Number::class;
 	protected string $testdata = '0123456789';
 
+	/**
+	 * isNumber() should pass on any number and fail on anything else
+	 */
+	public function stringValidateProvider():array{
+		return [
+			['0123456789', true],
+			['ABC123', false],
+		];
+	}
+
 }

+ 2 - 2
tests/Data/QRMatrixTest.php

@@ -146,7 +146,7 @@ final class QRMatrixTest extends TestCase{
 	public function testSetAlignmentPattern(int $version):void{
 
 		if($version === 1){
-			$this->markTestSkipped('N/A (Version 1 has no alignment pattern)');
+			$this::markTestSkipped('N/A (Version 1 has no alignment pattern)');
 		}
 
 		$matrix = $this
@@ -208,7 +208,7 @@ final class QRMatrixTest extends TestCase{
 	public function testSetVersionNumber(int $version):void{
 
 		if($version < 7){
-			$this->markTestSkipped('N/A (Version < 7)');
+			$this::markTestSkipped('N/A (Version < 7)');
 		}
 
 		$matrix = $this->getMatrix($version)->setVersionNumber();

+ 0 - 39
tests/QRCodeTest.php

@@ -31,45 +31,6 @@ final class QRCodeTest extends TestCase{
 		$this->options = new QROptions;
 	}
 
-	/**
-	 * isNumber() should pass on any number and fail on anything else
-	 */
-	public function testIsNumber():void{
-		$this::assertTrue($this->qrcode->isNumber('0123456789'));
-
-		$this::assertFalse($this->qrcode->isNumber('ABC123'));
-	}
-
-	/**
-	 * isAlphaNum() should pass on the 45 defined characters and fail on anything else (e.g. lowercase)
-	 */
-	public function testIsAlphaNum():void{
-		$this::assertTrue($this->qrcode->isAlphaNum('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'));
-
-		$this::assertFalse($this->qrcode->isAlphaNum('abc'));
-	}
-
-	/**
-	 * isKanji() should pass on Kanji/SJIS characters and fail on everything else
-	 */
-	public function testIsKanji():void{
-		$this::assertTrue($this->qrcode->isKanji('茗荷'));
-
-		$this::assertFalse($this->qrcode->isKanji('Ã'));
-		$this::assertFalse($this->qrcode->isKanji('ABC'));
-		$this::assertFalse($this->qrcode->isKanji('123'));
-	}
-
-	/**
-	 * isByte() passses any binary string and only fails on empty strings
-	 */
-	public function testIsByte():void{
-		$this::assertTrue($this->qrcode->isByte("\x01\x02\x03"));
-		$this::assertTrue($this->qrcode->isByte('            ')); // not empty!
-
-		$this::assertFalse($this->qrcode->isByte(''));
-	}
-
 	/**
 	 * tests if an exception is thrown when an invalid (built-in) output type is specified
 	 */