QRCodeReaderImagickTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Decoder\IMagickLuminanceSource;
  12. use chillerlan\QRCode\QRCode;
  13. use function extension_loaded;
  14. use const PHP_OS_FAMILY;
  15. /**
  16. * Tests the Imagick based reader
  17. */
  18. final class QRCodeReaderImagickTest extends QRCodeReaderTestAbstract{
  19. protected string $FQN = IMagickLuminanceSource::class;
  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. public function vectorQRCodeProvider():array{
  28. return [
  29. // SVG convert only works on windows (Warning: Option --export-png= is deprecated)
  30. 'SVG' => ['vector_sample.svg', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'],
  31. // fails on linux because of security policy: https://stackoverflow.com/a/59193253
  32. // fails on windows with a FailedToExecuteCommand and file not found error
  33. # 'EPS' => ['vector_sample.eps', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'],
  34. ];
  35. }
  36. /**
  37. * This test fails on Windows and PHP < 8.1 for whatever reason
  38. *
  39. * @dataProvider vectorQRCodeProvider
  40. */
  41. public function testReadVectorFormats(string $img, string $expected):void{
  42. if(PHP_OS_FAMILY === 'Linux'){
  43. $this::markTestSkipped('avoid imagick conversion errors (ha ha)');
  44. }
  45. $this::assertSame($expected, (string)(new QRCode)
  46. ->readFromSource(IMagickLuminanceSource::fromFile(__DIR__.'/samples/'.$img, $this->options)));
  47. }
  48. }