QRImageTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Class QRImageTest
  4. *
  5. * @filesource QRImageTest.php
  6. * @created 24.12.2017
  7. * @package chillerlan\QRCodeTest\Output
  8. * @author Smiley <smiley@chillerlan.net>
  9. * @copyright 2017 Smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCodeTest\Output;
  13. use chillerlan\QRCode\{QRCode, QROptions};
  14. use chillerlan\QRCode\Output\{QROutputInterface, QRImage};
  15. /**
  16. * Tests the QRImage output module
  17. */
  18. class QRImageTest extends QROutputTestAbstract{
  19. /**
  20. * @inheritDoc
  21. * @internal
  22. */
  23. public function setUp():void{
  24. if(!extension_loaded('gd')){
  25. $this->markTestSkipped('ext-gd not loaded');
  26. return;
  27. }
  28. parent::setUp();
  29. }
  30. /**
  31. * @inheritDoc
  32. * @internal
  33. */
  34. protected function getOutputInterface(QROptions $options):QROutputInterface{
  35. return new QRImage($options, $this->matrix);
  36. }
  37. /**
  38. * @inheritDoc
  39. * @internal
  40. */
  41. public function types():array{
  42. return [
  43. 'png' => [QRCode::OUTPUT_IMAGE_PNG],
  44. 'gif' => [QRCode::OUTPUT_IMAGE_GIF],
  45. 'jpg' => [QRCode::OUTPUT_IMAGE_JPG],
  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. * @phan-suppress PhanUndeclaredClassReference
  63. */
  64. public function testOutputGetResource():void{
  65. $this->options->returnResource = true;
  66. $this->outputInterface = $this->getOutputInterface($this->options);
  67. $actual = $this->outputInterface->dump();
  68. /** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */
  69. \PHP_MAJOR_VERSION >= 8
  70. ? $this::assertInstanceOf(\GdImage::class, $actual)
  71. : $this::assertIsResource($actual);
  72. }
  73. }