QRFpdfTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. return;
  29. }
  30. parent::setUp();
  31. }
  32. /**
  33. * @inheritDoc
  34. * @internal
  35. */
  36. protected function getOutputInterface(QROptions $options):QROutputInterface{
  37. return new QRFpdf($options, $this->matrix);
  38. }
  39. /**
  40. * @inheritDoc
  41. * @internal
  42. */
  43. public function types():array{
  44. return [
  45. 'fpdf' => [QRCode::OUTPUT_FPDF],
  46. ];
  47. }
  48. /**
  49. * @inheritDoc
  50. */
  51. public function testSetModuleValues():void{
  52. $this->options->moduleValues = [
  53. // data
  54. 1024 => [0, 0, 0],
  55. 4 => [255, 255, 255],
  56. ];
  57. $this->outputInterface = $this->getOutputInterface($this->options);
  58. $this->outputInterface->dump();
  59. $this::assertTrue(true); // tricking the code coverage
  60. }
  61. /**
  62. * @inheritDoc
  63. * @dataProvider types
  64. */
  65. public function testRenderImage(string $type):void{
  66. $this->options->outputType = $type;
  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. \var_dump([$expected, $actual]);
  71. $this::assertSame($expected, $actual);
  72. }
  73. }