QRFpdfTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\{QRCode, QROptions};
  13. use chillerlan\QRCode\Data\QRMatrix;
  14. use chillerlan\QRCode\Output\{QRFpdf, QROutputInterface};
  15. use function class_exists, substr;
  16. /**
  17. * Tests the QRFpdf output module
  18. */
  19. final class QRFpdfTest extends QROutputTestAbstract{
  20. /**
  21. * @inheritDoc
  22. */
  23. protected function setUp():void{
  24. if(!class_exists(FPDF::class)){
  25. $this->markTestSkipped('FPDF not available');
  26. }
  27. parent::setUp();
  28. }
  29. /**
  30. * @inheritDoc
  31. */
  32. protected function getOutputInterface(QROptions $options):QROutputInterface{
  33. return new QRFpdf($options, $this->matrix);
  34. }
  35. /**
  36. * @inheritDoc
  37. */
  38. public function types():array{
  39. return [
  40. 'fpdf' => [QRCode::OUTPUT_FPDF],
  41. ];
  42. }
  43. /**
  44. * @inheritDoc
  45. */
  46. public function testSetModuleValues():void{
  47. $this->options->moduleValues = [
  48. // data
  49. QRMatrix::M_DATA | QRMatrix::IS_DARK => [0, 0, 0],
  50. QRMatrix::M_DATA => [255, 255, 255],
  51. ];
  52. $this->outputInterface = $this->getOutputInterface($this->options);
  53. $this->outputInterface->dump();
  54. $this::assertTrue(true); // tricking the code coverage
  55. }
  56. /**
  57. * @inheritDoc
  58. * @dataProvider types
  59. */
  60. public function testRenderImage(string $type):void{
  61. $this->options->outputType = $type;
  62. $this->options->imageBase64 = false;
  63. // substr() to avoid CreationDate
  64. $expected = substr(file_get_contents(__DIR__.'/../samples/'.$type), 0, 2500);
  65. $actual = substr((new QRCode($this->options))->render('test'), 0, 2500);
  66. $this::assertSame($expected, $actual);
  67. }
  68. public function testOutputGetResource():void{
  69. $this->options->returnResource = true;
  70. $this->outputInterface = $this->getOutputInterface($this->options);
  71. $this::assertInstanceOf(FPDF::class, $this->outputInterface->dump());
  72. }
  73. }