QRImageTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\Data\QRMatrix;
  12. use chillerlan\QRCode\{QRCode, QROptions};
  13. use chillerlan\QRCode\Output\{QROutputInterface, QRImage};
  14. use const PHP_MAJOR_VERSION;
  15. /**
  16. * Tests the QRImage output module
  17. */
  18. final class QRImageTest extends QROutputTestAbstract{
  19. /**
  20. * @inheritDoc
  21. */
  22. protected function setUp():void{
  23. if(!extension_loaded('gd')){
  24. $this->markTestSkipped('ext-gd not loaded');
  25. }
  26. parent::setUp();
  27. }
  28. /**
  29. * @inheritDoc
  30. */
  31. protected function getOutputInterface(QROptions $options):QROutputInterface{
  32. return new QRImage($options, $this->matrix);
  33. }
  34. /**
  35. * @inheritDoc
  36. */
  37. public function types():array{
  38. return [
  39. 'png' => [QRCode::OUTPUT_IMAGE_PNG],
  40. 'gif' => [QRCode::OUTPUT_IMAGE_GIF],
  41. 'jpg' => [QRCode::OUTPUT_IMAGE_JPG],
  42. ];
  43. }
  44. /**
  45. * @inheritDoc
  46. */
  47. public function testSetModuleValues():void{
  48. $this->options->moduleValues = [
  49. // data
  50. QRMatrix::M_DATA | QRMatrix::IS_DARK => [0, 0, 0],
  51. QRMatrix::M_DATA => [255, 255, 255],
  52. ];
  53. $this->outputInterface = $this->getOutputInterface($this->options);
  54. $this->outputInterface->dump();
  55. $this::assertTrue(true); // tricking the code coverage
  56. }
  57. /**
  58. *
  59. */
  60. public function testOutputGetResource():void{
  61. $this->options->returnResource = true;
  62. $this->outputInterface = $this->getOutputInterface($this->options);
  63. $actual = $this->outputInterface->dump();
  64. /** @noinspection PhpFullyQualifiedNameUsageInspection */
  65. PHP_MAJOR_VERSION >= 8
  66. ? $this::assertInstanceOf(\GdImage::class, $actual)
  67. : $this::assertIsResource($actual);
  68. }
  69. }