summaryrefslogtreecommitdiff
path: root/vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php
diff options
context:
space:
mode:
authorChih-Hsuan Yen <[email protected]>2022-07-02 22:01:51 +0800
committerAndrew Dolgov <[email protected]>2022-07-12 22:23:48 +0300
commit4b6161892000cb2b8392dce92a9cf2cabdf2d20e (patch)
tree5cad602010e4d13e1a48d6b922d4768c0893ac8b /vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php
parentd9861038bcc3cb2f38c7153bdca7d5ab89597afa (diff)
Update php-qrcode and php-settings-container for PHP 8.1
By running the following command after updating composer.json ``` composer update chillerlan/php-qrcode chillerlan/php-settings-container ``` This change fixes a deprecation warning from Preferences -> Personal data / Authentication -> Authenticator (OTP). ``` Return type of chillerlan\Settings\SettingsContainerAbstract::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice 1. vendor/chillerlan/php-settings-container/src/SettingsContainerAbstract.php(19): ttrss_error_handler(Return type of chillerlan\Settings\SettingsContainerAbstract::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice, vendor/chillerlan/php-settings-container/src/SettingsContainerAbstract.php) 2. vendor/composer/ClassLoader.php(571): include(/usr/share/webapps/tt-rss/vendor/chillerlan/php-settings-container/src/SettingsContainerAbstract.php) 3. vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile(/usr/share/webapps/tt-rss/vendor/composer/../chillerlan/php-settings-container/src/SettingsContainerAbstract.php) 4. vendor/chillerlan/php-qrcode/src/QROptions.php(59): loadClass(chillerlan\Settings\SettingsContainerAbstract) 5. vendor/composer/ClassLoader.php(571): include(/usr/share/webapps/tt-rss/vendor/chillerlan/php-qrcode/src/QROptions.php) 6. vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile(/usr/share/webapps/tt-rss/vendor/composer/../chillerlan/php-qrcode/src/QROptions.php) 7. vendor/chillerlan/php-qrcode/src/QRCode.php(113): loadClass(chillerlan\QRCode\QROptions) 8. classes/pref/prefs.php(958): __construct() 9. classes/pref/prefs.php(469): _get_otp_qrcode_img() 10. classes/pref/prefs.php(541): index_auth_2fa() 11. backend.php(136): index_auth() ``` The issue is fixed in php-settings-container 2.1.1 [1] Here I use the latest php-qrcode version for another PHP 8.1 fix [2]. [1] https://github.com/chillerlan/php-settings-container/commit/68bc5019c8b38956c83906431ef879668366b036#diff-359c7f7a6d32d9935951e1b0742eb116fb654f4a932c8d40328bb5dcab2fa111L162 [2] https://github.com/chillerlan/php-qrcode/issues/97
Diffstat (limited to 'vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php')
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php135
1 files changed, 102 insertions, 33 deletions
diff --git a/vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php b/vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php
index 6cd95d080..d48468bca 100644
--- a/vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php
+++ b/vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php
@@ -12,60 +12,129 @@
namespace chillerlan\QRCodeTest\Output;
-use chillerlan\QRCode\QROptions;
-use chillerlan\QRCode\Data\Byte;
+use chillerlan\QRCode\{QRCode, QROptions};
+use chillerlan\QRCode\Data\{Byte, QRMatrix};
use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
-use chillerlan\QRCodeTest\QRTestAbstract;
+use PHPUnit\Framework\TestCase;
-use function dirname, file_exists, mkdir;
+use function file_exists, in_array, mkdir;
-abstract class QROutputTestAbstract extends QRTestAbstract{
+use const PHP_OS_FAMILY, PHP_VERSION_ID;
- const cachefile = __DIR__.'/../../.build/output_test/test.';
+/**
+ * Test abstract for the several (built-in) output modules,
+ * should also be used to test custom output modules
+ */
+abstract class QROutputTestAbstract extends TestCase{
+
+ /** @internal */
+ protected string $builddir = __DIR__.'/../../.build/output_test';
+ /** @internal */
+ protected QROutputInterface $outputInterface;
+ /** @internal */
+ protected QROptions $options;
+ /** @internal */
+ protected QRMatrix $matrix;
/**
- * @var \chillerlan\QRCode\Output\QROutputInterface
+ * Attempts to create a directory under /.build and instances several required objects
+ *
+ * @internal
*/
- protected $outputInterface;
+ protected function setUp():void{
+
+ if(!file_exists($this->builddir)){
+ mkdir($this->builddir, 0777, true);
+ }
+
+ $this->options = new QROptions;
+ $this->matrix = (new Byte($this->options, 'testdata'))->initMatrix(0);
+ $this->outputInterface = $this->getOutputInterface($this->options);
+ }
/**
- * @var \chillerlan\QRCode\QROptions
+ * Returns a QROutputInterface instance with the given options and using $this->matrix
+ *
+ * @internal
*/
- protected $options;
+ abstract protected function getOutputInterface(QROptions $options):QROutputInterface;
/**
- * @var \chillerlan\QRCode\Data\QRMatrix
+ * Validate the instance of the interface
*/
- protected $matrix;
-
- protected function setUp():void{
- parent::setUp();
+ public function testInstance():void{
+ $this::assertInstanceOf(QROutputInterface::class, $this->outputInterface);
+ }
- $buildDir = dirname($this::cachefile);
- if(!file_exists($buildDir)){
- mkdir($buildDir, 0777, true);
- }
+ /**
+ * 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('Could not write data to cache file: /foo/bar.test');
- $this->options = new QROptions;
- $this->setOutputInterface();
+ $this->options->cachefile = '/foo/bar.test';
+ $this->outputInterface = $this->getOutputInterface($this->options);
+ $this->outputInterface->dump();
}
- protected function setOutputInterface(){
- $this->outputInterface = $this->reflection->newInstanceArgs([$this->options, (new Byte($this->options, 'testdata'))->initMatrix(0)]);
- return $this->outputInterface;
- }
+ /**
+ * covers the module values settings
+ */
+ abstract public function testSetModuleValues():void;
- public function testInstance(){
- $this->assertInstanceOf(QROutputInterface::class, $this->outputInterface);
+ /*
+ * additional, non-essential, potentially inaccurate coverage tests
+ */
+
+ /**
+ * @see testStringOutput()
+ * @return string[][]
+ * @internal
+ */
+ abstract public function types():array;
+
+ /**
+ * coverage of the built-in output modules
+ *
+ * @dataProvider types
+ */
+ public function testStringOutput(string $type):void{
+ $this->options->outputType = $type;
+ $this->options->cachefile = $this->builddir.'/test.'.$type;
+ $this->options->imageBase64 = false;
+
+ $this->outputInterface = $this->getOutputInterface($this->options);
+ $data = $this->outputInterface->dump(); // creates the cache file
+
+ $this::assertSame($data, file_get_contents($this->options->cachefile));
}
- public function testSaveException(){
- $this->expectException(QRCodeOutputException::class);
- $this->expectExceptionMessage('Could not write data to cache file: /foo');
+ /**
+ * covers the built-in output modules, tests against pre-rendered data
+ *
+ * @dataProvider types
+ */
+ public function testRenderImage(string $type):void{
+
+ // may fail on CI, different PHP (platform) versions produce different output
+ // the samples were generated on php-7.4.3-Win32-vc15-x64
+ if(
+ (PHP_OS_FAMILY !== 'Windows' || PHP_VERSION_ID >= 80100)
+ && in_array($type, [QRCode::OUTPUT_IMAGE_JPG, QRCode::OUTPUT_IMAGICK, QRCode::OUTPUT_MARKUP_SVG])
+ ){
+ $this::markTestSkipped('may fail on CI');
+
+ /** @noinspection PhpUnreachableStatementInspection */
+ return;
+ }
- $this->options->cachefile = '/foo';
- $this->setOutputInterface();
- $this->outputInterface->dump();
+ $this->options->outputType = $type;
+
+ $this::assertSame(
+ trim(file_get_contents(__DIR__.'/samples/'.$type)),
+ trim((new QRCode($this->options))->render('test'))
+ );
}
}