QRCodeReaderImagickTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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, PHP_VERSION_ID;
  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. * @dataProvider vectorQRCodeProvider
  38. */
  39. public function testReadVectorFormats(string $img, string $expected):void{
  40. if(PHP_OS_FAMILY === 'Linux'){
  41. $this::markTestSkipped('avoid imagick conversion errors (ha ha)');
  42. }
  43. if(PHP_OS_FAMILY === 'Windows' && PHP_VERSION_ID < 80100){
  44. $this::markTestSkipped('This test fails on Windows and PHP < 8.1 for whatever reason');
  45. }
  46. $this::assertSame($expected, (string)(new QRCode)
  47. ->readFromSource(IMagickLuminanceSource::fromFile(__DIR__.'/samples/'.$img, $this->options)));
  48. }
  49. }