| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- /**
- * Class DatainterfaceTestAbstract
- *
- * @created 24.11.2017
- * @author Smiley <smiley@chillerlan.net>
- * @copyright 2017 Smiley
- * @license MIT
- */
- namespace chillerlan\QRCodeTest\Data;
- use chillerlan\QRCode\Common\MaskPattern;
- use chillerlan\QRCode\QRCode;
- use chillerlan\QRCode\QROptions;
- use PHPUnit\Framework\TestCase;
- use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRMatrix};
- use ReflectionClass;
- use function str_repeat;
- /**
- * The data interface test abstract
- */
- abstract class DatainterfaceTestAbstract extends TestCase{
- /** @internal */
- protected ReflectionClass $reflection;
- /** @internal */
- protected QRData $dataInterface;
- /** @internal */
- protected array $testdata;
- /** @internal */
- protected array $expected;
- /**
- * @internal
- */
- protected function setUp():void{
- $this->dataInterface = new QRData(new QROptions(['version' => 4]), []);
- $this->reflection = new ReflectionClass($this->dataInterface);
- }
- protected function setTestData():void{
- [$class, $data] = $this->testdata;
- $this->dataInterface->setData([new $class($data)]);
- }
- /**
- * Verifies the data interface instance
- */
- public function testInstance():void{
- $this::assertInstanceOf(QRData::class, $this->dataInterface);
- }
- /**
- * Tests ecc masking and verifies against a sample
- */
- /* public function testMaskEcc():void{
- $this->dataInterface->setData([$this->testdata]);
- $maskECC = $this->reflection->getMethod('maskECC');
- $maskECC->setAccessible(true);
- $bitBuffer = $this->reflection->getProperty('bitBuffer');
- $bitBuffer->setAccessible(true);
- $bb = $bitBuffer->getValue($this->dataInterface);
- $this::assertSame($this->expected, $maskECC->invokeArgs($this->dataInterface, [$bb->getBuffer()]));
- }*/
- /**
- * @see testInitMatrix()
- * @internal
- * @return int[][]
- */
- public function MaskPatternProvider():array{
- return [[0], [1], [2], [3], [4], [5], [6], [7]];
- }
- /**
- * Tests initializing the data matrix
- *
- * @dataProvider MaskPatternProvider
- */
- public function testInitMatrix(int $maskPattern):void{
- $this->setTestData();
- $matrix = $this->dataInterface->writeMatrix(new MaskPattern($maskPattern));
- $this::assertInstanceOf(QRMatrix::class, $matrix);
- $this::assertSame($maskPattern, $matrix->maskPattern()->getPattern());
- }
- /**
- * Tests getting the minimum QR version for the given data
- */
- public function testGetMinimumVersion():void{
- $this->setTestData();
- $getMinimumVersion = $this->reflection->getMethod('getMinimumVersion');
- $getMinimumVersion->setAccessible(true);
- $this::assertSame(1, $getMinimumVersion->invoke($this->dataInterface));
- }
- /**
- * Tests if an exception is thrown when the data exceeds the maximum version while auto detecting
- */
- public function testGetMinimumVersionException():void{
- $this->expectException(QRCodeDataException::class);
- $this->expectExceptionMessage('data exceeds');
- [$class, $data] = $this->testdata;
- $this->dataInterface = new QRData(
- new QROptions(['version' => QRCode::VERSION_AUTO]),
- [new $class(str_repeat($data, 1337))]
- );
- }
- /**
- * Tests if an exception is thrown on data overflow
- */
- public function testCodeLengthOverflowException():void{
- $this->expectException(QRCodeDataException::class);
- $this->expectExceptionMessage('code length overflow');
- [$class, $data] = $this->testdata;
- $this->testdata = [$class, str_repeat($data, 1337)];
- $this->setTestData();
- }
- }
|