From 2dde546ef9a7b56bfcda94541a74d117851c3d89 Mon Sep 17 00:00:00 2001 From: codemasher Date: Wed, 19 Feb 2020 20:47:08 +0100 Subject: [PATCH] :octocat: proper overflow test & coverage --- src/Data/QRDataAbstract.php | 4 ++-- tests/Data/DatainterfaceTestAbstract.php | 6 ++++++ tests/Data/KanjiTest.php | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Data/QRDataAbstract.php b/src/Data/QRDataAbstract.php index 51b374204..62b0e78ef 100644 --- a/src/Data/QRDataAbstract.php +++ b/src/Data/QRDataAbstract.php @@ -181,9 +181,9 @@ abstract class QRDataAbstract implements QRDataInterface{ $this->write($data); - // there was an error writing the BitBuffer data, which is... unlikely. + // overflow, likely caused due to invalid version setting if($this->bitBuffer->length > $MAX_BITS){ - throw new QRCodeException(sprintf('code length overflow. (%d > %d bit)', $this->bitBuffer->length, $MAX_BITS)); // @codeCoverageIgnore + throw new QRCodeDataException(sprintf('code length overflow. (%d > %d bit)', $this->bitBuffer->length, $MAX_BITS)); } // end code. diff --git a/tests/Data/DatainterfaceTestAbstract.php b/tests/Data/DatainterfaceTestAbstract.php index af1cddbb2..e5bedb974 100644 --- a/tests/Data/DatainterfaceTestAbstract.php +++ b/tests/Data/DatainterfaceTestAbstract.php @@ -60,4 +60,10 @@ abstract class DatainterfaceTestAbstract extends QRTestAbstract{ $this->getMethod('getMinimumVersion')->invoke($this->dataInterface); } + public function testCodeLengthOverflowException(){ + $this->expectException(QRCodeDataException::class); + $this->expectExceptionMessage('code length overflow'); + + $this->dataInterface->setData(\str_repeat('0', 1337)); + } } diff --git a/tests/Data/KanjiTest.php b/tests/Data/KanjiTest.php index 8677dd5b9..ff22d932e 100644 --- a/tests/Data/KanjiTest.php +++ b/tests/Data/KanjiTest.php @@ -49,4 +49,12 @@ class KanjiTest extends DatainterfaceTestAbstract{ $this->dataInterface->setData('Ã'); } + + public function testCodeLengthOverflowException(){ + $this->expectException(QRCodeDataException::class); + $this->expectExceptionMessage('code length overflow'); + + $this->dataInterface->setData(\str_repeat('荷', 1337)); + } + }