QRImagickTest.php 3.0 KB

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