QRCodeReaderImagickTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Class QRCodeReaderImagickTest
  4. *
  5. * @created 12.12.2021
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2021 smiley
  8. * @license MIT
  9. */
  10. declare(strict_types=1);
  11. namespace chillerlan\QRCodeTest;
  12. use chillerlan\QRCode\QROptions;
  13. use chillerlan\QRCode\Common\{IMagickLuminanceSource, LuminanceSourceInterface};
  14. use chillerlan\QRCode\Decoder\Decoder;
  15. use chillerlan\Settings\SettingsContainerInterface;
  16. use PHPUnit\Framework\Attributes\DataProvider;
  17. use function extension_loaded;
  18. use const PHP_OS_FAMILY;
  19. /**
  20. * Tests the Imagick based reader
  21. */
  22. final class QRCodeReaderImagickTest extends QRCodeReaderTestAbstract{
  23. protected function setUp():void{
  24. if(!extension_loaded('imagick')){
  25. $this::markTestSkipped('imagick not installed');
  26. }
  27. parent::setUp();
  28. $this->options->readerUseImagickIfAvailable = true;
  29. }
  30. protected function getLuminanceSourceFromFile(
  31. string $file,
  32. SettingsContainerInterface|QROptions $options,
  33. ):LuminanceSourceInterface{
  34. return IMagickLuminanceSource::fromFile($file, $options);
  35. }
  36. /**
  37. * @phpstan-return array<string, array{0: string, 1: string}>
  38. */
  39. public static function vectorQRCodeProvider():array{
  40. return [
  41. // SVG convert only works on windows (Warning: Option --export-png= is deprecated)
  42. 'SVG' => ['vector_sample.svg', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'],
  43. // fails on linux because of security policy: https://stackoverflow.com/a/59193253
  44. // fails on windows with a FailedToExecuteCommand and file not found error
  45. # 'EPS' => ['vector_sample.eps', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'],
  46. ];
  47. }
  48. #[DataProvider('vectorQRCodeProvider')]
  49. public function testReadVectorFormats(string $img, string $expected):void{
  50. if(PHP_OS_FAMILY === 'Linux'){
  51. $this::markTestSkipped('avoid imagick conversion errors (ha ha)');
  52. }
  53. $luminanceSource = $this->getLuminanceSourceFromFile($this::samplesDir.$img, $this->options);
  54. $this::assertSame($expected, (string)(new Decoder)->decode($luminanceSource));
  55. }
  56. }