QRFpdfTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. }
  27. parent::setUp();
  28. }
  29. /**
  30. * @inheritDoc
  31. * @internal
  32. */
  33. protected function getOutputInterface(QROptions $options):QROutputInterface{
  34. return new QRFpdf($options, $this->matrix);
  35. }
  36. /**
  37. * @inheritDoc
  38. * @internal
  39. */
  40. public function types():array{
  41. return [
  42. 'fpdf' => [QRCode::OUTPUT_FPDF],
  43. ];
  44. }
  45. /**
  46. * @inheritDoc
  47. */
  48. public function testSetModuleValues():void{
  49. $this->options->moduleValues = [
  50. // data
  51. 1024 => [0, 0, 0],
  52. 4 => [255, 255, 255],
  53. ];
  54. $this->outputInterface = $this->getOutputInterface($this->options);
  55. $this->outputInterface->dump();
  56. $this::assertTrue(true); // tricking the code coverage
  57. }
  58. /**
  59. * @inheritDoc
  60. * @dataProvider types
  61. */
  62. public function testRenderImage(string $type):void{
  63. $this->options->outputType = $type;
  64. $this->options->imageBase64 = false;
  65. // substr() to avoid CreationDate
  66. $expected = substr(file_get_contents(__DIR__.'/samples/'.$type), 0, 2500);
  67. $actual = substr((new QRCode($this->options))->render('test'), 0, 2500);
  68. $this::assertSame($expected, $actual);
  69. }
  70. public function testOutputGetResource():void{
  71. $this->options->returnResource = true;
  72. $this->outputInterface = $this->getOutputInterface($this->options);
  73. $this::assertInstanceOf(FPDF::class, $this->outputInterface->dump());
  74. }
  75. }