diff options
author | Chih-Hsuan Yen <[email protected]> | 2022-07-02 22:01:51 +0800 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2022-07-12 22:23:48 +0300 |
commit | 4b6161892000cb2b8392dce92a9cf2cabdf2d20e (patch) | |
tree | 5cad602010e4d13e1a48d6b922d4768c0893ac8b /vendor/chillerlan/php-qrcode/tests/QROptionsTest.php | |
parent | d9861038bcc3cb2f38c7153bdca7d5ab89597afa (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/QROptionsTest.php')
-rw-r--r-- | vendor/chillerlan/php-qrcode/tests/QROptionsTest.php | 142 |
1 files changed, 103 insertions, 39 deletions
diff --git a/vendor/chillerlan/php-qrcode/tests/QROptionsTest.php b/vendor/chillerlan/php-qrcode/tests/QROptionsTest.php index 41bf69ced..3a0260623 100644 --- a/vendor/chillerlan/php-qrcode/tests/QROptionsTest.php +++ b/vendor/chillerlan/php-qrcode/tests/QROptionsTest.php @@ -8,6 +8,8 @@ * @author smiley <[email protected]> * @copyright 2018 smiley * @license MIT + * + * @noinspection PhpUnusedLocalVariableInspection */ namespace chillerlan\QRCodeTest; @@ -15,66 +17,128 @@ namespace chillerlan\QRCodeTest; use chillerlan\QRCode\{QRCode, QRCodeException, QROptions}; use PHPUnit\Framework\TestCase; +/** + * QROptions test + */ class QROptionsTest extends TestCase{ /** - * @var \chillerlan\QRCode\QROptions + * @see testVersionClamp() + * @return int[][] + * @internal + */ + public function VersionProvider():array{ + return [ + 'values > 40 should be clamped to 40' => [42, 40], + 'values < 1 should be clamped to 1' => [-42, 1], + 'values in between shold not be touched' => [21, 21], + 'value -1 should be treated as is (default)' => [QRCode::VERSION_AUTO, -1], + ]; + } + + /** + * Tests the $version clamping + * + * @dataProvider VersionProvider + */ + public function testVersionClamp(int $version, int $expected):void{ + $o = new QROptions(['version' => $version]); + + $this::assertSame($expected, $o->version); + } + + /** + * @see testVersionMinMaxClamp() + * @return int[][] + * @internal + */ + public function VersionMinMaxProvider():array{ + return [ + 'normal clamp' => [5, 10, 5, 10], + 'exceeding values' => [-42, 42, 1, 40], + 'min > max' => [10, 5, 5, 10], + 'min > max, exceeding' => [42, -42, 1, 40], + ]; + } + + /** + * Tests the $versionMin/$versionMax clamping + * + * @dataProvider VersionMinMaxProvider */ - protected $options; + public function testVersionMinMaxClamp(int $versionMin, int $versionMax, int $expectedMin, int $expectedMax):void{ + $o = new QROptions(['versionMin' => $versionMin, 'versionMax' => $versionMax]); - public function testVersionClamp(){ - $this->assertSame(40, (new QROptions(['version' => 42]))->version); - $this->assertSame(1, (new QROptions(['version' => -42]))->version); - $this->assertSame(21, (new QROptions(['version' => 21]))->version); - $this->assertSame(QRCode::VERSION_AUTO, (new QROptions)->version); // QRCode::VERSION_AUTO = -1, default + $this::assertSame($expectedMin, $o->versionMin); + $this::assertSame($expectedMax, $o->versionMax); } - public function testVersionMinMaxClamp(){ - // normal clamp - $o = new QROptions(['versionMin' => 5, 'versionMax' => 10]); - $this->assertSame(5, $o->versionMin); - $this->assertSame(10, $o->versionMax); - - // exceeding values - $o = new QROptions(['versionMin' => -42, 'versionMax' => 42]); - $this->assertSame(1, $o->versionMin); - $this->assertSame(40, $o->versionMax); - - // min > max - $o = new QROptions(['versionMin' => 10, 'versionMax' => 5]); - $this->assertSame(5, $o->versionMin); - $this->assertSame(10, $o->versionMax); - - $o = new QROptions(['versionMin' => 42, 'versionMax' => -42]); - $this->assertSame(1, $o->versionMin); - $this->assertSame(40, $o->versionMax); + /** + * @see testMaskPatternClamp() + * @return int[][] + * @internal + */ + public function MaskPatternProvider():array{ + return [ + 'exceed max' => [42, 7,], + 'exceed min' => [-42, 0], + 'default (-1)' => [QRCode::MASK_PATTERN_AUTO, -1], + ]; } - public function testMaskPatternClamp(){ - $this->assertSame(7, (new QROptions(['maskPattern' => 42]))->maskPattern); - $this->assertSame(0, (new QROptions(['maskPattern' => -42]))->maskPattern); - $this->assertSame(QRCode::MASK_PATTERN_AUTO, (new QROptions)->maskPattern); // QRCode::MASK_PATTERN_AUTO = -1, default + /** + * Tests the $maskPattern clamping + * + * @dataProvider MaskPatternProvider + */ + public function testMaskPatternClamp(int $maskPattern, int $expected):void{ + $o = new QROptions(['maskPattern' => $maskPattern]); + + $this::assertSame($expected, $o->maskPattern); } - public function testInvalidEccLevelException(){ + /** + * Tests if an exception is thrown on an incorrect ECC level + */ + public function testInvalidEccLevelException():void{ $this->expectException(QRCodeException::class); $this->expectExceptionMessage('Invalid error correct level: 42'); - new QROptions(['eccLevel' => 42]); + $o = new QROptions(['eccLevel' => 42]); + } + + /** + * @see testClampRGBValues() + * @return int[][][] + * @internal + */ + public function RGBProvider():array{ + return [ + 'exceeding values' => [[-1, 0, 999], [0, 0 ,255]], + 'too few values' => [[1, 2], [255, 255, 255]], + 'too many values' => [[1, 2, 3, 4, 5], [1, 2, 3]], + ]; } - public function testClampRGBValues(){ - $o = new QROptions(['imageTransparencyBG' => [-1, 0, 999]]); + /** + * Tests clamping of the RGB values for $imageTransparencyBG + * + * @dataProvider RGBProvider + */ + public function testClampRGBValues(array $rgb, array $expected):void{ + $o = new QROptions(['imageTransparencyBG' => $rgb]); - $this->assertSame(0, $o->imageTransparencyBG[0]); - $this->assertSame(0, $o->imageTransparencyBG[1]); - $this->assertSame(255, $o->imageTransparencyBG[2]); + $this::assertSame($expected, $o->imageTransparencyBG); } - public function testInvalidRGBValueException(){ + /** + * Tests if an exception is thrown when a non-numeric RGB value was encoutered + */ + public function testInvalidRGBValueException():void{ $this->expectException(QRCodeException::class); $this->expectExceptionMessage('Invalid RGB value.'); - new QROptions(['imageTransparencyBG' => ['r', 'g', 'b']]); + $o = new QROptions(['imageTransparencyBG' => ['r', 'g', 'b']]); } + } |