:octocat: file caching rework/cleanup

This commit is contained in:
smiley
2023-03-07 22:42:48 +01:00
parent 0538d1be26
commit ecdd81a0cb
14 changed files with 57 additions and 43 deletions
+26
View File
@@ -14,6 +14,7 @@ use chillerlan\QRCode\{QROptions, QRCode};
use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
use PHPUnit\Framework\TestCase;
use stdClass;
use function file_get_contents;
/**
* Tests basic functions of the QRCode class
@@ -22,6 +23,7 @@ final class QRCodeTest extends TestCase{
private QRCode $qrcode;
private QROptions $options;
private string $builddir = __DIR__.'/../.build/output_test';
/**
* invoke test instances
@@ -68,4 +70,28 @@ final class QRCodeTest extends TestCase{
$this->qrcode->setOptions($this->options)->render('test');
}
/**
* Tests if an exception is thrown when trying to write a cache file to an invalid destination
*/
public function testSaveException():void{
$this->expectException(QRCodeOutputException::class);
$this->expectExceptionMessage('Cannot write data to cache file: /foo/bar.test');
$this->options->cachefile = '/foo/bar.test';
$this->qrcode->setOptions($this->options)->render('test');
}
/**
* Tests if a cache file is properly saved in the given path
*/
public function testRenderToCacheFile():void{
$this->options->cachefile = $this->builddir.'/test.cache.svg';
$this->options->imageBase64 = false;
// create the cache file
$data = $this->qrcode->setOptions($this->options)->render('test');
$this::assertSame($data, file_get_contents($this->options->cachefile));
}
}