QROutputTestAbstract.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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, QRMatrix};
  15. use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
  16. use chillerlan\QRCodeTest\QRTestAbstract;
  17. use chillerlan\Settings\SettingsContainerInterface;
  18. use function dirname, file_exists, mkdir;
  19. abstract class QROutputTestAbstract extends QRTestAbstract{
  20. protected const cachefile = __DIR__.'/../../.build/output_test/test.';
  21. protected QROutputInterface $outputInterface;
  22. /** @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\QRCode\QROptions */
  23. protected SettingsContainerInterface $options;
  24. protected QRMatrix $matrix;
  25. protected function setUp():void{
  26. parent::setUp();
  27. $buildDir = dirname($this::cachefile);
  28. if(!file_exists($buildDir)){
  29. mkdir($buildDir, 0777, true);
  30. }
  31. $this->options = new QROptions;
  32. $this->setOutputInterface();
  33. }
  34. protected function setOutputInterface():QROutputInterface{
  35. /** @noinspection PhpFieldAssignmentTypeMismatchInspection */
  36. $this->outputInterface = $this->reflection->newInstanceArgs([$this->options, (new Byte($this->options, 'testdata'))->initMatrix(0)]);
  37. return $this->outputInterface;
  38. }
  39. public function testInstance():void{
  40. $this::assertInstanceOf(QROutputInterface::class, $this->outputInterface);
  41. }
  42. public function testSaveException():void{
  43. $this->expectException(QRCodeOutputException::class);
  44. $this->expectExceptionMessage('Could not write data to cache file: /foo');
  45. $this->options->cachefile = '/foo';
  46. $this->setOutputInterface();
  47. $this->outputInterface->dump();
  48. }
  49. }