QROutputTestAbstract.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Class QROutputTestAbstract
  4. *
  5. * @filesource QROutputTestAbstract.php
  6. * @created 24.12.2017
  7. * @package chillerlan\QRCodeTest\Output
  8. * @author Smiley <smiley@chillerlan.net>
  9. * @copyright 2017 Smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCodeTest\Output;
  13. use chillerlan\QRCode\QROptions;
  14. use chillerlan\QRCode\Data\Byte;
  15. use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
  16. use chillerlan\QRCodeTest\QRTestAbstract;
  17. use function dirname, file_exists, mkdir;
  18. abstract class QROutputTestAbstract extends QRTestAbstract{
  19. const cachefile = __DIR__.'/../../.build/output_test/test.';
  20. /**
  21. * @var \chillerlan\QRCode\Output\QROutputInterface
  22. */
  23. protected $outputInterface;
  24. /**
  25. * @var \chillerlan\QRCode\QROptions
  26. */
  27. protected $options;
  28. /**
  29. * @var \chillerlan\QRCode\Data\QRMatrix
  30. */
  31. protected $matrix;
  32. protected function setUp():void{
  33. parent::setUp();
  34. $buildDir = dirname($this::cachefile);
  35. if(!file_exists($buildDir)){
  36. mkdir($buildDir, 0777, true);
  37. }
  38. $this->options = new QROptions;
  39. $this->setOutputInterface();
  40. }
  41. protected function setOutputInterface(){
  42. $this->outputInterface = $this->reflection->newInstanceArgs([$this->options, (new Byte($this->options, 'testdata'))->initMatrix(0)]);
  43. return $this->outputInterface;
  44. }
  45. public function testInstance(){
  46. $this->assertInstanceOf(QROutputInterface::class, $this->outputInterface);
  47. }
  48. public function testSaveException(){
  49. $this->expectException(QRCodeOutputException::class);
  50. $this->expectExceptionMessage('Could not write data to cache file: /foo');
  51. $this->options->cachefile = '/foo';
  52. $this->setOutputInterface();
  53. $this->outputInterface->dump();
  54. }
  55. }