QRGdImageTestAbstract.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Class QRGdImageTestAbstract
  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 const PHP_MAJOR_VERSION;
  13. /**
  14. * Tests the QRGdImage output module
  15. */
  16. abstract class QRGdImageTestAbstract extends QROutputTestAbstract{
  17. /**
  18. * @inheritDoc
  19. */
  20. protected function setUp():void{
  21. if(!extension_loaded('gd')){
  22. $this::markTestSkipped('ext-gd not loaded');
  23. }
  24. parent::setUp();
  25. }
  26. public static function moduleValueProvider():array{
  27. return [
  28. 'valid: int' => [[123, 123, 123], true],
  29. 'valid: w/invalid extra element' => [[123, 123, 123, 'abc'], true],
  30. 'valid: numeric string' => [['123', '123', '123'], true],
  31. 'invalid: wrong type' => ['foo', false],
  32. 'invalid: array too short' => [[1, 2], false],
  33. 'invalid: contains non-number' => [[1, 'b', 3], false],
  34. ];
  35. }
  36. /**
  37. * @inheritDoc
  38. */
  39. public function testSetModuleValues():void{
  40. $this->options->moduleValues = [
  41. // data
  42. QRMatrix::M_DATA_DARK => [0, 0, 0],
  43. QRMatrix::M_DATA => [255, 255, 255],
  44. ];
  45. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  46. $this->outputInterface->dump();
  47. $this::assertTrue(true); // tricking the code coverage
  48. }
  49. /**
  50. * @todo: remove php version check in v6
  51. */
  52. public function testOutputGetResource():void{
  53. $this->options->returnResource = true;
  54. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  55. $actual = $this->outputInterface->dump();
  56. /** @noinspection PhpFullyQualifiedNameUsageInspection */
  57. PHP_MAJOR_VERSION >= 8
  58. ? $this::assertInstanceOf(\GdImage::class, $actual)
  59. : $this::assertIsResource($actual);
  60. }
  61. public function testBase64MimeType():void{
  62. $this->options->outputBase64 = true;
  63. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  64. $this::assertStringContainsString($this->outputInterface::MIME_TYPE, $this->outputInterface->dump());
  65. }
  66. }