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] 68bc5019c8 (diff-359c7f7a6d32d9935951e1b0742eb116fb654f4a932c8d40328bb5dcab2fa111L162)
[2] https://github.com/chillerlan/php-qrcode/issues/97
152 lines
4.5 KiB
PHP
Executable File
152 lines
4.5 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Class QRCodeTest
|
|
*
|
|
* @filesource QRCodeTest.php
|
|
* @created 17.11.2017
|
|
* @package chillerlan\QRCodeTest
|
|
* @author Smiley <smiley@chillerlan.net>
|
|
* @copyright 2017 Smiley
|
|
* @license MIT
|
|
*/
|
|
|
|
namespace chillerlan\QRCodeTest;
|
|
|
|
use chillerlan\QRCode\{QROptions, QRCode};
|
|
use chillerlan\QRCode\Data\{AlphaNum, Byte, Kanji, Number, QRCodeDataException};
|
|
use chillerlan\QRCode\Output\QRCodeOutputException;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use function random_bytes;
|
|
|
|
/**
|
|
* Tests basic functions of the QRCode class
|
|
*/
|
|
class QRCodeTest extends TestCase{
|
|
|
|
/** @internal */
|
|
protected QRCode $qrcode;
|
|
/** @internal */
|
|
protected QROptions $options;
|
|
|
|
/**
|
|
* invoke test instances
|
|
*
|
|
* @internal
|
|
*/
|
|
protected function setUp():void{
|
|
$this->qrcode = new QRCode;
|
|
$this->options = new QROptions;
|
|
}
|
|
|
|
/**
|
|
* isNumber() should pass on any number and fail on anything else
|
|
*/
|
|
public function testIsNumber():void{
|
|
$this::assertTrue($this->qrcode->isNumber('0123456789'));
|
|
|
|
$this::assertFalse($this->qrcode->isNumber('ABC123'));
|
|
}
|
|
|
|
/**
|
|
* isAlphaNum() should pass on the 45 defined characters and fail on anything else (e.g. lowercase)
|
|
*/
|
|
public function testIsAlphaNum():void{
|
|
$this::assertTrue($this->qrcode->isAlphaNum('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'));
|
|
|
|
$this::assertFalse($this->qrcode->isAlphaNum('abc'));
|
|
}
|
|
|
|
/**
|
|
* isKanji() should pass on Kanji/SJIS characters and fail on everything else
|
|
*/
|
|
public function testIsKanji():void{
|
|
$this::assertTrue($this->qrcode->isKanji('茗荷'));
|
|
|
|
$this::assertFalse($this->qrcode->isKanji('Ã'));
|
|
$this::assertFalse($this->qrcode->isKanji('ABC'));
|
|
$this::assertFalse($this->qrcode->isKanji('123'));
|
|
}
|
|
|
|
/**
|
|
* isByte() passses any binary string and only fails on empty strings
|
|
*/
|
|
public function testIsByte():void{
|
|
$this::assertTrue($this->qrcode->isByte("\x01\x02\x03"));
|
|
$this::assertTrue($this->qrcode->isByte(' ')); // not empty!
|
|
|
|
$this::assertFalse($this->qrcode->isByte(''));
|
|
}
|
|
|
|
/**
|
|
* tests if an exception is thrown when an invalid (built-in) output type is specified
|
|
*/
|
|
public function testInitDataInterfaceException():void{
|
|
$this->expectException(QRCodeOutputException::class);
|
|
$this->expectExceptionMessage('invalid output type');
|
|
|
|
$this->options->outputType = 'foo';
|
|
|
|
(new QRCode($this->options))->render('test');
|
|
}
|
|
|
|
/**
|
|
* tests if an exception is thrown when trying to call getMatrix() without data (empty string, no data set)
|
|
*/
|
|
public function testGetMatrixException():void{
|
|
$this->expectException(QRCodeDataException::class);
|
|
$this->expectExceptionMessage('QRCode::getMatrix() No data given.');
|
|
|
|
$this->qrcode->getMatrix('');
|
|
}
|
|
|
|
/**
|
|
* test whether stings are trimmed (they are not) - i'm still torn on that (see isByte)
|
|
*/
|
|
public function testAvoidTrimming():void{
|
|
$m1 = $this->qrcode->getMatrix('hello')->matrix();
|
|
$m2 = $this->qrcode->getMatrix('hello ')->matrix(); // added space
|
|
|
|
$this::assertNotSame($m1, $m2);
|
|
}
|
|
|
|
/**
|
|
* tests if the data mode is overriden if QROptions::$dataModeOverride is set to a valid value
|
|
*
|
|
* @see https://github.com/chillerlan/php-qrcode/issues/39
|
|
*/
|
|
public function testDataModeOverride():void{
|
|
|
|
// no (or invalid) value set - auto detection
|
|
$this->options->dataModeOverride = 'foo';
|
|
$this->qrcode = new QRCode;
|
|
|
|
$this::assertInstanceOf(Number::class, $this->qrcode->initDataInterface('123'));
|
|
$this::assertInstanceOf(AlphaNum::class, $this->qrcode->initDataInterface('ABC123'));
|
|
$this::assertInstanceOf(Byte::class, $this->qrcode->initDataInterface(random_bytes(32)));
|
|
$this::assertInstanceOf(Kanji::class, $this->qrcode->initDataInterface('茗荷'));
|
|
|
|
// data mode set: force the given data mode
|
|
$this->options->dataModeOverride = 'Byte';
|
|
$this->qrcode = new QRCode($this->options);
|
|
|
|
$this::assertInstanceOf(Byte::class, $this->qrcode->initDataInterface('123'));
|
|
$this::assertInstanceOf(Byte::class, $this->qrcode->initDataInterface('ABC123'));
|
|
$this::assertInstanceOf(Byte::class, $this->qrcode->initDataInterface(random_bytes(32)));
|
|
$this::assertInstanceOf(Byte::class, $this->qrcode->initDataInterface('茗荷'));
|
|
}
|
|
|
|
/**
|
|
* tests if an exception is thrown when an invalid character occurs when forcing a data mode other than Byte
|
|
*/
|
|
public function testDataModeOverrideError():void{
|
|
$this->expectException(QRCodeDataException::class);
|
|
$this->expectExceptionMessage('illegal char:');
|
|
|
|
$this->options->dataModeOverride = 'AlphaNum';
|
|
|
|
(new QRCode($this->options))->initDataInterface(random_bytes(32));
|
|
}
|
|
|
|
}
|