QRCodeReaderImagickTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, RequiresPhpExtension, Test};
  17. use const PHP_OS_FAMILY;
  18. /**
  19. * Tests the Imagick based reader
  20. */
  21. #[RequiresPhpExtension('imagick')]
  22. final class QRCodeReaderImagickTest extends QRCodeReaderTestAbstract{
  23. protected function setUp():void{
  24. parent::setUp();
  25. $this->options->readerUseImagickIfAvailable = true;
  26. }
  27. protected function getLuminanceSourceFromFile(
  28. string $file,
  29. SettingsContainerInterface|QROptions $options,
  30. ):LuminanceSourceInterface{
  31. return IMagickLuminanceSource::fromFile($file, $options);
  32. }
  33. /**
  34. * @phpstan-return array<string, array{0: string, 1: string}>
  35. */
  36. public static function vectorQRCodeProvider():array{
  37. return [
  38. // SVG convert only works on windows (Warning: Option --export-png= is deprecated)
  39. 'SVG' => ['vector_sample.svg', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'],
  40. // fails on linux because of security policy: https://stackoverflow.com/a/59193253
  41. // fails on windows with a FailedToExecuteCommand and file not found error
  42. # 'EPS' => ['vector_sample.eps', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'],
  43. ];
  44. }
  45. #[Test]
  46. #[DataProvider('vectorQRCodeProvider')]
  47. public function readVectorFormats(string $img, string $expected):void{
  48. if(PHP_OS_FAMILY === 'Linux'){
  49. $this::markTestSkipped('avoid imagick conversion errors (ha ha)');
  50. }
  51. $luminanceSource = $this->getLuminanceSourceFromFile($this::samplesDir.$img, $this->options);
  52. $this::assertSame($expected, (string)(new Decoder)->decode($luminanceSource));
  53. }
  54. }