QRImagickTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. declare(strict_types=1);
  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 chillerlan\Settings\SettingsContainerInterface;
  18. use PHPUnit\Framework\Attributes\{RequiresPhpExtension, Test};
  19. use Imagick;
  20. /**
  21. * Tests the QRImagick output class
  22. */
  23. #[RequiresPhpExtension('imagick')]
  24. final class QRImagickTest extends QROutputTestAbstract{
  25. protected function getOutputInterface(
  26. SettingsContainerInterface|QROptions $options,
  27. QRMatrix $matrix,
  28. ):QROutputInterface{
  29. return new QRImagick($options, $matrix);
  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. #[Test]
  57. public function setModuleValues():void{
  58. $this->options->moduleValues = [
  59. // data
  60. QRMatrix::M_DATA_DARK => '#4A6000',
  61. QRMatrix::M_DATA => '#ECF9BE',
  62. ];
  63. $this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
  64. $this->outputInterface->dump();
  65. /** @phpstan-ignore-next-line */
  66. $this::assertTrue(true); // tricking the code coverage
  67. }
  68. #[Test]
  69. public function outputGetResource():void{
  70. $this->options->returnResource = true;
  71. $this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
  72. $this::assertInstanceOf(Imagick::class, $this->outputInterface->dump());
  73. }
  74. }