🛀 test cleanup

This commit is contained in:
smiley
2024-01-07 01:21:16 +01:00
parent c27973ace0
commit 6239074411
30 changed files with 369 additions and 259 deletions
+11 -83
View File
@@ -13,15 +13,15 @@ namespace chillerlan\QRCodeTest\Data;
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version};
use chillerlan\QRCode\Data\{QRCodeDataException, QRMatrix};
use chillerlan\QRCode\Output\{QROutputInterface, QRString};
use chillerlan\QRCodeTest\QRMatrixDebugTrait;
use PHPUnit\Framework\TestCase;
use Generator;
use function defined;
/**
* Tests the QRMatrix class
*/
final class QRMatrixTest extends TestCase{
use QRMatrixDebugTrait;
private const version = 40;
private QRMatrix $matrix;
@@ -36,103 +36,31 @@ final class QRMatrixTest extends TestCase{
);
}
/**
* Matrix debugging console output
*/
public static function debugMatrix(QRMatrix $matrix):void{
/** @noinspection PhpUndefinedConstantInspection - see phpunit.xml.dist */
if(defined('TEST_IS_CI') && TEST_IS_CI === true){
return;
}
$opt = new QROptions;
$opt->outputType = QROutputInterface::STRING_TEXT;
$opt->eol = "\n";
$opt->moduleValues = [
// finder
QRMatrix::M_FINDER_DARK => QRString::ansi8('██', 124), // dark (true)
QRMatrix::M_FINDER => QRString::ansi8('░░', 124), // light (false)
QRMatrix::M_FINDER_DOT => QRString::ansi8('██', 124), // finder dot, dark (true)
// alignment
QRMatrix::M_ALIGNMENT_DARK => QRString::ansi8('██', 2),
QRMatrix::M_ALIGNMENT => QRString::ansi8('░░', 2),
// timing
QRMatrix::M_TIMING_DARK => QRString::ansi8('██', 184),
QRMatrix::M_TIMING => QRString::ansi8('░░', 184),
// format
QRMatrix::M_FORMAT_DARK => QRString::ansi8('██', 200),
QRMatrix::M_FORMAT => QRString::ansi8('░░', 200),
// version
QRMatrix::M_VERSION_DARK => QRString::ansi8('██', 21),
QRMatrix::M_VERSION => QRString::ansi8('░░', 21),
// data
QRMatrix::M_DATA_DARK => QRString::ansi8('██', 166),
QRMatrix::M_DATA => QRString::ansi8('░░', 166),
// dark module
QRMatrix::M_DARKMODULE => QRString::ansi8('██', 53),
// separator
QRMatrix::M_SEPARATOR => QRString::ansi8('░░', 219),
// quiet zone
QRMatrix::M_QUIETZONE => QRString::ansi8('░░', 195),
// logo space
QRMatrix::M_LOGO => QRString::ansi8('░░', 105),
// empty
QRMatrix::M_NULL => QRString::ansi8('░░', 231),
];
$out = (new QRString($opt, $matrix))->dump();
echo "\n\n".$out."\n\n";
}
/**
* debugging shortcut - limit to a single version when using with matrixProvider
*
* @see QRMatrixTest::matrixProvider()
*/
protected function dm(QRMatrix $matrix):void{
// limit
if($matrix->getVersion()->getVersionNumber() !== 7){
return;
}
$this::debugMatrix($matrix);
}
/**
* Validates the QRMatrix instance
*/
public function testInstance():void{
$this::assertInstanceOf(QRMatrix::class, $this->matrix);
}
/**
* Tests if size() returns the actual matrix size/count
*/
public function testSize():void{
public function testGetSize():void{
$this::assertCount($this->matrix->getSize(), $this->matrix->getMatrix(true));
}
/**
* Tests if version() returns the current (given) version
*/
public function testVersion():void{
public function testGetVersion():void{
$this::assertSame($this::version, $this->matrix->getVersion()->getVersionNumber());
}
/**
* Tests if eccLevel() returns the current (given) ECC level
*/
public function testECC():void{
public function testGetECC():void{
$this::assertSame(EccLevel::L, $this->matrix->getEccLevel()->getLevel());
}
/**
* Tests if maskPattern() returns the current (or default) mask pattern
*/
public function testMaskPattern():void{
public function testGetMaskPattern():void{
// set via matrix evaluation
$matrix = (new QRCode)->addByteSegment('testdata')->getQRMatrix();
@@ -401,7 +329,7 @@ final class QRMatrixTest extends TestCase{
/**
* Tests if the logo space is drawn square if one of the dimensions is omitted
*/
public function testSetLogoSpaceOmitHeight():void{
public function testSetLogoSpaceOmitDimension():void{
$o = new QROptions;
$o->version = 2;
$o->eccLevel = EccLevel::H;
@@ -411,7 +339,7 @@ final class QRMatrixTest extends TestCase{
$matrix = (new QRCode($o))->addByteSegment('testdata')->getQRMatrix();
$this::debugMatrix($matrix);
$this->debugMatrix($matrix);
$this::assertFalse($matrix->checkType(9, 9, QRMatrix::M_LOGO));
$this::assertTrue($matrix->checkType(10, 10, QRMatrix::M_LOGO));
@@ -433,7 +361,7 @@ final class QRMatrixTest extends TestCase{
// also testing size adjustment to uneven numbers
$matrix->setLogoSpace(20, 14);
$this::debugMatrix($matrix);
$this->debugMatrix($matrix);
// NW corner
$this::assertFalse($matrix->checkType(17, 20, QRMatrix::M_LOGO));
@@ -457,7 +385,7 @@ final class QRMatrixTest extends TestCase{
$matrix = (new QRCode($o))->addByteSegment('testdata')->getQRMatrix();
$matrix->setLogoSpace(21, 21, -10, -10);
$this::debugMatrix($matrix);
$this->debugMatrix($matrix);
$this::assertSame(QRMatrix::M_QUIETZONE, $matrix->get(9, 9));
$this::assertSame(QRMatrix::M_LOGO, $matrix->get(10, 10));
$this::assertSame(QRMatrix::M_LOGO, $matrix->get(20, 20));
@@ -466,7 +394,7 @@ final class QRMatrixTest extends TestCase{
// I just realized that setLogoSpace() could be called multiple times
// on the same instance, and I'm not going to do anything about it :P
$matrix->setLogoSpace(21, 21, 45, 45);
$this::debugMatrix($matrix);
$this->debugMatrix($matrix);
$this::assertNotSame(QRMatrix::M_LOGO, $matrix->get(54, 54));
$this::assertSame(QRMatrix::M_LOGO, $matrix->get(55, 55));
$this::assertSame(QRMatrix::M_QUIETZONE, $matrix->get(67, 67));