QRCodeReaderImagickTest.php 2.0 KB

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