diff --git a/composer.json b/composer.json index 63e4f5ab9..5e0273d5a 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "chillerlan/php-settings-container": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^7.5" + "phpunit/phpunit": "^8.0" }, "autoload": { "psr-4": { diff --git a/tests/Data/AlphaNumTest.php b/tests/Data/AlphaNumTest.php index ec06a5818..c29b1f639 100644 --- a/tests/Data/AlphaNumTest.php +++ b/tests/Data/AlphaNumTest.php @@ -12,7 +12,7 @@ namespace chillerlan\QRCodeTest\Data; -use chillerlan\QRCode\Data\AlphaNum; +use chillerlan\QRCode\Data\{AlphaNum, QRCodeDataException}; class AlphaNumTest extends DatainterfaceTestAbstract{ @@ -34,11 +34,10 @@ class AlphaNumTest extends DatainterfaceTestAbstract{ 92, 112, 20, 198, 27 ]; - /** - * @expectedException \chillerlan\QRCode\Data\QRCodeDataException - * @expectedExceptionMessage illegal char: "#" [35] - */ public function testGetCharCodeException(){ + $this->expectException(QRCodeDataException::class); + $this->expectExceptionMessage('illegal char: "#" [35]'); + $this->dataInterface->setData('#'); } diff --git a/tests/Data/DatainterfaceTestAbstract.php b/tests/Data/DatainterfaceTestAbstract.php index d8f040250..19d74617a 100644 --- a/tests/Data/DatainterfaceTestAbstract.php +++ b/tests/Data/DatainterfaceTestAbstract.php @@ -12,7 +12,8 @@ namespace chillerlan\QRCodeTest\Data; -use chillerlan\QRCode\{QROptions, Data\QRDataInterface, Data\QRMatrix}; +use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\Data\{QRCodeDataException, QRDataInterface, QRMatrix}; use chillerlan\QRCodeTest\QRTestAbstract; abstract class DatainterfaceTestAbstract extends QRTestAbstract{ @@ -25,7 +26,7 @@ abstract class DatainterfaceTestAbstract extends QRTestAbstract{ protected $testdata; protected $expected; - protected function setUp(){ + protected function setUp():void{ parent::setUp(); $this->dataInterface = $this->reflection->newInstanceArgs([new QROptions(['version' => 4])]); @@ -53,11 +54,10 @@ abstract class DatainterfaceTestAbstract extends QRTestAbstract{ $this->assertSame(1, $this->getMethod('getMinimumVersion')->invoke($this->dataInterface)); } - /** - * @expectedException \chillerlan\QRCode\Data\QRCodeDataException - * @expectedExceptionMessage data exceeds - */ public function testGetMinimumVersionException(){ + $this->expectException(QRCodeDataException::class); + $this->expectExceptionMessage('data exceeds'); + $this->getProperty('strlen')->setValue($this->dataInterface, 13370); $this->getMethod('getMinimumVersion')->invoke($this->dataInterface); } diff --git a/tests/Data/KanjiTest.php b/tests/Data/KanjiTest.php index 3a66ae770..108b8fed7 100644 --- a/tests/Data/KanjiTest.php +++ b/tests/Data/KanjiTest.php @@ -12,7 +12,7 @@ namespace chillerlan\QRCodeTest\Data; -use chillerlan\QRCode\Data\Kanji; +use chillerlan\QRCode\Data\{Kanji, QRCodeDataException}; class KanjiTest extends DatainterfaceTestAbstract{ @@ -34,19 +34,17 @@ class KanjiTest extends DatainterfaceTestAbstract{ 96, 113, 54, 191 ]; - /** - * @expectedException \chillerlan\QRCode\Data\QRCodeDataException - * @expectedExceptionMessage illegal char at 1 [16191] - */ public function testIllegalCharException1(){ + $this->expectException(QRCodeDataException::class); + $this->expectExceptionMessage('illegal char at 1 [16191]'); + $this->dataInterface->setData('ÃÃ'); } - /** - * @expectedException \chillerlan\QRCode\Data\QRCodeDataException - * @expectedExceptionMessage illegal char at 1 - */ public function testIllegalCharException2(){ + $this->expectException(QRCodeDataException::class); + $this->expectExceptionMessage('illegal char at 1'); + $this->dataInterface->setData('Ã'); } } diff --git a/tests/Data/NumberTest.php b/tests/Data/NumberTest.php index 8327cb2f5..983346a34 100644 --- a/tests/Data/NumberTest.php +++ b/tests/Data/NumberTest.php @@ -12,7 +12,7 @@ namespace chillerlan\QRCodeTest\Data; -use chillerlan\QRCode\Data\Number; +use chillerlan\QRCode\Data\{Number, QRCodeDataException}; class NumberTest extends DatainterfaceTestAbstract{ @@ -34,11 +34,10 @@ class NumberTest extends DatainterfaceTestAbstract{ 89, 63, 168, 151 ]; - /** - * @expectedException \chillerlan\QRCode\Data\QRCodeDataException - * @expectedExceptionMessage illegal char: "#" [35] - */ public function testGetCharCodeException(){ + $this->expectException(QRCodeDataException::class); + $this->expectExceptionMessage('illegal char: "#" [35]'); + $this->dataInterface->setData('#'); } diff --git a/tests/Data/QRMatrixTest.php b/tests/Data/QRMatrixTest.php index 7b77e44c3..95ec581db 100755 --- a/tests/Data/QRMatrixTest.php +++ b/tests/Data/QRMatrixTest.php @@ -12,7 +12,8 @@ namespace chillerlan\QRCodeTest\Data; -use chillerlan\QRCode\{QRCode, Data\QRMatrix}; +use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\Data\{QRCodeDataException, QRMatrix}; use chillerlan\QRCodeTest\QRTestAbstract; use ReflectionClass; @@ -67,25 +68,23 @@ class QRMatrixTest extends QRTestAbstract{ */ protected $matrix; - protected function setUp(){ + protected function setUp():void{ parent::setUp(); $this->matrix = $this->reflection->newInstanceArgs([$this->version, QRCode::ECC_L]); } - /** - * @expectedException \chillerlan\QRCode\Data\QRCodeDataException - * @expectedExceptionMessage invalid QR Code version - */ public function testInvalidVersionException(){ + $this->expectException(QRCodeDataException::class); + $this->expectExceptionMessage('invalid QR Code version'); + $this->reflection->newInstanceArgs([42, 0]); } - /** - * @expectedException \chillerlan\QRCode\Data\QRCodeDataException - * @expectedExceptionMessage invalid ecc level - */ public function testInvalidEccException(){ + $this->expectException(QRCodeDataException::class); + $this->expectExceptionMessage('invalid ecc level'); + $this->reflection->newInstanceArgs([1, 42]); } @@ -234,11 +233,10 @@ class QRMatrixTest extends QRTestAbstract{ $this->assertSame(QRMatrix::M_TEST << 8, $this->matrix->get($size - 1 - $q, $size - 1 - $q)); } - /** - * @expectedException \chillerlan\QRCode\Data\QRCodeDataException - * @expectedExceptionMessage use only after writing data - */ public function testSetQuietZoneException(){ + $this->expectException(QRCodeDataException::class); + $this->expectExceptionMessage('use only after writing data'); + $this->matrix->setQuietZone(); } diff --git a/tests/Helpers/BitBufferTest.php b/tests/Helpers/BitBufferTest.php index 2e9aff3cb..25d1c3504 100644 --- a/tests/Helpers/BitBufferTest.php +++ b/tests/Helpers/BitBufferTest.php @@ -22,7 +22,7 @@ class BitBufferTest extends QRTestAbstract{ */ protected $bitBuffer; - protected function setUp(){ + protected function setUp():void{ $this->bitBuffer = new BitBuffer; } diff --git a/tests/Helpers/PolynomialTest.php b/tests/Helpers/PolynomialTest.php index 396fe2a24..7f6da303c 100644 --- a/tests/Helpers/PolynomialTest.php +++ b/tests/Helpers/PolynomialTest.php @@ -13,6 +13,7 @@ namespace chillerlan\QRCodeTest\Helpers; use chillerlan\QRCode\Helpers\Polynomial; +use chillerlan\QRCode\QRCodeException; use chillerlan\QRCodeTest\QRTestAbstract; class PolynomialTest extends QRTestAbstract{ @@ -22,7 +23,7 @@ class PolynomialTest extends QRTestAbstract{ */ protected $polynomial; - protected function setUp(){ + protected function setUp():void{ $this->polynomial = new Polynomial; } @@ -32,11 +33,10 @@ class PolynomialTest extends QRTestAbstract{ $this->assertSame(2, $this->polynomial->gexp(256)); } - /** - * @expectedException \chillerlan\QRCode\QRCodeException - * @expectedExceptionMessage log(0) - */ public function testGlogException(){ + $this->expectException(QRCodeException::class); + $this->expectExceptionMessage('log(0)'); + $this->polynomial->glog(0); } } diff --git a/tests/Output/QROutputTestAbstract.php b/tests/Output/QROutputTestAbstract.php index ce2dc394c..765b6de3f 100644 --- a/tests/Output/QROutputTestAbstract.php +++ b/tests/Output/QROutputTestAbstract.php @@ -12,7 +12,9 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\{QROptions, Data\Byte, Output\QROutputInterface}; +use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\Data\Byte; +use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface}; use chillerlan\QRCodeTest\QRTestAbstract; /** @@ -36,7 +38,7 @@ abstract class QROutputTestAbstract extends QRTestAbstract{ */ protected $matrix; - protected function setUp(){ + protected function setUp():void{ parent::setUp(); $this->options = new QROptions; @@ -52,11 +54,10 @@ abstract class QROutputTestAbstract extends QRTestAbstract{ $this->assertInstanceOf(QROutputInterface::class, $this->outputInterface); } - /** - * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException - * @expectedExceptionMessage Could not write data to cache file: /foo - */ public function testSaveException(){ + $this->expectException(QRCodeOutputException::class); + $this->expectExceptionMessage('Could not write data to cache file: /foo'); + $this->options->cachefile = '/foo'; $this->setOutputInterface(); $this->outputInterface->dump(); diff --git a/tests/QRCodeTest.php b/tests/QRCodeTest.php index 33a841eb1..ce311edf5 100755 --- a/tests/QRCodeTest.php +++ b/tests/QRCodeTest.php @@ -12,8 +12,9 @@ namespace chillerlan\QRCodeTest; -use chillerlan\QRCode\QROptions; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\{QROptions, QRCode}; +use chillerlan\QRCode\Data\QRCodeDataException; +use chillerlan\QRCode\Output\QRCodeOutputException; use chillerlan\QRCodeExamples\MyCustomOutput; class QRCodeTest extends QRTestAbstract{ @@ -25,7 +26,7 @@ class QRCodeTest extends QRTestAbstract{ */ protected $qrcode; - protected function setUp(){ + protected function setUp():void{ parent::setUp(); $this->qrcode = $this->reflection->newInstance(); @@ -67,22 +68,20 @@ class QRCodeTest extends QRTestAbstract{ public function testRenderImage($type, $expected){ $this->qrcode = $this->reflection->newInstanceArgs([new QROptions(['outputType' => $type])]); - $this->assertContains($expected, $this->qrcode->render('test')); + $this->assertStringContainsString($expected, $this->qrcode->render('test')); } - /** - * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException - * @expectedExceptionMessage invalid output type - */ public function testInitDataInterfaceException(){ + $this->expectException(QRCodeOutputException::class); + $this->expectExceptionMessage('invalid output type'); + (new QRCode(new QROptions(['outputType' => 'foo'])))->render('test'); } - /** - * @expectedException \chillerlan\QRCode\Data\QRCodeDataException - * @expectedExceptionMessage QRCode::getMatrix() No data given. - */ public function testGetMatrixException(){ + $this->expectException(QRCodeDataException::class); + $this->expectExceptionMessage('QRCode::getMatrix() No data given.'); + $this->qrcode->getMatrix(''); } diff --git a/tests/QROptionsTest.php b/tests/QROptionsTest.php index b21d6daf4..41bf69ced 100644 --- a/tests/QROptionsTest.php +++ b/tests/QROptionsTest.php @@ -12,7 +12,7 @@ namespace chillerlan\QRCodeTest; -use chillerlan\QRCode\{QRCode,QROptions}; +use chillerlan\QRCode\{QRCode, QRCodeException, QROptions}; use PHPUnit\Framework\TestCase; class QROptionsTest extends TestCase{ @@ -56,11 +56,10 @@ class QROptionsTest extends TestCase{ $this->assertSame(QRCode::MASK_PATTERN_AUTO, (new QROptions)->maskPattern); // QRCode::MASK_PATTERN_AUTO = -1, default } - /** - * @expectedException \chillerlan\QRCode\QRCodeException - * @expectedExceptionMessage Invalid error correct level: 42 - */ public function testInvalidEccLevelException(){ + $this->expectException(QRCodeException::class); + $this->expectExceptionMessage('Invalid error correct level: 42'); + new QROptions(['eccLevel' => 42]); } @@ -72,11 +71,10 @@ class QROptionsTest extends TestCase{ $this->assertSame(255, $o->imageTransparencyBG[2]); } - /** - * @expectedException \chillerlan\QRCode\QRCodeException - * @expectedExceptionMessage Invalid RGB value. - */ public function testInvalidRGBValueException(){ + $this->expectException(QRCodeException::class); + $this->expectExceptionMessage('Invalid RGB value.'); + new QROptions(['imageTransparencyBG' => ['r', 'g', 'b']]); } } diff --git a/tests/QRTestAbstract.php b/tests/QRTestAbstract.php index 830951c69..7b9eb8049 100644 --- a/tests/QRTestAbstract.php +++ b/tests/QRTestAbstract.php @@ -27,7 +27,7 @@ abstract class QRTestAbstract extends TestCase{ */ protected $FQCN; - protected function setUp(){ + protected function setUp():void{ $this->reflection = new ReflectionClass($this->FQCN); }