QRFpdfTest.php 2.0 KB

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