🛀 test overhaul

This commit is contained in:
smiley
2025-11-02 00:48:56 +01:00
parent b9d2059743
commit c99f5d4022
36 changed files with 356 additions and 333 deletions
+39 -6
View File
@@ -11,9 +11,11 @@ declare(strict_types=1);
namespace chillerlan\QRCodeTest;
use chillerlan\QRCode\{QROptions, QRCode};
use chillerlan\QRCode\Output\QRCodeOutputException;
use chillerlan\QRCode\{QRCode, QRCodeException, QROptions};
use chillerlan\QRCode\Common\ECICharset;
use chillerlan\QRCode\Output\{QRCodeOutputException, QRGdImagePNG};
use chillerlan\QRCodeTest\Traits\BuildDirTrait;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use stdClass;
@@ -41,7 +43,8 @@ final class QRCodeTest extends TestCase{
/**
* tests if an exception is thrown if the given output class does not exist
*/
public function testInitCustomOutputInterfaceNotExistsException():void{
#[Test]
public function initCustomOutputInterfaceNotExistsException():void{
$this->expectException(QRCodeOutputException::class);
$this->expectExceptionMessage('invalid output class');
@@ -53,7 +56,8 @@ final class QRCodeTest extends TestCase{
/**
* tests if an exception is thrown if the given output class does not implement QROutputInterface
*/
public function testInitCustomOutputInterfaceNotImplementsException():void{
#[Test]
public function initCustomOutputInterfaceNotImplementsException():void{
$this->expectException(QRCodeOutputException::class);
$this->expectExceptionMessage('output class does not implement QROutputInterface');
@@ -65,7 +69,8 @@ final class QRCodeTest extends TestCase{
/**
* Tests if an exception is thrown when trying to write a cache file to an invalid destination
*/
public function testSaveException():void{
#[Test]
public function saveException():void{
$this->expectException(QRCodeOutputException::class);
$this->expectExceptionMessage('Cannot write data to cache file: /foo/bar.test');
@@ -77,7 +82,8 @@ final class QRCodeTest extends TestCase{
/**
* Tests if a cache file is properly saved in the given path
*/
public function testRenderToCacheFile():void{
#[Test]
public function renderToCacheFile():void{
$fileSubPath = $this::buildDir.'/test.cache.svg';
$this->options->cachefile = $this->getBuildPath($fileSubPath);
@@ -88,4 +94,31 @@ final class QRCodeTest extends TestCase{
$this::assertSame($data, $this->getBuildFileContent($fileSubPath));
}
/**
* Tests adding and decoding an ECI sequence
*/
#[Test]
public function addEciSegment():void{
$expected = '无可奈何燃花作香';
$qrCode = (new QRCode([
'outputBase64' => false,
'outputInterface' => QRGdImagePNG::class,
]));
$qrCode->addEciSegment(ECICharset::GB18030, $expected);
$result = $qrCode->readFromBlob($qrCode->render());
$this::assertSame($expected, $result->data);
}
#[Test]
public function addEciSegmentInvalidCharsetException():void{
$this->expectException(QRCodeException::class);
$this->expectExceptionMessage('unable to add ECI segment');
(new QRCode)->addEciSegment(666, 'nope');
}
}