Skip to content

Commit

Permalink
Merge pull request #8681 from paulbalandan/imagemagick-getversion
Browse files Browse the repository at this point in the history
refactor: simplify ImageMagickHandler::getVersion()
  • Loading branch information
paulbalandan authored Mar 30, 2024
2 parents f22b8cf + d272bfe commit 7ca24b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 3 additions & 5 deletions system/Images/Handlers/ImageMagickHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,10 @@ protected function _flip(string $direction)
*/
public function getVersion(): string
{
$result = $this->process('-version');
$versionString = $this->process('-version')[0];
preg_match('/ImageMagick\s(?P<version>[\S]+)/', $versionString, $matches);

// The first line has the version in it...
preg_match('/(ImageMagick\s[\S]+)/', $result[0], $matches);

return str_replace('ImageMagick ', '', $matches[0]);
return $matches['version'];
}

/**
Expand Down
9 changes: 4 additions & 5 deletions tests/system/Images/ImageMagickHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ public static function provideNonexistentLibraryPathTerminatesProcessing(): iter
public function testGetVersion(): void
{
$version = $this->handler->getVersion();
// make sure that the call worked
$this->assertNotFalse($version);
// we should have a numeric version, greater than 6
$this->assertGreaterThanOrEqual(0, version_compare($version, '6.0.0'));
$this->assertLessThan(0, version_compare($version, '99.0.0'));

$this->assertNotSame('', $version);
$this->assertTrue(version_compare($version, '6.0.0', '>'));
$this->assertTrue(version_compare($version, '99.0.0', '<'));
}

public function testImageProperties(): void
Expand Down

0 comments on commit 7ca24b2

Please sign in to comment.