Просмотр исходного кода

:octocat: proper overflow test & coverage

codemasher 5 лет назад
Родитель
Сommit
2dde546ef9
3 измененных файлов с 16 добавлено и 2 удалено
  1. 2 2
      src/Data/QRDataAbstract.php
  2. 6 0
      tests/Data/DatainterfaceTestAbstract.php
  3. 8 0
      tests/Data/KanjiTest.php

+ 2 - 2
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.

+ 6 - 0
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));
+	}
 }

+ 8 - 0
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));
+	}
+
 }