QROutputTestAbstract.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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(){
  35. $this->outputInterface = $this->reflection->newInstanceArgs([$this->options, (new Byte($this->options, 'testdata'))->initMatrix(0)]);
  36. return $this->outputInterface;
  37. }
  38. public function testInstance(){
  39. $this::assertInstanceOf(QROutputInterface::class, $this->outputInterface);
  40. }
  41. public function testSaveException(){
  42. $this->expectException(QRCodeOutputException::class);
  43. $this->expectExceptionMessage('Could not write data to cache file: /foo');
  44. $this->options->cachefile = '/foo';
  45. $this->setOutputInterface();
  46. $this->outputInterface->dump();
  47. }
  48. }