QRImagickTest.php 3.0 KB

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