QRFpdfTest.php 1.9 KB

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