QRCodeReaderImagickTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\Common\IMagickLuminanceSource;
  12. use chillerlan\QRCode\QRCode;
  13. use PHPUnit\Framework\Attributes\DataProvider;
  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 string $FQN = IMagickLuminanceSource::class;
  21. protected function setUp():void{
  22. if(!extension_loaded('imagick')){
  23. $this::markTestSkipped('imagick not installed');
  24. }
  25. parent::setUp();
  26. $this->options->readerUseImagickIfAvailable = true;
  27. }
  28. public static function vectorQRCodeProvider():array{
  29. return [
  30. // SVG convert only works on windows (Warning: Option --export-png= is deprecated)
  31. 'SVG' => ['vector_sample.svg', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'],
  32. // fails on linux because of security policy: https://stackoverflow.com/a/59193253
  33. // fails on windows with a FailedToExecuteCommand and file not found error
  34. # 'EPS' => ['vector_sample.eps', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'],
  35. ];
  36. }
  37. #[DataProvider('vectorQRCodeProvider')]
  38. public function testReadVectorFormats(string $img, string $expected):void{
  39. if(PHP_OS_FAMILY === 'Linux'){
  40. $this::markTestSkipped('avoid imagick conversion errors (ha ha)');
  41. }
  42. if(PHP_OS_FAMILY === 'Windows' && PHP_VERSION_ID < 80100){
  43. $this::markTestSkipped('This test fails on Windows and PHP < 8.1 for whatever reason');
  44. }
  45. $this::assertSame($expected, (string)(new QRCode)
  46. ->readFromSource(IMagickLuminanceSource::fromFile(__DIR__.'/samples/'.$img, $this->options)));
  47. }
  48. }