QRCodeReaderImagickTest.php 1.9 KB

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