QRGdImageTestAbstract.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 chillerlan\QRCode\Output\QRGdImage;
  13. use const PHP_MAJOR_VERSION;
  14. /**
  15. * Tests the QRGdImage output module
  16. */
  17. abstract class QRGdImageTestAbstract extends QROutputTestAbstract{
  18. protected string $FQN = QRGdImage::class;
  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. public static function moduleValueProvider():array{
  29. return [
  30. 'valid: int' => [[123, 123, 123], true],
  31. 'valid: w/invalid extra element' => [[123, 123, 123, 'abc'], true],
  32. 'valid: numeric string' => [['123', '123', '123'], true],
  33. 'invalid: wrong type' => ['foo', false],
  34. 'invalid: array too short' => [[1, 2], false],
  35. 'invalid: contains non-number' => [[1, 'b', 3], false],
  36. ];
  37. }
  38. /**
  39. * @inheritDoc
  40. */
  41. public function testSetModuleValues():void{
  42. $this->options->moduleValues = [
  43. // data
  44. QRMatrix::M_DATA_DARK => [0, 0, 0],
  45. QRMatrix::M_DATA => [255, 255, 255],
  46. ];
  47. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  48. $this->outputInterface->dump();
  49. $this::assertTrue(true); // tricking the code coverage
  50. }
  51. /**
  52. *
  53. */
  54. public function testOutputGetResource():void{
  55. $this->options->returnResource = true;
  56. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  57. $actual = $this->outputInterface->dump();
  58. /** @noinspection PhpFullyQualifiedNameUsageInspection */
  59. PHP_MAJOR_VERSION >= 8
  60. ? $this::assertInstanceOf(\GdImage::class, $actual)
  61. : $this::assertIsResource($actual);
  62. }
  63. }