QRFpdfTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Class QRFpdfTest
  4. *
  5. * @created 03.06.2020
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2020 smiley
  8. * @license MIT
  9. */
  10. namespace chillerlan\QRCodeTest\Output;
  11. use FPDF;
  12. use chillerlan\QRCode\Data\QRMatrix;
  13. use chillerlan\QRCode\Output\{QRFpdf, QROutputInterface};
  14. use function class_exists;
  15. /**
  16. * Tests the QRFpdf output module
  17. */
  18. final class QRFpdfTest extends QROutputTestAbstract{
  19. protected string $FQN = QRFpdf::class;
  20. protected string $type = QROutputInterface::FPDF;
  21. /**
  22. * @inheritDoc
  23. */
  24. protected function setUp():void{
  25. if(!class_exists(FPDF::class)){
  26. $this::markTestSkipped('FPDF not available');
  27. }
  28. parent::setUp();
  29. }
  30. public static function moduleValueProvider():array{
  31. return [
  32. 'valid: int' => [[123, 123, 123], true],
  33. 'valid: w/invalid extra element' => [[123, 123, 123, 'abc'], true],
  34. 'valid: numeric string' => [['123', '123', '123'], true],
  35. 'invalid: wrong type' => ['foo', false],
  36. 'invalid: array too short' => [[1, 2], false],
  37. 'invalid: contains non-number' => [[1, 'b', 3], false],
  38. ];
  39. }
  40. /**
  41. * @inheritDoc
  42. */
  43. public function testSetModuleValues():void{
  44. $this->options->moduleValues = [
  45. // data
  46. QRMatrix::M_DATA_DARK => [0, 0, 0],
  47. QRMatrix::M_DATA => [255, 255, 255],
  48. ];
  49. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  50. $this->outputInterface->dump();
  51. $this::assertTrue(true); // tricking the code coverage
  52. }
  53. public function testOutputGetResource():void{
  54. $this->options->returnResource = true;
  55. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  56. $this::assertInstanceOf(FPDF::class, $this->outputInterface->dump());
  57. }
  58. }