DatainterfaceTestAbstract.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /**
  18. * @var \chillerlan\QRCode\Data\QRDataAbstract
  19. */
  20. protected $dataInterface;
  21. protected $testdata;
  22. protected $expected;
  23. protected function setUp():void{
  24. parent::setUp();
  25. $this->dataInterface = $this->reflection->newInstanceArgs([new QROptions(['version' => 4])]);
  26. }
  27. public function testInstance(){
  28. $this->dataInterface = $this->reflection->newInstanceArgs([new QROptions, $this->testdata]);
  29. $this->assertInstanceOf(QRDataInterface::class, $this->dataInterface);
  30. }
  31. public function testSetData(){
  32. $this->dataInterface->setData($this->testdata);
  33. $this->assertSame($this->expected, $this->getProperty('matrixdata')->getValue($this->dataInterface));
  34. }
  35. public function testInitMatrix(){
  36. $m = $this->dataInterface->setData($this->testdata)->initMatrix(0);
  37. $this->assertInstanceOf(QRMatrix::class, $m);
  38. }
  39. public function testGetMinimumVersion(){
  40. $this->assertSame(1, $this->getMethod('getMinimumVersion')->invoke($this->dataInterface));
  41. }
  42. public function testGetMinimumVersionException(){
  43. $this->expectException(QRCodeDataException::class);
  44. $this->expectExceptionMessage('data exceeds');
  45. $this->getProperty('strlen')->setValue($this->dataInterface, 13370);
  46. $this->getMethod('getMinimumVersion')->invoke($this->dataInterface);
  47. }
  48. }