QRFpdfTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. protected $FQCN = QRFpdf::class;
  22. /**
  23. * @inheritDoc
  24. * @internal
  25. */
  26. public function setUp():void{
  27. if(!class_exists(FPDF::class)){
  28. $this->markTestSkipped('FPDF not available');
  29. return;
  30. }
  31. parent::setUp();
  32. }
  33. /**
  34. * @inheritDoc
  35. */
  36. public function testSetModuleValues():void{
  37. $this->options->moduleValues = [
  38. // data
  39. 1024 => [0, 0, 0],
  40. 4 => [255, 255, 255],
  41. ];
  42. $this->outputInterface->dump();
  43. $this::assertTrue(true); // tricking the code coverage
  44. }
  45. /**
  46. * @inheritDoc
  47. */
  48. public function testRenderImage():void{
  49. $type = QRCode::OUTPUT_FPDF;
  50. $this->options->outputType = $type;
  51. $this->options->imageBase64 = false;
  52. $this->outputInterface->dump($this::cachefile.$type);
  53. // substr() to avoid CreationDate
  54. $expected = substr(file_get_contents($this::cachefile.$type), 0, 2000);
  55. $actual = substr($this->outputInterface->dump(), 0, 2000);
  56. $this::assertSame($expected, $actual);
  57. }
  58. public function testOutputGetResource():void{
  59. $this->options->returnResource = true;
  60. $this->setOutputInterface();
  61. $this::assertInstanceOf(FPDF::class, $this->outputInterface->dump());
  62. }
  63. }