QRImagickTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Class QRImagickTest
  4. *
  5. * @created 04.07.2018
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2018 smiley
  8. * @license MIT
  9. *
  10. * @noinspection PhpUndefinedClassInspection
  11. * @noinspection PhpComposerExtensionStubsInspection
  12. */
  13. namespace chillerlan\QRCodeTest\Output;
  14. use chillerlan\QRCode\Data\QRMatrix;
  15. use chillerlan\QRCode\Output\{QRImagick, QROutputInterface};
  16. use Imagick;
  17. /**
  18. * Tests the QRImagick output module
  19. */
  20. final class QRImagickTest extends QROutputTestAbstract{
  21. protected string $FQN = QRImagick::class;
  22. protected string $type = QROutputInterface::IMAGICK;
  23. /**
  24. * @inheritDoc
  25. */
  26. protected function setUp():void{
  27. if(!extension_loaded('imagick')){
  28. $this::markTestSkipped('ext-imagick not loaded');
  29. }
  30. parent::setUp();
  31. }
  32. public static function moduleValueProvider():array{
  33. return [
  34. 'invalid: wrong type' => [[], false],
  35. 'valid: hex color (3)' => ['#abc', true],
  36. 'valid: hex color (4)' => ['#abcd', true],
  37. 'valid: hex color (6)' => ['#aabbcc', true],
  38. 'valid: hex color (8)' => ['#aabbccdd', true],
  39. 'valid: hex color (32)' => ['#aaaaaaaabbbbbbbbccccccccdddddddd', true],
  40. 'invalid: hex color (non-hex)' => ['#aabbcxyz', false],
  41. 'invalid: hex color (too short)' => ['#aa', false],
  42. 'invalid: hex color (too long)' => ['#aaaaaaaabbbbbbbbccccccccdddddddd00', false],
  43. 'invalid: hex color (5)' => ['#aabbc', false],
  44. 'invalid: hex color (7)' => ['#aabbccd', false],
  45. 'valid: rgb(...%)' => ['rgb(100.0%, 0.0%, 0.0%)', true],
  46. 'valid: rgba(...)' => [' rgba(255, 0, 0, 1.0) ', true],
  47. 'valid: hsb(...)' => ['hsb(33.3333%, 100%, 75%)', true],
  48. 'valid: hsla(...)' => ['hsla(120, 255, 191.25, 1.0)', true],
  49. 'invalid: rgba(non-numeric)' => ['rgba(255, 0, whatever, 0, 1.0)', false],
  50. 'invalid: rgba(extra-char)' => ['rgba(255, 0, 0, 1.0);', false],
  51. 'valid: csscolor' => ['purple', true],
  52. 'invalid: c5s c0lor' => ['c5sc0lor', false],
  53. ];
  54. }
  55. /**
  56. * @inheritDoc
  57. */
  58. public function testSetModuleValues():void{
  59. $this->options->moduleValues = [
  60. // data
  61. QRMatrix::M_DATA_DARK => '#4A6000',
  62. QRMatrix::M_DATA => '#ECF9BE',
  63. ];
  64. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  65. $this->outputInterface->dump();
  66. $this::assertTrue(true); // tricking the code coverage
  67. }
  68. public function testOutputGetResource():void{
  69. $this->options->returnResource = true;
  70. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  71. $this::assertInstanceOf(Imagick::class, $this->outputInterface->dump());
  72. }
  73. }