🔥 v6.0 third pass: test clean-up (again)

This commit is contained in:
smiley
2023-11-26 18:42:45 +01:00
parent 2478f75324
commit 2d2a00fabb
37 changed files with 398 additions and 249 deletions
+17 -23
View File
@@ -10,16 +10,14 @@
namespace chillerlan\QRCodeTest\Output;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
use chillerlan\Settings\SettingsContainerInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
use PHPUnit\Framework\TestCase;
use function file_exists, mkdir;
use function str_replace;
use ReflectionClass;
use function file_exists, file_get_contents, mkdir, realpath;
/**
* Test abstract for the several (built-in) output modules,
@@ -30,30 +28,27 @@ abstract class QROutputTestAbstract extends TestCase{
protected SettingsContainerInterface|QROptions $options;
protected QROutputInterface $outputInterface;
protected QRMatrix $matrix;
protected string $builddir = __DIR__.'/../../.build/output-test';
protected string $FQN;
protected const buildDir = __DIR__.'/../../.build/output-test/';
/**
* Attempts to create a directory under /.build and instances several required objects
*/
protected function setUp():void{
if(!file_exists($this->builddir)){
mkdir($this->builddir, 0777, true);
if(!file_exists($this::buildDir)){
mkdir($this::buildDir, 0777, true);
}
$this->options = new QROptions;
$this->options->outputInterface = $this->FQN;
$this->matrix = (new QRCode($this->options))->addByteSegment('testdata')->getQRMatrix();
$this->outputInterface = new $this->FQN($this->options, $this->matrix);
$this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
}
/**
* Validate the instance of the interface
*/
public function testInstance():void{
$this::assertInstanceOf(QROutputInterface::class, $this->outputInterface);
}
abstract protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
):QROutputInterface;
/**
* Tests if an exception is thrown when trying to write a cache file to an invalid destination
@@ -62,7 +57,6 @@ abstract class QROutputTestAbstract extends TestCase{
$this->expectException(QRCodeOutputException::class);
$this->expectExceptionMessage('Cannot write data to cache file: /foo/bar.test');
$this->outputInterface = new $this->FQN($this->options, $this->matrix);
$this->outputInterface->dump('/foo/bar.test');
}
@@ -70,8 +64,7 @@ abstract class QROutputTestAbstract extends TestCase{
#[DataProvider('moduleValueProvider')]
public function testValidateModuleValues(mixed $value, bool $expected):void{
/** @noinspection PhpUndefinedMethodInspection */
$this::assertSame($expected, $this->FQN::moduleValueIsValid($value));
$this::assertSame($expected, $this->outputInterface::moduleValueIsValid($value));
}
/*
@@ -88,9 +81,10 @@ abstract class QROutputTestAbstract extends TestCase{
*/
public function testRenderToCacheFile():void{
$this->options->outputBase64 = false;
$this->outputInterface = new $this->FQN($this->options, $this->matrix);
$this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
// create the cache file
$file = $this->builddir.'/test.output.'.str_replace('chillerlan\\QRCode\\Output\\', '', $this->FQN);
$name = (new ReflectionClass($this->outputInterface))->getShortName();
$file = realpath($this::buildDir).'test.output.'.$name;
$data = $this->outputInterface->dump($file);
$this::assertSame($data, file_get_contents($file));