QRFpdfTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Class QRFpdfTest
  4. *
  5. * @filesource QRFpdfTest.php
  6. * @created 03.06.2020
  7. * @package chillerlan\QRCodeTest\Output
  8. * @author smiley <smiley@chillerlan.net>
  9. * @copyright 2020 smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCodeTest\Output;
  13. use FPDF;
  14. use chillerlan\QRCode\{QRCode, QROptions};
  15. use chillerlan\QRCode\Data\QRMatrix;
  16. use chillerlan\QRCode\Output\{QRFpdf, QROutputInterface};
  17. use function class_exists, substr;
  18. /**
  19. * Tests the QRFpdf output module
  20. */
  21. class QRFpdfTest extends QROutputTestAbstract{
  22. /**
  23. * @inheritDoc
  24. * @internal
  25. */
  26. public function setUp():void{
  27. if(!class_exists(FPDF::class)){
  28. $this->markTestSkipped('FPDF not available');
  29. /** @noinspection PhpUnreachableStatementInspection */
  30. return;
  31. }
  32. parent::setUp();
  33. }
  34. /**
  35. * @inheritDoc
  36. * @internal
  37. */
  38. protected function getOutputInterface(QROptions $options):QROutputInterface{
  39. return new QRFpdf($options, $this->matrix);
  40. }
  41. /**
  42. * @inheritDoc
  43. * @internal
  44. */
  45. public function types():array{
  46. return [
  47. 'fpdf' => [QRCode::OUTPUT_FPDF],
  48. ];
  49. }
  50. /**
  51. * @inheritDoc
  52. */
  53. public function testSetModuleValues():void{
  54. $this->options->moduleValues = [
  55. // data
  56. QRMatrix::M_DATA_DARK => [0, 0, 0],
  57. QRMatrix::M_DATA => [255, 255, 255],
  58. ];
  59. $this->outputInterface = $this->getOutputInterface($this->options);
  60. $this->outputInterface->dump();
  61. $this::assertTrue(true); // tricking the code coverage
  62. }
  63. /**
  64. * @inheritDoc
  65. * @dataProvider types
  66. */
  67. public function testRenderImage(string $type):void{
  68. $this->options->outputType = $type;
  69. $this->options->imageBase64 = false;
  70. // substr() to avoid CreationDate
  71. $expected = substr(file_get_contents(__DIR__.'/samples/'.$type), 0, 2500);
  72. $actual = substr((new QRCode($this->options))->render('test'), 0, 2500);
  73. $this::assertSame($expected, $actual);
  74. }
  75. public function testOutputGetResource():void{
  76. $this->options->returnResource = true;
  77. $this->outputInterface = $this->getOutputInterface($this->options);
  78. $this::assertInstanceOf(FPDF::class, $this->outputInterface->dump());
  79. }
  80. }