DatainterfaceTestAbstract.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Class DatainterfaceTestAbstract
  4. *
  5. * @filesource DatainterfaceTestAbstract.php
  6. * @created 24.11.2017
  7. * @package chillerlan\QRCodeTest\Data
  8. * @author Smiley <smiley@chillerlan.net>
  9. * @copyright 2017 Smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCodeTest\Data;
  13. use chillerlan\QRCode\QROptions;
  14. use chillerlan\QRCode\Data\{QRCodeDataException, QRDataInterface, QRMatrix};
  15. use chillerlan\QRCodeTest\QRTestAbstract;
  16. abstract class DatainterfaceTestAbstract extends QRTestAbstract{
  17. protected QRDataInterface $dataInterface;
  18. protected string $testdata;
  19. protected array $expected;
  20. protected function setUp():void{
  21. parent::setUp();
  22. $this->dataInterface = $this->reflection->newInstanceArgs([new QROptions(['version' => 4])]);
  23. }
  24. public function testInstance(){
  25. $this->dataInterface = $this->reflection->newInstanceArgs([new QROptions, $this->testdata]);
  26. $this::assertInstanceOf(QRDataInterface::class, $this->dataInterface);
  27. }
  28. public function testSetData(){
  29. $this->dataInterface->setData($this->testdata);
  30. $this::assertSame($this->expected, $this->getProperty('matrixdata')->getValue($this->dataInterface));
  31. }
  32. public function testInitMatrix(){
  33. $m = $this->dataInterface->setData($this->testdata)->initMatrix(0);
  34. $this::assertInstanceOf(QRMatrix::class, $m);
  35. }
  36. public function testGetMinimumVersion(){
  37. $this::assertSame(1, $this->getMethod('getMinimumVersion')->invoke($this->dataInterface));
  38. }
  39. public function testGetMinimumVersionException(){
  40. $this->expectException(QRCodeDataException::class);
  41. $this->expectExceptionMessage('data exceeds');
  42. $this->getProperty('strlen')->setValue($this->dataInterface, 13370);
  43. $this->getMethod('getMinimumVersion')->invoke($this->dataInterface);
  44. }
  45. public function testCodeLengthOverflowException(){
  46. $this->expectException(QRCodeDataException::class);
  47. $this->expectExceptionMessage('code length overflow');
  48. $this->dataInterface->setData(\str_repeat('0', 1337));
  49. }
  50. }