From cc0e21fb3a939b63dc494112771b27e9b2d0d06f Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 26 Jan 2024 22:32:21 +0800 Subject: [PATCH] test: refactor ImageMagickHandlerTest --- .../system/Images/ImageMagickHandlerTest.php | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/tests/system/Images/ImageMagickHandlerTest.php b/tests/system/Images/ImageMagickHandlerTest.php index 69a5df6e687c..b313fef96275 100644 --- a/tests/system/Images/ImageMagickHandlerTest.php +++ b/tests/system/Images/ImageMagickHandlerTest.php @@ -30,6 +30,8 @@ * @internal * * @group Others + * + * @requires extension imagick */ final class ImageMagickHandlerTest extends CIUnitTestCase { @@ -40,10 +42,6 @@ final class ImageMagickHandlerTest extends CIUnitTestCase protected function setUp(): void { - if (! extension_loaded('imagick')) { - $this->markTestSkipped('The ImageMagick extension is not available.'); - } - $this->root = WRITEPATH . 'cache/'; // cleanup everything @@ -55,11 +53,28 @@ protected function setUp(): void $this->path = $this->origin . 'ci-logo.png'; - $handlerConfig = new Images(); - if (is_file('/usr/bin/convert')) { - $handlerConfig->libraryPath = '/usr/bin/convert'; + // get our locally available `convert` + $config = new Images(); + $found = false; + + foreach ([ + '/usr/bin/convert', + trim((string) shell_exec('which convert')), + $config->libraryPath, + ] as $convert) { + if (is_file($convert)) { + $config->libraryPath = $convert; + + $found = true; + break; + } + } + + if (! $found) { + $this->markTestSkipped('Cannot test imagick as there is no available convert program.'); } - $this->handler = Services::image('imagick', $handlerConfig, false); + + $this->handler = Services::image('imagick', $config, false); } public function testGetVersion(): void