:octocat: clean up builddir mess

This commit is contained in:
smiley
2024-01-07 13:32:32 +01:00
parent e9cc23dc31
commit d641fced1f
3 changed files with 106 additions and 14 deletions
+8 -10
View File
@@ -10,18 +10,19 @@
namespace chillerlan\QRCodeTest\Output;
use chillerlan\QRCodeTest\BuildDirTrait;
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use function file_exists, file_get_contents, mkdir, realpath;
/**
* Test abstract for the several (built-in) output modules,
* should also be used to test custom output modules
*/
abstract class QROutputTestAbstract extends TestCase{
use BuildDirTrait;
/** @var \chillerlan\QRCode\QROptions|\chillerlan\Settings\SettingsContainerInterface */
protected QROptions $options;
@@ -29,16 +30,13 @@ abstract class QROutputTestAbstract extends TestCase{
protected QRMatrix $matrix;
protected string $type;
protected const buildDir = __DIR__.'/../../.build/output-test/';
protected const buildDir = '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);
}
$this->createBuildDir($this::buildDir);
$this->options = new QROptions;
$this->options->outputType = $this->type;
@@ -86,11 +84,11 @@ abstract class QROutputTestAbstract extends TestCase{
$this->options->outputBase64 = false;
$this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
// create the cache file
$name = (new ReflectionClass($this->outputInterface))->getShortName();
$file = realpath($this::buildDir).'test.output.'.$name;
$data = $this->outputInterface->dump($file);
$name = (new ReflectionClass($this->outputInterface))->getShortName();
$fileSubPath = $this::buildDir.'/test.output.'.$name;
$data = $this->outputInterface->dump($this->getBuildPath($fileSubPath));
$this::assertSame($data, file_get_contents($file));
$this::assertSame($data, $this->getBuildFileContent($fileSubPath));
}
}