QRImageTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Class QRImageTest
  4. *
  5. * @created 24.12.2017
  6. * @author Smiley <smiley@chillerlan.net>
  7. * @copyright 2017 Smiley
  8. * @license MIT
  9. */
  10. namespace chillerlan\QRCodeTest\Output;
  11. use chillerlan\QRCode\{QRCode, QROptions};
  12. use chillerlan\QRCode\Output\{QROutputInterface, QRImage};
  13. /**
  14. * Tests the QRImage output module
  15. */
  16. class QRImageTest extends QROutputTestAbstract{
  17. /**
  18. * @inheritDoc
  19. * @internal
  20. */
  21. public function setUp():void{
  22. if(!extension_loaded('gd')){
  23. $this->markTestSkipped('ext-gd not loaded');
  24. return;
  25. }
  26. parent::setUp();
  27. }
  28. /**
  29. * @inheritDoc
  30. * @internal
  31. */
  32. protected function getOutputInterface(QROptions $options):QROutputInterface{
  33. return new QRImage($options, $this->matrix);
  34. }
  35. /**
  36. * @inheritDoc
  37. * @internal
  38. */
  39. public function types():array{
  40. return [
  41. 'png' => [QRCode::OUTPUT_IMAGE_PNG],
  42. 'gif' => [QRCode::OUTPUT_IMAGE_GIF],
  43. 'jpg' => [QRCode::OUTPUT_IMAGE_JPG],
  44. ];
  45. }
  46. /**
  47. * @inheritDoc
  48. */
  49. public function testSetModuleValues():void{
  50. $this->options->moduleValues = [
  51. // data
  52. 1024 => [0, 0, 0],
  53. 4 => [255, 255, 255],
  54. ];
  55. $this->outputInterface = $this->getOutputInterface($this->options);
  56. $this->outputInterface->dump();
  57. $this::assertTrue(true); // tricking the code coverage
  58. }
  59. /**
  60. *
  61. */
  62. public function testOutputGetResource():void{
  63. $this->options->returnResource = true;
  64. $this->outputInterface = $this->getOutputInterface($this->options);
  65. $actual = $this->outputInterface->dump();
  66. /** @noinspection PhpFullyQualifiedNameUsageInspection */
  67. \PHP_MAJOR_VERSION >= 8
  68. ? $this::assertInstanceOf(\GdImage::class, $actual)
  69. : $this::assertIsResource($actual);
  70. }
  71. }