diff --git a/phpdoc.xml b/phpdoc.xml
index e95687977..1735d5b3c 100644
--- a/phpdoc.xml
+++ b/phpdoc.xml
@@ -8,6 +8,7 @@
src
+ tests
diff --git a/tests/Data/AlphaNumTest.php b/tests/Data/AlphaNumTest.php
index ce8348d15..10847633c 100644
--- a/tests/Data/AlphaNumTest.php
+++ b/tests/Data/AlphaNumTest.php
@@ -12,14 +12,18 @@
namespace chillerlan\QRCodeTest\Data;
-use chillerlan\QRCode\Data\{AlphaNum, QRCodeDataException};
+use chillerlan\QRCode\Data\{AlphaNum, QRCodeDataException, QRDataInterface};
+use chillerlan\QRCode\QROptions;
-class AlphaNumTest extends DatainterfaceTestAbstract{
-
- protected string $FQCN = AlphaNum::class;
+/**
+ * Tests the AlphaNum class
+ */
+final class AlphaNumTest extends DatainterfaceTestAbstract{
+ /** @internal */
protected string $testdata = '0 $%*+-./:';
+ /** @internal */
protected array $expected = [
32, 80, 36, 212, 252, 15, 175, 251,
176, 236, 17, 236, 17, 236, 17, 236,
@@ -36,6 +40,17 @@ class AlphaNumTest extends DatainterfaceTestAbstract{
92, 112, 20, 198, 27
];
+ /**
+ * @inheritDoc
+ * @internal
+ */
+ protected function getDataInterfaceInstance(QROptions $options):QRDataInterface{
+ return new AlphaNum($options);
+ }
+
+ /**
+ * Tests if an exception is thrown when an invalid character is encountered
+ */
public function testGetCharCodeException():void{
$this->expectException(QRCodeDataException::class);
$this->expectExceptionMessage('illegal char: "#" [35]');
diff --git a/tests/Data/ByteTest.php b/tests/Data/ByteTest.php
index 270ac46b8..295603200 100644
--- a/tests/Data/ByteTest.php
+++ b/tests/Data/ByteTest.php
@@ -13,13 +13,18 @@
namespace chillerlan\QRCodeTest\Data;
use chillerlan\QRCode\Data\Byte;
+use chillerlan\QRCode\Data\QRDataInterface;
+use chillerlan\QRCode\QROptions;
-class ByteTest extends DatainterfaceTestAbstract{
-
- protected string $FQCN = Byte::class;
+/**
+ * Tests the Byte class
+ */
+final class ByteTest extends DatainterfaceTestAbstract{
+ /** @internal */
protected string $testdata = '[¯\_(ツ)_/¯]';
+ /** @internal */
protected array $expected = [
64, 245, 188, 42, 245, 197, 242, 142,
56, 56, 66, 149, 242, 252, 42, 245,
@@ -36,5 +41,12 @@ class ByteTest extends DatainterfaceTestAbstract{
21, 47, 250, 101
];
+ /**
+ * @inheritDoc
+ * @internal
+ */
+ protected function getDataInterfaceInstance(QROptions $options):QRDataInterface{
+ return new Byte($options);
+ }
}
diff --git a/tests/Data/DatainterfaceTestAbstract.php b/tests/Data/DatainterfaceTestAbstract.php
index 94bda6a6c..373c92986 100644
--- a/tests/Data/DatainterfaceTestAbstract.php
+++ b/tests/Data/DatainterfaceTestAbstract.php
@@ -12,63 +12,116 @@
namespace chillerlan\QRCodeTest\Data;
+use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
+use PHPUnit\Framework\TestCase;
use chillerlan\QRCode\Data\{QRCodeDataException, QRDataInterface, QRMatrix};
-use chillerlan\QRCodeTest\QRTestAbstract;
+use ReflectionClass;
use function str_repeat;
-abstract class DatainterfaceTestAbstract extends QRTestAbstract{
+/**
+ * Te data interface test abstract
+ */
+abstract class DatainterfaceTestAbstract extends TestCase{
+ /** @internal */
+ protected ReflectionClass $reflection;
+ /** @internal */
protected QRDataInterface $dataInterface;
-
+ /** @internal */
protected string $testdata;
-
+ /** @internal */
protected array $expected;
+ /**
+ * @internal
+ */
protected function setUp():void{
- parent::setUp();
-
- /** @noinspection PhpFieldAssignmentTypeMismatchInspection */
- $this->dataInterface = $this->reflection->newInstanceArgs([new QROptions(['version' => 4])]);
+ $this->dataInterface = $this->getDataInterfaceInstance(new QROptions(['version' => 4]));
+ $this->reflection = new ReflectionClass($this->dataInterface);
}
- public function testInstance():void{
- /** @noinspection PhpFieldAssignmentTypeMismatchInspection */
- $this->dataInterface = $this->reflection->newInstanceArgs([new QROptions, $this->testdata]);
+ /**
+ * Returns a data interface instance
+ *
+ * @internal
+ */
+ abstract protected function getDataInterfaceInstance(QROptions $options):QRDataInterface;
+ /**
+ * Verifies the data interface instance
+ */
+ public function testInstance():void{
$this::assertInstanceOf(QRDataInterface::class, $this->dataInterface);
}
- public function testSetData():void{
+ /**
+ * Tests ecc masking and verifies against a sample
+ */
+ public function testMaskEcc():void{
$this->dataInterface->setData($this->testdata);
- $this::assertSame($this->expected, $this->getProperty('matrixdata')->getValue($this->dataInterface));
+ $maskECC = $this->reflection->getMethod('maskECC');
+ $maskECC->setAccessible(true);
+
+ $this::assertSame($this->expected, $maskECC->invoke($this->dataInterface));
}
- public function testInitMatrix():void{
- $m = $this->dataInterface->setData($this->testdata)->initMatrix(0);
-
- $this::assertInstanceOf(QRMatrix::class, $m);
+ /**
+ * @see testInitMatrix()
+ * @internal
+ * @return int[][]
+ */
+ public function MaskPatternProvider():array{
+ return [[0], [1], [2], [3], [4], [5], [6], [7]];
}
+ /**
+ * Tests initializing the data matrix
+ *
+ * @dataProvider MaskPatternProvider
+ */
+ public function testInitMatrix(int $maskPattern):void{
+ $this->dataInterface->setData($this->testdata);
+
+ $matrix = $this->dataInterface->initMatrix($maskPattern);
+
+ $this::assertInstanceOf(QRMatrix::class, $matrix);
+ $this::assertSame($maskPattern, $matrix->maskPattern());
+ }
+
+ /**
+ * Tests getting the minimum QR version for the given data
+ */
public function testGetMinimumVersion():void{
- $this::assertSame(1, $this->getMethod('getMinimumVersion')->invoke($this->dataInterface));
+ $this->dataInterface->setData($this->testdata);
+
+ $getMinimumVersion = $this->reflection->getMethod('getMinimumVersion');
+ $getMinimumVersion->setAccessible(true);
+
+ $this::assertSame(1, $getMinimumVersion->invoke($this->dataInterface));
}
+ /**
+ * Tests if an exception is thrown when the data exceeds the maximum version while auto detecting
+ */
public function testGetMinimumVersionException():void{
$this->expectException(QRCodeDataException::class);
$this->expectExceptionMessage('data exceeds');
- $this->getProperty('strlen')->setValue($this->dataInterface, 13370);
- $this->getMethod('getMinimumVersion')->invoke($this->dataInterface);
+ $this->dataInterface = $this->getDataInterfaceInstance(new QROptions(['version' => QRCode::VERSION_AUTO]));
+ $this->dataInterface->setData(str_repeat($this->testdata, 1337));
}
+ /**
+ * Tests if an exception is thrown on data overflow
+ */
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($this->testdata, 1337));
}
}
diff --git a/tests/Data/KanjiTest.php b/tests/Data/KanjiTest.php
index 960ead8af..484f388dc 100644
--- a/tests/Data/KanjiTest.php
+++ b/tests/Data/KanjiTest.php
@@ -12,16 +12,18 @@
namespace chillerlan\QRCodeTest\Data;
-use chillerlan\QRCode\Data\{Kanji, QRCodeDataException};
+use chillerlan\QRCode\QROptions;
+use chillerlan\QRCode\Data\{Kanji, QRCodeDataException, QRDataInterface};
-use function str_repeat;
-
-class KanjiTest extends DatainterfaceTestAbstract{
-
- protected string $FQCN = Kanji::class;
+/**
+ * Tests the Kanji class
+ */
+final class KanjiTest extends DatainterfaceTestAbstract{
+ /** @internal */
protected string $testdata = '茗荷茗荷茗荷茗荷茗荷';
+ /** @internal */
protected array $expected = [
128, 173, 85, 26, 95, 85, 70, 151,
213, 81, 165, 245, 84, 105, 125, 85,
@@ -38,6 +40,17 @@ class KanjiTest extends DatainterfaceTestAbstract{
96, 113, 54, 191
];
+ /**
+ * @inheritDoc
+ * @internal
+ */
+ protected function getDataInterfaceInstance(QROptions $options):QRDataInterface{
+ return new Kanji($options);
+ }
+
+ /**
+ * Tests if an exception is thrown when an invalid character is encountered
+ */
public function testIllegalCharException1():void{
$this->expectException(QRCodeDataException::class);
$this->expectExceptionMessage('illegal char at 1 [16191]');
@@ -45,6 +58,9 @@ class KanjiTest extends DatainterfaceTestAbstract{
$this->dataInterface->setData('ÃÃ');
}
+ /**
+ * Tests if an exception is thrown when an invalid character is encountered
+ */
public function testIllegalCharException2():void{
$this->expectException(QRCodeDataException::class);
$this->expectExceptionMessage('illegal char at 1');
@@ -52,11 +68,4 @@ class KanjiTest extends DatainterfaceTestAbstract{
$this->dataInterface->setData('Ã');
}
- public function testCodeLengthOverflowException():void{
- $this->expectException(QRCodeDataException::class);
- $this->expectExceptionMessage('code length overflow');
-
- $this->dataInterface->setData(str_repeat('荷', 1337));
- }
-
}
diff --git a/tests/Data/MaskPatternTesterTest.php b/tests/Data/MaskPatternTesterTest.php
index 3856d497d..63caf7779 100644
--- a/tests/Data/MaskPatternTesterTest.php
+++ b/tests/Data/MaskPatternTesterTest.php
@@ -12,20 +12,27 @@
namespace chillerlan\QRCodeTest\Data;
-use chillerlan\QRCode\{QROptions, Data\Byte, Data\MaskPatternTester};
-use chillerlan\QRCodeTest\QRTestAbstract;
+use chillerlan\QRCode\QROptions;
+use chillerlan\QRCode\Data\{Byte, MaskPatternTester};
+use PHPUnit\Framework\TestCase;
-class MaskPatternTesterTest extends QRTestAbstract{
+/**
+ * MaskPatternTester coverage test
+ */
+final class MaskPatternTesterTest extends TestCase{
- protected string $FQCN = MaskPatternTester::class;
-
- // coverage
+ /**
+ * Tests getting the best mask pattern
+ */
public function testMaskpattern():void{
$dataInterface = new Byte(new QROptions(['version' => 10]), 'test');
$this::assertSame(4, (new MaskPatternTester($dataInterface))->getBestMaskPattern());
}
+ /**
+ * Tests getting the penalty value for a given mask pattern
+ */
public function testMaskpatternID():void{
$dataInterface = new Byte(new QROptions(['version' => 10]), 'test');
diff --git a/tests/Data/NumberTest.php b/tests/Data/NumberTest.php
index 9dcb47aff..dcd9507ab 100644
--- a/tests/Data/NumberTest.php
+++ b/tests/Data/NumberTest.php
@@ -12,14 +12,18 @@
namespace chillerlan\QRCodeTest\Data;
-use chillerlan\QRCode\Data\{Number, QRCodeDataException};
+use chillerlan\QRCode\QROptions;
+use chillerlan\QRCode\Data\{Number, QRCodeDataException, QRDataInterface};
-class NumberTest extends DatainterfaceTestAbstract{
-
- protected string $FQCN = Number::class;
+/**
+ * Tests the Number class
+ */
+final class NumberTest extends DatainterfaceTestAbstract{
+ /** @internal */
protected string $testdata = '0123456789';
+ /** @internal */
protected array $expected = [
16, 40, 12, 86, 106, 105, 0, 236,
17, 236, 17, 236, 17, 236, 17, 236,
@@ -36,6 +40,17 @@ class NumberTest extends DatainterfaceTestAbstract{
89, 63, 168, 151
];
+ /**
+ * @inheritDoc
+ * @internal
+ */
+ protected function getDataInterfaceInstance(QROptions $options):QRDataInterface{
+ return new Number($options);
+ }
+
+ /**
+ * Tests if an exception is thrown when an invalid character is encountered
+ */
public function testGetCharCodeException():void{
$this->expectException(QRCodeDataException::class);
$this->expectExceptionMessage('illegal char: "#" [35]');
diff --git a/tests/Data/QRMatrixTest.php b/tests/Data/QRMatrixTest.php
index de33cee7a..7e3cb6e73 100755
--- a/tests/Data/QRMatrixTest.php
+++ b/tests/Data/QRMatrixTest.php
@@ -14,58 +14,97 @@ namespace chillerlan\QRCodeTest\Data;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\Data\{QRCodeDataException, QRMatrix};
-use chillerlan\QRCodeTest\QRTestAbstract;
+use PHPUnit\Framework\TestCase;
use ReflectionClass;
-class QRMatrixTest extends QRTestAbstract{
-
- protected string $FQCN = QRMatrix::class;
-
- protected int $version = 7;
+/**
+ * Tests the QRMatix class
+ */
+final class QRMatrixTest extends TestCase{
+ /** @internal */
+ protected const version = 40;
+ /** @internal */
protected QRMatrix $matrix;
+ /**
+ * invokes a QRMatrix object
+ *
+ * @internal
+ */
protected function setUp():void{
- parent::setUp();
-
- /** @noinspection PhpFieldAssignmentTypeMismatchInspection */
- $this->matrix = $this->reflection->newInstanceArgs([$this->version, QRCode::ECC_L]);
+ $this->matrix = $this->getMatrix($this::version);
}
+ /**
+ * shortcut
+ *
+ * @internal
+ */
+ protected function getMatrix(int $version):QRMatrix{
+ return new QRMatrix($version, QRCode::ECC_L);
+ }
+
+ /**
+ * Validates the QRMatrix instance
+ */
+ public function testInstance():void{
+ $this::assertInstanceOf(QRMatrix::class, $this->matrix);
+ }
+
+ /**
+ * Tests if an exception is thrown when an invalid QR version was given
+ */
public function testInvalidVersionException():void{
$this->expectException(QRCodeDataException::class);
$this->expectExceptionMessage('invalid QR Code version');
- $this->reflection->newInstanceArgs([42, 0]);
+ $this->matrix = new QRMatrix(42, 0);
}
+ /**
+ * Tests if an exception is thrown when an invalid ECC level was given
+ */
public function testInvalidEccException():void{
$this->expectException(QRCodeDataException::class);
$this->expectExceptionMessage('invalid ecc level');
- $this->reflection->newInstanceArgs([1, 42]);
- }
-
- public function testInstance():void{
- $this::assertInstanceOf($this->FQCN, $this->matrix);
+ $this->matrix = new QRMatrix(1, 42);
}
+ /**
+ * Tests if size() returns the actual matrix size/count
+ */
public function testSize():void{
$this::assertCount($this->matrix->size(), $this->matrix->matrix());
}
+ /**
+ * Tests if version() returns the current (given) version
+ */
public function testVersion():void{
- $this::assertSame($this->version, $this->matrix->version());
+ $this::assertSame($this::version, $this->matrix->version());
}
+ /**
+ * Tests if eccLevel() returns the current (given) ECC level
+ */
public function testECC():void{
$this::assertSame(QRCode::ECC_L, $this->matrix->eccLevel());
}
+ /**
+ * Tests if maskPattern() returns the current (or default) mask pattern
+ */
public function testMaskPattern():void{
- $this::assertSame(-1, $this->matrix->maskPattern());
+ $this::assertSame(-1, $this->matrix->maskPattern()); // default
+
+ // @todo: actual mask pattern after mapData()
}
+ /**
+ * Tests the set(), get() and check() methods
+ */
public function testGetSetCheck():void{
$this->matrix->set(10, 10, true, QRMatrix::M_TEST);
$this::assertSame(65280, $this->matrix->get(10, 10));
@@ -76,62 +115,112 @@ class QRMatrixTest extends QRTestAbstract{
$this::assertFalse($this->matrix->check(20, 20));
}
- public function testSetDarkModule():void{
- $this->matrix->setDarkModule();
+ /**
+ * Version data provider for several pattern tests
+ *
+ * @return int[][]
+ * @internal
+ */
+ public function versionProvider():array{
+ $versions = [];
- $this::assertSame(QRMatrix::M_DARKMODULE << 8, $this->matrix->get(8, $this->matrix->size() - 8));
+ for($i = 1; $i <= 40; $i++){
+ $versions[] = [$i];
+ }
+
+ return $versions;
}
- public function testSetFinderPattern():void{
- $this->matrix->setFinderPattern();
+ /**
+ * Tests setting the dark module and verifies its position
+ *
+ * @dataProvider versionProvider
+ */
+ public function testSetDarkModule(int $version):void{
+ $matrix = $this->getMatrix($version)->setDarkModule();
- $this::assertSame(QRMatrix::M_FINDER << 8, $this->matrix->get(0, 0));
- $this::assertSame(QRMatrix::M_FINDER << 8, $this->matrix->get(0, $this->matrix->size() - 1));
- $this::assertSame(QRMatrix::M_FINDER << 8, $this->matrix->get($this->matrix->size() - 1, 0));
+ $this::assertSame(QRMatrix::M_DARKMODULE << 8, $matrix->get(8, $matrix->size() - 8));
}
- public function testSetSeparators():void{
- $this->matrix->setSeparators();
+ /**
+ * Tests setting the finder patterns and verifies their positions
+ *
+ * @dataProvider versionProvider
+ */
+ public function testSetFinderPattern(int $version):void{
+ $matrix = $this->getMatrix($version)->setFinderPattern();
- $this::assertSame(QRMatrix::M_SEPARATOR, $this->matrix->get(7, 0));
- $this::assertSame(QRMatrix::M_SEPARATOR, $this->matrix->get(0, 7));
- $this::assertSame(QRMatrix::M_SEPARATOR, $this->matrix->get(0, $this->matrix->size() - 8));
- $this::assertSame(QRMatrix::M_SEPARATOR, $this->matrix->get($this->matrix->size() - 8, 0));
+ $this::assertSame(QRMatrix::M_FINDER << 8, $matrix->get(0, 0));
+ $this::assertSame(QRMatrix::M_FINDER << 8, $matrix->get(0, $matrix->size() - 1));
+ $this::assertSame(QRMatrix::M_FINDER << 8, $matrix->get($matrix->size() - 1, 0));
}
- public function testSetAlignmentPattern():void{
- $this->matrix
+ /**
+ * Tests the separator patterns and verifies their positions
+ *
+ * @dataProvider versionProvider
+ */
+ public function testSetSeparators(int $version):void{
+ $matrix = $this->getMatrix($version)->setSeparators();
+
+ $this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(7, 0));
+ $this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(0, 7));
+ $this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(0, $matrix->size() - 8));
+ $this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get($matrix->size() - 8, 0));
+ }
+
+ /**
+ * Tests the alignment patterns and verifies their positions - version 1 (no pattern) skipped
+ *
+ * @dataProvider versionProvider
+ */
+ public function testSetAlignmentPattern(int $version):void{
+
+ if($version === 1){
+ $this->markTestSkipped('N/A');
+ return;
+ }
+
+ $matrix = $this
+ ->getMatrix($version)
->setFinderPattern()
->setAlignmentPattern()
;
- $alignmentPattern = (new ReflectionClass(QRMatrix::class))->getConstant('alignmentPattern')[$this->version];
+ $alignmentPattern = (new ReflectionClass(QRMatrix::class))->getConstant('alignmentPattern')[$version];
foreach($alignmentPattern as $py){
foreach($alignmentPattern as $px){
- if($this->matrix->get($px, $py) === QRMatrix::M_FINDER << 8){
- $this::assertSame(QRMatrix::M_FINDER << 8, $this->matrix->get($px, $py), 'skipped finder pattern');
+ if($matrix->get($px, $py) === QRMatrix::M_FINDER << 8){
+ $this::assertSame(QRMatrix::M_FINDER << 8, $matrix->get($px, $py), 'skipped finder pattern');
continue;
}
- $this::assertSame(QRMatrix::M_ALIGNMENT << 8, $this->matrix->get($px, $py));
+ $this::assertSame(QRMatrix::M_ALIGNMENT << 8, $matrix->get($px, $py));
}
}
}
- public function testSetTimingPattern():void{
- $this->matrix
+ /**
+ * Tests the timing patterns and verifies their positions
+ *
+ * @dataProvider versionProvider
+ */
+ public function testSetTimingPattern(int $version):void{
+
+ $matrix = $this
+ ->getMatrix($version)
->setAlignmentPattern()
->setTimingPattern()
;
- $size = $this->matrix->size();
+ $size = $matrix->size();
for($i = 7; $i < $size - 7; $i++){
if($i % 2 === 0){
- $p1 = $this->matrix->get(6, $i);
+ $p1 = $matrix->get(6, $i);
if($p1 === QRMatrix::M_ALIGNMENT << 8){
$this::assertSame(QRMatrix::M_ALIGNMENT << 8, $p1, 'skipped alignment pattern');
@@ -139,49 +228,75 @@ class QRMatrixTest extends QRTestAbstract{
}
$this::assertSame(QRMatrix::M_TIMING << 8, $p1);
- $this::assertSame(QRMatrix::M_TIMING << 8, $this->matrix->get($i, 6));
+ $this::assertSame(QRMatrix::M_TIMING << 8, $matrix->get($i, 6));
}
}
}
- public function testSetVersionNumber():void{
- $this->matrix->setVersionNumber(true);
+ /**
+ * Tests the version patterns and verifies their positions - version < 7 skipped
+ *
+ * @dataProvider versionProvider
+ */
+ public function testSetVersionNumber(int $version):void{
- $this::assertSame(QRMatrix::M_VERSION, $this->matrix->get($this->matrix->size() - 9, 0));
- $this::assertSame(QRMatrix::M_VERSION, $this->matrix->get($this->matrix->size() - 11, 5));
- $this::assertSame(QRMatrix::M_VERSION, $this->matrix->get(0, $this->matrix->size() - 9));
- $this::assertSame(QRMatrix::M_VERSION, $this->matrix->get(5, $this->matrix->size() - 11));
+ if($version < 7){
+ $this->markTestSkipped('N/A');
+ return;
+ }
+
+ $matrix = $this->getMatrix($version)->setVersionNumber(true);
+
+ $this::assertSame(QRMatrix::M_VERSION, $matrix->get($matrix->size() - 9, 0));
+ $this::assertSame(QRMatrix::M_VERSION, $matrix->get($matrix->size() - 11, 5));
+ $this::assertSame(QRMatrix::M_VERSION, $matrix->get(0, $matrix->size() - 9));
+ $this::assertSame(QRMatrix::M_VERSION, $matrix->get(5, $matrix->size() - 11));
}
- public function testSetFormatInfo():void{
- $this->matrix->setFormatInfo(0, true);
+ /**
+ * Tests the format patterns and verifies their positions
+ *
+ * @dataProvider versionProvider
+ */
+ public function testSetFormatInfo(int $version):void{
+ $matrix = $this->getMatrix($version)->setFormatInfo(0, true);
- $this::assertSame(QRMatrix::M_FORMAT, $this->matrix->get(8, 0));
- $this::assertSame(QRMatrix::M_FORMAT, $this->matrix->get(0, 8));
- $this::assertSame(QRMatrix::M_FORMAT, $this->matrix->get($this->matrix->size() - 1, 8));
- $this::assertSame(QRMatrix::M_FORMAT, $this->matrix->get($this->matrix->size() - 8, 8));
+ $this::assertSame(QRMatrix::M_FORMAT, $matrix->get(8, 0));
+ $this::assertSame(QRMatrix::M_FORMAT, $matrix->get(0, 8));
+ $this::assertSame(QRMatrix::M_FORMAT, $matrix->get($matrix->size() - 1, 8));
+ $this::assertSame(QRMatrix::M_FORMAT, $matrix->get($matrix->size() - 8, 8));
}
- public function testSetQuietZone():void{
- $size = $this->matrix->size();
+ /**
+ * Tests the quiet zone pattern and verifies its position
+ *
+ * @dataProvider versionProvider
+ */
+ public function testSetQuietZone(int $version):void{
+ $matrix = $this->getMatrix($version);
+
+ $size = $matrix->size();
$q = 5;
- $this->matrix->set(0, 0, true, QRMatrix::M_TEST);
- $this->matrix->set($size - 1, $size - 1, true, QRMatrix::M_TEST);
+ $matrix->set(0, 0, true, QRMatrix::M_TEST);
+ $matrix->set($size - 1, $size - 1, true, QRMatrix::M_TEST);
- $this->matrix->setQuietZone($q);
+ $matrix->setQuietZone($q);
- $this::assertCount($size + 2 * $q, $this->matrix->matrix());
- $this::assertCount($size + 2 * $q, $this->matrix->matrix()[$size - 1]);
+ $this::assertCount($size + 2 * $q, $matrix->matrix());
+ $this::assertCount($size + 2 * $q, $matrix->matrix()[$size - 1]);
- $size = $this->matrix->size();
- $this::assertSame(QRMatrix::M_QUIETZONE, $this->matrix->get(0, 0));
- $this::assertSame(QRMatrix::M_QUIETZONE, $this->matrix->get($size - 1, $size - 1));
+ $size = $matrix->size();
+ $this::assertSame(QRMatrix::M_QUIETZONE, $matrix->get(0, 0));
+ $this::assertSame(QRMatrix::M_QUIETZONE, $matrix->get($size - 1, $size - 1));
- $this::assertSame(QRMatrix::M_TEST << 8, $this->matrix->get($q, $q));
- $this::assertSame(QRMatrix::M_TEST << 8, $this->matrix->get($size - 1 - $q, $size - 1 - $q));
+ $this::assertSame(QRMatrix::M_TEST << 8, $matrix->get($q, $q));
+ $this::assertSame(QRMatrix::M_TEST << 8, $matrix->get($size - 1 - $q, $size - 1 - $q));
}
+ /**
+ * Tests if an exception is thrown in an attempt to create it before data was written
+ */
public function testSetQuietZoneException():void{
$this->expectException(QRCodeDataException::class);
$this->expectExceptionMessage('use only after writing data');
diff --git a/tests/Helpers/BitBufferTest.php b/tests/Helpers/BitBufferTest.php
index ccac12789..e9479a5c6 100644
--- a/tests/Helpers/BitBufferTest.php
+++ b/tests/Helpers/BitBufferTest.php
@@ -12,10 +12,14 @@
namespace chillerlan\QRCodeTest\Helpers;
-use chillerlan\QRCode\{QRCode, Helpers\BitBuffer};
-use chillerlan\QRCodeTest\QRTestAbstract;
+use chillerlan\QRCode\QRCode;
+use chillerlan\QRCode\Helpers\BitBuffer;
+use PHPUnit\Framework\TestCase;
-class BitBufferTest extends QRTestAbstract{
+/**
+ * BitBuffer coverage test
+ */
+final class BitBufferTest extends TestCase{
protected BitBuffer $bitBuffer;
diff --git a/tests/Helpers/PolynomialTest.php b/tests/Helpers/PolynomialTest.php
index ddbceed60..b0f3f4aa7 100644
--- a/tests/Helpers/PolynomialTest.php
+++ b/tests/Helpers/PolynomialTest.php
@@ -14,9 +14,12 @@ namespace chillerlan\QRCodeTest\Helpers;
use chillerlan\QRCode\Helpers\Polynomial;
use chillerlan\QRCode\QRCodeException;
-use chillerlan\QRCodeTest\QRTestAbstract;
+use PHPUnit\Framework\TestCase;
-class PolynomialTest extends QRTestAbstract{
+/**
+ * Polynomial coverage test
+ */
+final class PolynomialTest extends TestCase{
protected Polynomial $polynomial;
diff --git a/tests/Output/QRImageTest.php b/tests/Output/QRImageTest.php
index 48dfd774e..8038b999e 100644
--- a/tests/Output/QRImageTest.php
+++ b/tests/Output/QRImageTest.php
@@ -12,12 +12,40 @@
namespace chillerlan\QRCodeTest\Output;
-use chillerlan\QRCode\{QRCode, Output\QRImage};
+use chillerlan\QRCode\{QRCode, QROptions};
+use chillerlan\QRCode\Output\{QROutputInterface, QRImage};
+/**
+ * Tests the QRImage output module
+ */
class QRImageTest extends QROutputTestAbstract{
- protected string $FQCN = QRImage::class;
+ /**
+ * @inheritDoc
+ * @internal
+ */
+ public function setUp():void{
+ if(!extension_loaded('gd')){
+ $this->markTestSkipped('ext-gd not loaded');
+ return;
+ }
+
+ parent::setUp();
+ }
+
+ /**
+ * @inheritDoc
+ * @internal
+ */
+ protected function getOutputInterface(QROptions $options):QROutputInterface{
+ return new QRImage($options, $this->matrix);
+ }
+
+ /**
+ * @inheritDoc
+ * @internal
+ */
public function types():array{
return [
'png' => [QRCode::OUTPUT_IMAGE_PNG],
@@ -27,23 +55,8 @@ class QRImageTest extends QROutputTestAbstract{
}
/**
- * @dataProvider types
+ * @inheritDoc
*/
- public function testImageOutput(string $type):void{
- $this->options->outputType = $type;
- $this->options->imageBase64 = false;
-
- $this->setOutputInterface();
- $this->outputInterface->dump($this::cachefile.$type);
- $img = $this->outputInterface->dump();
-
- if($type === QRCode::OUTPUT_IMAGE_JPG){ // jpeg encoding may cause different results
- $this->markAsRisky();
- }
-
- $this::assertSame($img, file_get_contents($this::cachefile.$type));
- }
-
public function testSetModuleValues():void{
$this->options->moduleValues = [
@@ -52,7 +65,8 @@ class QRImageTest extends QROutputTestAbstract{
4 => [255, 255, 255],
];
- $this->setOutputInterface()->dump();
+ $this->outputInterface = $this->getOutputInterface($this->options);
+ $this->outputInterface->dump();
$this::assertTrue(true); // tricking the code coverage
}
diff --git a/tests/Output/QRImagickTest.php b/tests/Output/QRImagickTest.php
index 5d24ddc79..2987a476e 100644
--- a/tests/Output/QRImagickTest.php
+++ b/tests/Output/QRImagickTest.php
@@ -12,12 +12,18 @@
namespace chillerlan\QRCodeTest\Output;
-use chillerlan\QRCode\{QRCode, Output\QRImagick};
+use chillerlan\QRCode\{QRCode, QROptions};
+use chillerlan\QRCode\Output\{QROutputInterface, QRImagick};
+/**
+ * Tests the QRImagick output module
+ */
class QRImagickTest extends QROutputTestAbstract{
- protected string $FQCN = QRImagick::class;
-
+ /**
+ * @inheritDoc
+ * @internal
+ */
public function setUp():void{
if(!extension_loaded('imagick')){
@@ -28,17 +34,27 @@ class QRImagickTest extends QROutputTestAbstract{
parent::setUp();
}
- public function testImageOutput():void{
- $type = QRCode::OUTPUT_IMAGICK;
-
- $this->options->outputType = $type;
- $this->setOutputInterface();
- $this->outputInterface->dump($this::cachefile.$type);
- $img = $this->outputInterface->dump();
-
- $this::assertSame($img, file_get_contents($this::cachefile.$type));
+ /**
+ * @inheritDoc
+ * @internal
+ */
+ protected function getOutputInterface(QROptions $options):QROutputInterface{
+ return new QRImagick($options, $this->matrix);
}
+ /**
+ * @inheritDoc
+ * @internal
+ */
+ public function types():array{
+ return [
+ 'imagick' => [QRCode::OUTPUT_IMAGICK],
+ ];
+ }
+
+ /**
+ * @inheritDoc
+ */
public function testSetModuleValues():void{
$this->options->moduleValues = [
@@ -47,7 +63,8 @@ class QRImagickTest extends QROutputTestAbstract{
4 => '#ECF9BE',
];
- $this->setOutputInterface()->dump();
+ $this->outputInterface = $this->getOutputInterface($this->options);
+ $this->outputInterface->dump();
$this::assertTrue(true); // tricking the code coverage
}
diff --git a/tests/Output/QRMarkupTest.php b/tests/Output/QRMarkupTest.php
index 493598a0d..fe3033d30 100644
--- a/tests/Output/QRMarkupTest.php
+++ b/tests/Output/QRMarkupTest.php
@@ -12,12 +12,26 @@
namespace chillerlan\QRCodeTest\Output;
-use chillerlan\QRCode\{QRCode, Output\QRMarkup};
+use chillerlan\QRCode\{QRCode, QROptions};
+use chillerlan\QRCode\Output\{QROutputInterface, QRMarkup};
+/**
+ * Tests the QRMarkup output module
+ */
class QRMarkupTest extends QROutputTestAbstract{
- protected string $FQCN = QRMarkup::class;
+ /**
+ * @inheritDoc
+ * @internal
+ */
+ protected function getOutputInterface(QROptions $options):QROutputInterface{
+ return new QRMarkup($options, $this->matrix);
+ }
+ /**
+ * @inheritDoc
+ * @internal
+ */
public function types():array{
return [
'html' => [QRCode::OUTPUT_MARKUP_HTML],
@@ -26,38 +40,8 @@ class QRMarkupTest extends QROutputTestAbstract{
}
/**
- * @dataProvider types
+ * @inheritDoc
*/
- public function testMarkupOutputFile(string $type):void{
- $this->options->outputType = $type;
- $this->options->cachefile = $this::cachefile.$type;
- $this->setOutputInterface();
- $data = $this->outputInterface->dump();
-
- $this::assertSame($data, file_get_contents($this->options->cachefile));
- }
-
- /**
- * @dataProvider types
- */
- public function testMarkupOutput(string $type):void{
- $this->options->outputType = $type;
- $this->setOutputInterface();
-
- $expected = explode($this->options->eol, file_get_contents($this::cachefile.$type));
- // cut off the doctype & head
- array_shift($expected);
-
- if($type === QRCode::OUTPUT_MARKUP_HTML){
- // cut off the