QRFpdfTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 chillerlan\QRCode\QROptions;
  12. use chillerlan\QRCode\Data\QRMatrix;
  13. use chillerlan\QRCode\Output\{QRFpdf, QROutputInterface};
  14. use chillerlan\Settings\SettingsContainerInterface;
  15. use FPDF;
  16. use function class_exists;
  17. /**
  18. * Tests the QRFpdf output module
  19. */
  20. final class QRFpdfTest extends QROutputTestAbstract{
  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. protected function getOutputInterface(
  31. SettingsContainerInterface|QROptions $options,
  32. QRMatrix $matrix
  33. ):QROutputInterface{
  34. return new QRFpdf($options, $matrix);
  35. }
  36. public static function moduleValueProvider():array{
  37. return [
  38. 'valid: int' => [[123, 123, 123], true],
  39. 'valid: w/invalid extra element' => [[123, 123, 123, 'abc'], true],
  40. 'valid: numeric string' => [['123', '123', '123'], true],
  41. 'invalid: wrong type' => ['foo', false],
  42. 'invalid: array too short' => [[1, 2], false],
  43. 'invalid: contains non-number' => [[1, 'b', 3], false],
  44. ];
  45. }
  46. /**
  47. * @inheritDoc
  48. */
  49. public function testSetModuleValues():void{
  50. $this->options->moduleValues = [
  51. // data
  52. QRMatrix::M_DATA_DARK => [0, 0, 0],
  53. QRMatrix::M_DATA => [255, 255, 255],
  54. ];
  55. $this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
  56. $this->outputInterface->dump();
  57. $this::assertTrue(true); // tricking the code coverage
  58. }
  59. public function testOutputGetResource():void{
  60. $this->options->returnResource = true;
  61. $this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
  62. $this::assertInstanceOf(FPDF::class, $this->outputInterface->dump());
  63. }
  64. }