QRImagickTest.php 2.7 KB

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