Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify ImageMagickHandler::getVersion() #8681

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions system/Images/Handlers/ImageMagickHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,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 @@ -80,11 +80,10 @@
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 Expand Up @@ -422,7 +421,7 @@
$this->assertSame(exif_imagetype($this->root . 'ci-logo.png'), IMAGETYPE_PNG);
}

public function testImageReorientLandscape(): void

Check warning on line 424 in tests/system/Images/ImageMagickHandlerTest.php

View workflow job for this annotation

GitHub Actions / Others (8.1) / Sanity Tests

Took 0.57s from 0.50s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageReorientLandscape
{
for ($i = 0; $i <= 8; $i++) {
$source = $this->origin . 'EXIFsamples/landscape_' . $i . '.jpg';
Expand All @@ -441,7 +440,7 @@
}
}

public function testImageReorientPortrait(): void

Check warning on line 443 in tests/system/Images/ImageMagickHandlerTest.php

View workflow job for this annotation

GitHub Actions / Others (8.1) / Sanity Tests

Took 0.55s from 0.50s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageReorientPortrait
{
for ($i = 0; $i <= 8; $i++) {
$source = $this->origin . 'EXIFsamples/portrait_' . $i . '.jpg';
Expand Down
Loading