codemasher 5 лет назад
Родитель
Сommit
6eb4dd1ac3

+ 12 - 7
tests/Data/DatainterfaceTestAbstract.php

@@ -16,6 +16,8 @@ use chillerlan\QRCode\QROptions;
 use chillerlan\QRCode\Data\{QRCodeDataException, QRDataInterface, QRMatrix};
 use chillerlan\QRCodeTest\QRTestAbstract;
 
+use function str_repeat;
+
 abstract class DatainterfaceTestAbstract extends QRTestAbstract{
 
 	protected QRDataInterface $dataInterface;
@@ -27,32 +29,34 @@ abstract class DatainterfaceTestAbstract extends QRTestAbstract{
 	protected function setUp():void{
 		parent::setUp();
 
+		/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
 		$this->dataInterface = $this->reflection->newInstanceArgs([new QROptions(['version' => 4])]);
 	}
 
-	public function testInstance(){
+	public function testInstance():void{
+		/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
 		$this->dataInterface = $this->reflection->newInstanceArgs([new QROptions, $this->testdata]);
 
 		$this::assertInstanceOf(QRDataInterface::class, $this->dataInterface);
 	}
 
-	public function testSetData(){
+	public function testSetData():void{
 		$this->dataInterface->setData($this->testdata);
 
 		$this::assertSame($this->expected, $this->getProperty('matrixdata')->getValue($this->dataInterface));
 	}
 
-	public function testInitMatrix(){
+	public function testInitMatrix():void{
 		$m = $this->dataInterface->setData($this->testdata)->initMatrix(0);
 
 		$this::assertInstanceOf(QRMatrix::class, $m);
 	}
 
-	public function testGetMinimumVersion(){
+	public function testGetMinimumVersion():void{
 		$this::assertSame(1, $this->getMethod('getMinimumVersion')->invoke($this->dataInterface));
 	}
 
-	public function testGetMinimumVersionException(){
+	public function testGetMinimumVersionException():void{
 		$this->expectException(QRCodeDataException::class);
 		$this->expectExceptionMessage('data exceeds');
 
@@ -60,10 +64,11 @@ abstract class DatainterfaceTestAbstract extends QRTestAbstract{
 		$this->getMethod('getMinimumVersion')->invoke($this->dataInterface);
 	}
 
-	public function testCodeLengthOverflowException(){
+	public function testCodeLengthOverflowException():void{
 		$this->expectException(QRCodeDataException::class);
 		$this->expectExceptionMessage('code length overflow');
 
-		$this->dataInterface->setData(\str_repeat('0', 1337));
+		$this->dataInterface->setData(str_repeat('0', 1337));
 	}
+
 }

+ 6 - 4
tests/Data/KanjiTest.php

@@ -14,6 +14,8 @@ namespace chillerlan\QRCodeTest\Data;
 
 use chillerlan\QRCode\Data\{Kanji, QRCodeDataException};
 
+use function str_repeat;
+
 class KanjiTest extends DatainterfaceTestAbstract{
 
 	protected string $FQCN = Kanji::class;
@@ -36,25 +38,25 @@ class KanjiTest extends DatainterfaceTestAbstract{
 		96, 113, 54, 191
 	];
 
-	public function testIllegalCharException1(){
+	public function testIllegalCharException1():void{
 		$this->expectException(QRCodeDataException::class);
 		$this->expectExceptionMessage('illegal char at 1 [16191]');
 
 		$this->dataInterface->setData('ÃÃ');
 	}
 
-	public function testIllegalCharException2(){
+	public function testIllegalCharException2():void{
 		$this->expectException(QRCodeDataException::class);
 		$this->expectExceptionMessage('illegal char at 1');
 
 		$this->dataInterface->setData('Ã');
 	}
 
-	public function testCodeLengthOverflowException(){
+	public function testCodeLengthOverflowException():void{
 		$this->expectException(QRCodeDataException::class);
 		$this->expectExceptionMessage('code length overflow');
 
-		$this->dataInterface->setData(\str_repeat('荷', 1337));
+		$this->dataInterface->setData(str_repeat('荷', 1337));
 	}
 
 }

+ 1 - 1
tests/Data/MaskPatternTesterTest.php

@@ -20,7 +20,7 @@ class MaskPatternTesterTest extends QRTestAbstract{
 	protected string $FQCN = MaskPatternTester::class;
 
 	// coverage
-	public function testMaskpattern(){
+	public function testMaskpattern():void{
 		$matrix = (new Byte(new QROptions(['version' => 10]), 'test'))->initMatrix(0, true);
 
 		$this::assertSame(6178, (new MaskPatternTester($matrix))->testPattern());

+ 1 - 1
tests/Data/NumberTest.php

@@ -36,7 +36,7 @@ class NumberTest extends DatainterfaceTestAbstract{
 		89, 63, 168, 151
 	];
 
-	public function testGetCharCodeException(){
+	public function testGetCharCodeException():void{
 		$this->expectException(QRCodeDataException::class);
 		$this->expectExceptionMessage('illegal char: "#" [35]');
 

+ 18 - 17
tests/Data/QRMatrixTest.php

@@ -28,44 +28,45 @@ class QRMatrixTest extends QRTestAbstract{
 	protected function setUp():void{
 		parent::setUp();
 
+		/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
 		$this->matrix = $this->reflection->newInstanceArgs([$this->version, QRCode::ECC_L]);
 	}
 
-	public function testInvalidVersionException(){
+	public function testInvalidVersionException():void{
 		$this->expectException(QRCodeDataException::class);
 		$this->expectExceptionMessage('invalid QR Code version');
 
 		$this->reflection->newInstanceArgs([42, 0]);
 	}
 
-	public function testInvalidEccException(){
+	public function testInvalidEccException():void{
 		$this->expectException(QRCodeDataException::class);
 		$this->expectExceptionMessage('invalid ecc level');
 
 		$this->reflection->newInstanceArgs([1, 42]);
 	}
 
-	public function testInstance(){
+	public function testInstance():void{
 		$this::assertInstanceOf($this->FQCN, $this->matrix);
 	}
 
-	public function testSize(){
+	public function testSize():void{
 		$this::assertCount($this->matrix->size(), $this->matrix->matrix());
 	}
 
-	public function testVersion(){
+	public function testVersion():void{
 		$this::assertSame($this->version, $this->matrix->version());
 	}
 
-	public function testECC(){
+	public function testECC():void{
 		$this::assertSame(QRCode::ECC_L, $this->matrix->eccLevel());
 	}
 
-	public function testMaskPattern(){
+	public function testMaskPattern():void{
 		$this::assertSame(-1, $this->matrix->maskPattern());
 	}
 
-	public function testGetSetCheck(){
+	public function testGetSetCheck():void{
 		$this->matrix->set(10, 10, true, QRMatrix::M_TEST);
 		$this::assertSame(65280, $this->matrix->get(10, 10));
 		$this::assertTrue($this->matrix->check(10, 10));
@@ -75,13 +76,13 @@ class QRMatrixTest extends QRTestAbstract{
 		$this::assertFalse($this->matrix->check(20, 20));
 	}
 
-	public function testSetDarkModule(){
+	public function testSetDarkModule():void{
 		$this->matrix->setDarkModule();
 
 		$this::assertSame(QRMatrix::M_DARKMODULE << 8, $this->matrix->get(8, $this->matrix->size() - 8));
 	}
 
-	public function testSetFinderPattern(){
+	public function testSetFinderPattern():void{
 		$this->matrix->setFinderPattern();
 
 		$this::assertSame(QRMatrix::M_FINDER << 8, $this->matrix->get(0, 0));
@@ -89,7 +90,7 @@ class QRMatrixTest extends QRTestAbstract{
 		$this::assertSame(QRMatrix::M_FINDER << 8, $this->matrix->get($this->matrix->size() - 1, 0));
 	}
 
-	public function testSetSeparators(){
+	public function testSetSeparators():void{
 		$this->matrix->setSeparators();
 
 		$this::assertSame(QRMatrix::M_SEPARATOR, $this->matrix->get(7, 0));
@@ -98,7 +99,7 @@ class QRMatrixTest extends QRTestAbstract{
 		$this::assertSame(QRMatrix::M_SEPARATOR, $this->matrix->get($this->matrix->size() - 8, 0));
 	}
 
-	public function testSetAlignmentPattern(){
+	public function testSetAlignmentPattern():void{
 		$this->matrix
 			->setFinderPattern()
 			->setAlignmentPattern()
@@ -120,7 +121,7 @@ class QRMatrixTest extends QRTestAbstract{
 
 	}
 
-	public function testSetTimingPattern(){
+	public function testSetTimingPattern():void{
 		$this->matrix
 			->setAlignmentPattern()
 			->setTimingPattern()
@@ -143,7 +144,7 @@ class QRMatrixTest extends QRTestAbstract{
 		}
 	}
 
-	public function testSetVersionNumber(){
+	public function testSetVersionNumber():void{
 		$this->matrix->setVersionNumber(true);
 
 		$this::assertSame(QRMatrix::M_VERSION, $this->matrix->get($this->matrix->size() - 9, 0));
@@ -152,7 +153,7 @@ class QRMatrixTest extends QRTestAbstract{
 		$this::assertSame(QRMatrix::M_VERSION, $this->matrix->get(5, $this->matrix->size() - 11));
 	}
 
-	public function testSetFormatInfo(){
+	public function testSetFormatInfo():void{
 		$this->matrix->setFormatInfo(0, true);
 
 		$this::assertSame(QRMatrix::M_FORMAT, $this->matrix->get(8, 0));
@@ -161,7 +162,7 @@ class QRMatrixTest extends QRTestAbstract{
 		$this::assertSame(QRMatrix::M_FORMAT, $this->matrix->get($this->matrix->size() - 8, 8));
 	}
 
-	public function testSetQuietZone(){
+	public function testSetQuietZone():void{
 		$size = $this->matrix->size();
 		$q    = 5;
 
@@ -181,7 +182,7 @@ class QRMatrixTest extends QRTestAbstract{
 		$this::assertSame(QRMatrix::M_TEST << 8, $this->matrix->get($size - 1 - $q, $size - 1 - $q));
 	}
 
-	public function testSetQuietZoneException(){
+	public function testSetQuietZoneException():void{
 		$this->expectException(QRCodeDataException::class);
 		$this->expectExceptionMessage('use only after writing data');
 

+ 3 - 3
tests/Helpers/BitBufferTest.php

@@ -23,7 +23,7 @@ class BitBufferTest extends QRTestAbstract{
 		$this->bitBuffer = new BitBuffer;
 	}
 
-	public function bitProvider(){
+	public function bitProvider():array{
 		return [
 			'number'   => [QRCode::DATA_NUMBER, 16],
 			'alphanum' => [QRCode::DATA_ALPHANUM, 32],
@@ -35,13 +35,13 @@ class BitBufferTest extends QRTestAbstract{
 	/**
 	 * @dataProvider bitProvider
 	 */
-	public function testPut($data, $value){
+	public function testPut(int $data, int $value):void{
 		$this->bitBuffer->put($data, 4);
 		$this::assertSame($value, $this->bitBuffer->buffer[0]);
 		$this::assertSame(4, $this->bitBuffer->length);
 	}
 
-	public function testClear(){
+	public function testClear():void{
 		$this->bitBuffer->clear();
 		$this::assertSame([], $this->bitBuffer->buffer);
 		$this::assertSame(0, $this->bitBuffer->length);

+ 2 - 2
tests/Helpers/PolynomialTest.php

@@ -24,13 +24,13 @@ class PolynomialTest extends QRTestAbstract{
 		$this->polynomial = new Polynomial;
 	}
 
-	public function testGexp(){
+	public function testGexp():void{
 		$this::assertSame(142, $this->polynomial->gexp(-1));
 		$this::assertSame(133, $this->polynomial->gexp(128));
 		$this::assertSame(2,   $this->polynomial->gexp(256));
 	}
 
-	public function testGlogException(){
+	public function testGlogException():void{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('log(0)');
 

+ 3 - 4
tests/Output/QRImageTest.php

@@ -18,7 +18,7 @@ class QRImageTest extends QROutputTestAbstract{
 
 	protected string $FQCN = QRImage::class;
 
-	public function types(){
+	public function types():array{
 		return [
 			'png' => [QRCode::OUTPUT_IMAGE_PNG],
 			'gif' => [QRCode::OUTPUT_IMAGE_GIF],
@@ -28,9 +28,8 @@ class QRImageTest extends QROutputTestAbstract{
 
 	/**
 	 * @dataProvider types
-	 * @param $type
 	 */
-	public function testImageOutput($type){
+	public function testImageOutput(string $type):void{
 		$this->options->outputType  = $type;
 		$this->options->imageBase64 = false;
 
@@ -45,7 +44,7 @@ class QRImageTest extends QROutputTestAbstract{
 		$this::assertSame($img, file_get_contents($this::cachefile.$type));
 	}
 
-	public function testSetModuleValues(){
+	public function testSetModuleValues():void{
 
 		$this->options->moduleValues = [
 			// data

+ 2 - 2
tests/Output/QRImagickTest.php

@@ -28,7 +28,7 @@ class QRImagickTest extends QROutputTestAbstract{
 		parent::setUp();
 	}
 
-	public function testImageOutput(){
+	public function testImageOutput():void{
 		$type = QRCode::OUTPUT_IMAGICK;
 
 		$this->options->outputType = $type;
@@ -39,7 +39,7 @@ class QRImagickTest extends QROutputTestAbstract{
 		$this::assertSame($img, file_get_contents($this::cachefile.$type));
 	}
 
-	public function testSetModuleValues(){
+	public function testSetModuleValues():void{
 
 		$this->options->moduleValues = [
 			// data

+ 4 - 6
tests/Output/QRMarkupTest.php

@@ -18,7 +18,7 @@ class QRMarkupTest extends QROutputTestAbstract{
 
 	protected string $FQCN = QRMarkup::class;
 
-	public function types(){
+	public function types():array{
 		return [
 			'html' => [QRCode::OUTPUT_MARKUP_HTML],
 			'svg'  => [QRCode::OUTPUT_MARKUP_SVG],
@@ -27,9 +27,8 @@ class QRMarkupTest extends QROutputTestAbstract{
 
 	/**
 	 * @dataProvider types
-	 * @param $type
 	 */
-	public function testMarkupOutputFile($type){
+	public function testMarkupOutputFile(string $type):void{
 		$this->options->outputType = $type;
 		$this->options->cachefile  = $this::cachefile.$type;
 		$this->setOutputInterface();
@@ -40,9 +39,8 @@ class QRMarkupTest extends QROutputTestAbstract{
 
 	/**
 	 * @dataProvider types
-	 * @param $type
 	 */
-	public function testMarkupOutput($type){
+	public function testMarkupOutput(string $type):void{
 		$this->options->outputType = $type;
 		$this->setOutputInterface();
 
@@ -60,7 +58,7 @@ class QRMarkupTest extends QROutputTestAbstract{
 		$this::assertSame(trim($expected), trim($this->outputInterface->dump()));
 	}
 
-	public function testSetModuleValues(){
+	public function testSetModuleValues():void{
 
 		$this->options->moduleValues = [
 			// data

+ 4 - 3
tests/Output/QROutputTestAbstract.php

@@ -42,16 +42,17 @@ abstract class QROutputTestAbstract extends QRTestAbstract{
 		$this->setOutputInterface();
 	}
 
-	protected function setOutputInterface(){
+	protected function setOutputInterface():QROutputInterface{
+		/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
 		$this->outputInterface = $this->reflection->newInstanceArgs([$this->options, (new Byte($this->options, 'testdata'))->initMatrix(0)]);
 		return $this->outputInterface;
 	}
 
-	public function testInstance(){
+	public function testInstance():void{
 		$this::assertInstanceOf(QROutputInterface::class, $this->outputInterface);
 	}
 
-	public function testSaveException(){
+	public function testSaveException():void{
 		$this->expectException(QRCodeOutputException::class);
 		$this->expectExceptionMessage('Could not write data to cache file: /foo');
 

+ 3 - 4
tests/Output/QRStringTest.php

@@ -18,7 +18,7 @@ class QRStringTest extends QROutputTestAbstract{
 
 	protected string $FQCN = QRString::class;
 
-	public function types(){
+	public function types():array{
 		return [
 			'json' => [QRCode::OUTPUT_STRING_JSON],
 			'text' => [QRCode::OUTPUT_STRING_TEXT],
@@ -27,9 +27,8 @@ class QRStringTest extends QROutputTestAbstract{
 
 	/**
 	 * @dataProvider types
-	 * @param $type
 	 */
-	public function testStringOutput($type){
+	public function testStringOutput(string $type):void{
 		$this->options->outputType = $type;
 		$this->options->cachefile  = $this::cachefile.$type;
 		$this->setOutputInterface();
@@ -38,7 +37,7 @@ class QRStringTest extends QROutputTestAbstract{
 		$this::assertSame($data, file_get_contents($this->options->cachefile));
 	}
 
-	public function testSetModuleValues(){
+	public function testSetModuleValues():void{
 
 		$this->options->moduleValues = [
 			// data

+ 12 - 12
tests/QRCodeTest.php

@@ -34,24 +34,24 @@ class QRCodeTest extends QRTestAbstract{
 		$this->qrcode = $this->reflection->newInstance();
 	}
 
-	public function testIsNumber(){
+	public function testIsNumber():void{
 		$this::assertTrue($this->qrcode->isNumber('0123456789'));
 		$this::assertFalse($this->qrcode->isNumber('ABC'));
 	}
 
-	public function testIsAlphaNum(){
+	public function testIsAlphaNum():void{
 		$this::assertTrue($this->qrcode->isAlphaNum('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'));
 		$this::assertFalse($this->qrcode->isAlphaNum('abc'));
 	}
 
-	public function testIsKanji(){
+	public function testIsKanji():void{
 		$this::assertTrue($this->qrcode->isKanji('茗荷'));
 		$this::assertFalse($this->qrcode->isKanji('Ã'));
 	}
 
 	// coverage
 
-	public function typeDataProvider(){
+	public function typeDataProvider():array{
 		return [
 			'png'  => [QRCode::OUTPUT_IMAGE_PNG, 'data:image/png;base64,'],
 			'gif'  => [QRCode::OUTPUT_IMAGE_GIF, 'data:image/gif;base64,'],
@@ -67,40 +67,40 @@ class QRCodeTest extends QRTestAbstract{
 	 * @dataProvider typeDataProvider
 	 * @param $type
 	 */
-	public function testRenderImage($type, $expected){
+	public function testRenderImage($type, $expected):void{
 		$this->qrcode = $this->reflection->newInstanceArgs([new QROptions(['outputType' => $type])]);
 
 		$this::assertStringContainsString($expected, $this->qrcode->render('test'));
 	}
 
-	public function testInitDataInterfaceException(){
+	public function testInitDataInterfaceException():void{
 		$this->expectException(QRCodeOutputException::class);
 		$this->expectExceptionMessage('invalid output type');
 
 		(new QRCode(new QROptions(['outputType' => 'foo'])))->render('test');
 	}
 
-	public function testGetMatrixException(){
+	public function testGetMatrixException():void{
 		$this->expectException(QRCodeDataException::class);
 		$this->expectExceptionMessage('QRCode::getMatrix() No data given.');
 
 		$this->qrcode->getMatrix('');
 	}
 
-	public function testTrim() {
+	public function testTrim():void{
 		$m1 = $this->qrcode->getMatrix('hello');
 		$m2 = $this->qrcode->getMatrix('hello '); // added space
 
 		$this::assertNotEquals($m1, $m2);
 	}
 
-	public function testImageTransparencyBGDefault(){
+	public function testImageTransparencyBGDefault():void{
 		$this->qrcode = $this->reflection->newInstanceArgs([new QROptions(['imageTransparencyBG' => ['foo']])]);
 
 		$this::assertSame([255,255,255], $this->getProperty('options')->getValue($this->qrcode)->imageTransparencyBG);
 	}
 
-	public function testCustomOutput(){
+	public function testCustomOutput():void{
 
 		$options = new QROptions([
 			'version'         => 5,
@@ -114,7 +114,7 @@ class QRCodeTest extends QRTestAbstract{
 		$this::assertSame($expected, $this->reflection->newInstanceArgs([$options])->render('test'));
 	}
 
-	public function testDataModeOverride(){
+	public function testDataModeOverride():void{
 		$this->qrcode = $this->reflection->newInstance();
 
 		$this::assertInstanceOf(Number::class, $this->qrcode->initDataInterface('123'));
@@ -128,7 +128,7 @@ class QRCodeTest extends QRTestAbstract{
 		$this::assertInstanceOf(Byte::class, $this->qrcode->initDataInterface(random_bytes(32)));
 	}
 
-	public function testDataModeOverrideError(){
+	public function testDataModeOverrideError():void{
 		$this->expectException(QRCodeDataException::class);
 		$this->expectExceptionMessage('illegal char:');
 

+ 6 - 6
tests/QROptionsTest.php

@@ -21,14 +21,14 @@ class QROptionsTest extends TestCase{
 	/** @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\QRCode\QROptions */
 	protected SettingsContainerInterface $options;
 
-	public function testVersionClamp(){
+	public function testVersionClamp():void{
 		$this::assertSame(40, (new QROptions(['version' => 42]))->version);
 		$this::assertSame(1, (new QROptions(['version' => -42]))->version);
 		$this::assertSame(21, (new QROptions(['version' => 21]))->version);
 		$this::assertSame(QRCode::VERSION_AUTO, (new QROptions)->version); // QRCode::VERSION_AUTO = -1, default
 	}
 
-	public function testVersionMinMaxClamp(){
+	public function testVersionMinMaxClamp():void{
 		// normal clamp
 		$o = new QROptions(['versionMin' => 5, 'versionMax' => 10]);
 		$this::assertSame(5, $o->versionMin);
@@ -49,20 +49,20 @@ class QROptionsTest extends TestCase{
 		$this::assertSame(40, $o->versionMax);
 	}
 
-	public function testMaskPatternClamp(){
+	public function testMaskPatternClamp():void{
 		$this::assertSame(7, (new QROptions(['maskPattern' => 42]))->maskPattern);
 		$this::assertSame(0, (new QROptions(['maskPattern' => -42]))->maskPattern);
 		$this::assertSame(QRCode::MASK_PATTERN_AUTO, (new QROptions)->maskPattern); // QRCode::MASK_PATTERN_AUTO = -1, default
 	}
 
-	public function testInvalidEccLevelException(){
+	public function testInvalidEccLevelException():void{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('Invalid error correct level: 42');
 
 		new QROptions(['eccLevel' => 42]);
 	}
 
-	public function testClampRGBValues(){
+	public function testClampRGBValues():void{
 		$o = new QROptions(['imageTransparencyBG' => [-1, 0, 999]]);
 
 		$this::assertSame(0, $o->imageTransparencyBG[0]);
@@ -70,7 +70,7 @@ class QROptionsTest extends TestCase{
 		$this::assertSame(255, $o->imageTransparencyBG[2]);
 	}
 
-	public function testInvalidRGBValueException(){
+	public function testInvalidRGBValueException():void{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('Invalid RGB value.');
 

+ 4 - 5
tests/QRTestAbstract.php

@@ -30,7 +30,7 @@ abstract class QRTestAbstract extends TestCase{
 	 *
 	 * @return \ReflectionMethod
 	 */
-	protected function getMethod(string $method):ReflectionMethod {
+	protected function getMethod(string $method):ReflectionMethod{
 		$method = $this->reflection->getMethod($method);
 		$method->setAccessible(true);
 
@@ -50,17 +50,16 @@ abstract class QRTestAbstract extends TestCase{
 	}
 
 	/**
-	 * @param        $object
+	 * @param object $object
 	 * @param string $property
-	 * @param        $value
+	 * @param mixed  $value
 	 *
 	 * @return void
 	 */
-	protected function setProperty($object, string $property, $value){
+	protected function setProperty($object, string $property, $value):void{
 		$property = $this->getProperty($property);
 		$property->setAccessible(true);
 		$property->setValue($object, $value);
 	}
 
-
 }