QRImageTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }
  25. parent::setUp();
  26. }
  27. /**
  28. * @inheritDoc
  29. * @internal
  30. */
  31. protected function getOutputInterface(QROptions $options):QROutputInterface{
  32. return new QRImage($options, $this->matrix);
  33. }
  34. /**
  35. * @inheritDoc
  36. * @internal
  37. */
  38. public function types():array{
  39. return [
  40. 'png' => [QRCode::OUTPUT_IMAGE_PNG],
  41. 'gif' => [QRCode::OUTPUT_IMAGE_GIF],
  42. 'jpg' => [QRCode::OUTPUT_IMAGE_JPG],
  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. *
  60. */
  61. public function testOutputGetResource():void{
  62. $this->options->returnResource = true;
  63. $this->outputInterface = $this->getOutputInterface($this->options);
  64. $actual = $this->outputInterface->dump();
  65. /** @noinspection PhpFullyQualifiedNameUsageInspection */
  66. \PHP_MAJOR_VERSION >= 8
  67. ? $this::assertInstanceOf(\GdImage::class, $actual)
  68. : $this::assertIsResource($actual);
  69. }
  70. }