Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ vendor/
bin/
/.php_cs.cache
/.php_cs
/.phpunit.result.cache
/tests/tmp
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ install:
codestyle)
;;
*)
sudo apt-get update
sudo apt-get remove -y imagemagick libmagickcore-dev libmagickwand-dev
sudo apt-get update -y || true
sudo apt-get remove -y imagemagick libmagickcore-dev libmagickwand-dev
sudo apt-get install -y ca-certificates libtiff-dev libjpeg-dev libdjvulibre-dev libwmf-dev pkg-config liblcms2-dev
PHPUNIT_EXCLUDED_GROUPS=always-skipped
if test "${IMAGINE_DRIVER:-}" = 'imagick' -o "${IMAGINE_DRIVER:-}" = 'all'; then ./.travis/imagick.sh; else PHPUNIT_EXCLUDED_GROUPS="${PHPUNIT_EXCLUDED_GROUPS},imagick"; fi
Expand Down Expand Up @@ -69,11 +68,13 @@ matrix:
- IMAGINE_DRIVER: gmagick
-
name: Test with PHP 5.4 (all drivers)
dist: trusty
php: '5.4'
env:
- IMAGINE_DRIVER: all
-
name: Test with PHP 5.5 (all drivers)
dist: trusty
php: '5.5'
env:
- IMAGINE_DRIVER: all
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"php": ">=5.3.2"
},
"require-dev": {
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.4 || ^8.2",
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.5 || ^8.4",
"friendsofphp/php-cs-fixer": "2.2.*"
},
"suggest": {
Expand Down
27 changes: 24 additions & 3 deletions src/Image/Metadata/ExifMetadataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,40 @@ class ExifMetadataReader extends AbstractMetadataReader
*/
public function __construct()
{
if (!self::isSupported()) {
throw new NotSupportedException('PHP exif extension is required to use the ExifMetadataReader');
$whyNot = static::getUnsupportedReason();
if ($whyNot !== '') {
throw new NotSupportedException($whyNot);
}
}

/**
* Get the reason why this metadata reader is not supported.
*
* @return string empty string if the reader is available
*/
public static function getUnsupportedReason()
{
if (!function_exists('exif_read_data')) {
return 'The PHP EXIF extension is required to use the ExifMetadataReader';
}
if (!in_array('data', stream_get_wrappers(), true)) {
return 'The data:// stream wrapper must be enabled';
}
if (in_array(ini_get('allow_url_fopen'), array('', '0', 0), true)) {
return 'The allow_url_fopen php.ini configuration key must be set to 1';
}

return '';
}

/**
* Is this metadata reader supported?
*
* @return bool
*/
public static function isSupported()
{
return function_exists('exif_read_data');
return static::getUnsupportedReason() === '';
}

/**
Expand Down
4 changes: 0 additions & 4 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
class_alias('PHPUnit_Framework_Constraint', 'PHPUnit\Framework\Constraint\Constraint');
}

if (!class_exists('PHPUnit\Util\InvalidArgumentHelper')) {
class_alias('PHPUnit_Util_InvalidArgumentHelper', 'PHPUnit\Util\InvalidArgumentHelper');
}

if (!class_exists('PHPUnit\Framework\Exception')) {
class_alias('PHPUnit_Framework_Exception', 'PHPUnit\Framework\Exception');
}
Expand Down
10 changes: 5 additions & 5 deletions tests/tests/Constraint/AbstractIsImageEqualTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testThrowsExceptionWithInvalidArguments()
$error = $x;
}
$this->assertInstanceOf('PHPUnit\Framework\Exception', $error, 'the first argument should be an ImageInterface instance');
$this->assertRegExp('/^Argument #1 .* must be a /', $error->getMessage());
$this->assertRegExp('/^Argument #1 .* must be an? /', $error->getMessage());

try {
$this->assertImageEquals($image, 'invalid 2');
Expand All @@ -37,7 +37,7 @@ public function testThrowsExceptionWithInvalidArguments()
$error = $x;
}
$this->assertInstanceOf('PHPUnit\Framework\Exception', $error, 'the second argument should be an ImageInterface instance');
$this->assertRegExp('/^Argument #1 .* must be a /', $error->getMessage());
$this->assertRegExp('/^Argument #1 .* must be an? /', $error->getMessage());

try {
$this->assertImageEquals($image, $image, '', 'invalid');
Expand All @@ -46,7 +46,7 @@ public function testThrowsExceptionWithInvalidArguments()
$error = $x;
}
$this->assertInstanceOf('PHPUnit\Framework\Exception', $error, 'the third argument should be a number');
$this->assertRegExp('/^Argument #2 .* must be a /', $error->getMessage());
$this->assertRegExp('/^Argument #2 .* must be an? /', $error->getMessage());

try {
$this->assertImageEquals($image, $image, '', 0.1, null, 'invalid');
Expand All @@ -55,7 +55,7 @@ public function testThrowsExceptionWithInvalidArguments()
$error = $x;
}
$this->assertInstanceOf('PHPUnit\Framework\Exception', $error, 'the fourth argument should be an integer');
$this->assertRegExp('/^Argument #4 .* must be a /', $error->getMessage());
$this->assertRegExp('/^Argument #4 .* must be an? /', $error->getMessage());

try {
$this->assertImageEquals($image, $image, '', 0.1, null, 0);
Expand All @@ -64,7 +64,7 @@ public function testThrowsExceptionWithInvalidArguments()
$error = $x;
}
$this->assertInstanceOf('PHPUnit\Framework\Exception', $error, 'the fourth argument should be a positive integer');
$this->assertRegExp('/^Argument #4 .* must be a /', $error->getMessage());
$this->assertRegExp('/^Argument #4 .* must be an? /', $error->getMessage());

try {
$this->assertImageEquals('foo', 'bar', '', 0, $this->getImagine());
Expand Down
12 changes: 6 additions & 6 deletions tests/tests/Constraint/IsBoxInRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Imagine\Test\Constraint;

use Imagine\Image\BoxInterface;
use PHPUnit\Util\InvalidArgumentHelper;
use Imagine\Test\InvalidArgumentFactory;

class IsBoxInRange extends Constraint
{
Expand Down Expand Up @@ -40,19 +40,19 @@ public function __construct($minWidth, $maxWidth, $minHeight, $maxHeight)
{
parent::__construct();
if (!is_int($minWidth) || $minWidth < 0) {
throw InvalidArgumentHelper::factory(1, 'integer');
throw InvalidArgumentFactory::create(1, 'integer');
}
$this->minWidth = $minWidth;
if (!is_int($maxWidth) || $maxWidth < $minWidth) {
throw InvalidArgumentHelper::factory(2, 'integer');
throw InvalidArgumentFactory::create(2, 'integer');
}
$this->maxWidth = $maxWidth;
if (!is_int($minHeight) || $minHeight < 0) {
throw InvalidArgumentHelper::factory(3, 'integer');
throw InvalidArgumentFactory::create(3, 'integer');
}
$this->minHeight = $minHeight;
if (!is_int($maxHeight) || $maxHeight < $minHeight) {
throw InvalidArgumentHelper::factory(4, 'integer');
throw InvalidArgumentFactory::create(4, 'integer');
}
$this->maxHeight = $maxHeight;
}
Expand All @@ -63,7 +63,7 @@ public function __construct($minWidth, $maxWidth, $minHeight, $maxHeight)
protected function _matches($other)
{
if (!$other instanceof BoxInterface) {
throw InvalidArgumentHelper::factory(1, 'Imagine\Image\BoxInterface');
throw InvalidArgumentFactory::create(1, 'Imagine\Image\BoxInterface');
}

return
Expand Down
12 changes: 6 additions & 6 deletions tests/tests/Constraint/IsColorSimilar.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Imagine\Test\Constraint;

use Imagine\Image\Palette\Color\ColorInterface;
use PHPUnit\Util\InvalidArgumentHelper;
use Imagine\Test\InvalidArgumentFactory;

class IsColorSimilar extends Constraint
{
Expand Down Expand Up @@ -52,7 +52,7 @@ public function __construct($value, $maxDistance = 0.1, $includeAlpha = true)
{
parent::__construct();
if (!$value instanceof ColorInterface) {
throw InvalidArgumentHelper::factory(1, 'Imagine\Image\Palette\Color\ColorInterface', $value);
throw InvalidArgumentFactory::create(1, 'Imagine\Image\Palette\Color\ColorInterface', $value);
}
$this->value = $value;

Expand All @@ -62,10 +62,10 @@ public function __construct($value, $maxDistance = 0.1, $includeAlpha = true)
if (is_int($maxDistance)) {
$maxDistance = (float) $maxDistance;
} elseif (!is_float($maxDistance)) {
throw InvalidArgumentHelper::factory(2, 'float', $maxDistance);
throw InvalidArgumentFactory::create(2, 'float', $maxDistance);
}
if ($maxDistance < 0) {
throw InvalidArgumentHelper::factory(2, 'float', $maxDistance);
throw InvalidArgumentFactory::create(2, 'float', $maxDistance);
}
$this->maxDistance = $maxDistance;
$this->includeAlpha = (bool) $includeAlpha;
Expand All @@ -79,11 +79,11 @@ public function __construct($value, $maxDistance = 0.1, $includeAlpha = true)
protected function _matches($other)
{
if (!$other instanceof ColorInterface) {
throw InvalidArgumentHelper::factory(1, 'Imagine\Image\Palette\Color\ColorInterface', $other);
throw InvalidArgumentFactory::create(1, 'Imagine\Image\Palette\Color\ColorInterface', $other);
}
$pixelDefinition = $other->getPalette()->pixelDefinition();
if ($pixelDefinition !== $this->pixelDefinition) {
throw InvalidArgumentHelper::factory(1, 'Imagine\Image\Palette\Color\ColorInterface', $other);
throw InvalidArgumentFactory::create(1, 'Imagine\Image\Palette\Color\ColorInterface', $other);
}

$distance = $this->calculateDistance($other);
Expand Down
10 changes: 5 additions & 5 deletions tests/tests/Constraint/IsImageEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Imagine\Image\ImagineInterface;
use Imagine\Image\Palette\PaletteInterface;
use Imagine\Image\Palette\RGB;
use PHPUnit\Util\InvalidArgumentHelper;
use Imagine\Test\InvalidArgumentFactory;

class IsImageEqual extends Constraint
{
Expand Down Expand Up @@ -57,15 +57,15 @@ public function __construct($value, $delta = 0.1, ImagineInterface $imagine = nu
$value = $this->imagine->open($value);
}
if (!$value instanceof ImageInterface) {
throw InvalidArgumentHelper::factory(1, 'Imagine\Image\ImageInterface');
throw InvalidArgumentFactory::create(1, 'Imagine\Image\ImageInterface');
}

if (!is_numeric($delta)) {
throw InvalidArgumentHelper::factory(2, 'numeric');
throw InvalidArgumentFactory::create(2, 'numeric');
}

if (!is_int($buckets) || $buckets <= 0) {
throw InvalidArgumentHelper::factory(4, 'integer');
throw InvalidArgumentFactory::create(4, 'integer');
}

$this->value = $value;
Expand All @@ -82,7 +82,7 @@ protected function _matches($other)
$other = $this->imagine->open($other);
}
if (!$other instanceof ImageInterface) {
throw InvalidArgumentHelper::factory(1, 'Imagine\Image\ImageInterface');
throw InvalidArgumentFactory::create(1, 'Imagine\Image\ImageInterface');
}

$total = $this->getDelta($other);
Expand Down
24 changes: 24 additions & 0 deletions tests/tests/InvalidArgumentFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Imagine\Test;

class InvalidArgumentFactory
{
/**
* @param int $argument
* @param string $type
*
* @return \PHPUnit\Framework\InvalidArgumentException
*/
public static function create($argument, $type)
{
if (class_exists('PHPUnit\Framework\InvalidArgumentException')) {
return \PHPUnit\Framework\InvalidArgumentException::create($argument, $type);
}
if (class_exists('PHPUnit\Util\InvalidArgumentHelper')) {
return \PHPUnit\Util\InvalidArgumentHelper::factory($argument, $type);
}

return \PHPUnit_Util_InvalidArgumentHelper::factory($argument, $type);
}
}