From 8dfb1ba282486ae28cada7f94fad70f9984a76d1 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Mon, 2 Dec 2024 18:02:27 +0100 Subject: [PATCH 1/8] Fix PHP 8.4 deprecations nullable objects --- .php-cs-fixer.dist.php | 3 +++ src/Filter/Advanced/Canvas.php | 2 +- src/Filter/Basic/Rotate.php | 2 +- src/Filter/Transformation.php | 4 ++-- src/Gd/Image.php | 2 +- src/Gd/Imagine.php | 2 +- src/Gmagick/Image.php | 2 +- src/Gmagick/Imagine.php | 2 +- src/Image/Box.php | 2 +- src/Image/BoxInterface.php | 2 +- src/Image/ImagineInterface.php | 2 +- src/Image/ManipulatorInterface.php | 2 +- src/Imagick/Image.php | 2 +- src/Imagick/Imagine.php | 2 +- tests/tests/Constraint/IsImageEqual.php | 2 +- tests/tests/Filter/Advanced/CanvasTest.php | 2 +- tests/tests/Image/Fill/Gradient/HorizontalTest.php | 1 + tests/tests/Image/Fill/Gradient/VerticalTest.php | 1 + tests/tests/ImagineTestCaseBase.php | 2 +- 19 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index ac6ed8e48..77f455b86 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,4 +1,5 @@ true, // Write conditions in Yoda style (`true`), non-Yoda style (`['equal' => false, 'identical' => false, 'less_and_greater' => false]`) or ignore those conditions (`null`) based on configuration. 'yoda_style' => array('always_move_variable' => false, 'equal' => false, 'identical' => false, 'less_and_greater' => false), + // Make type definition of default null also nullable to avoid PHP 8.4 deprecations + 'nullable_type_declaration_for_default_null_value' => true, )) ->setFinder( PhpCsFixer\Finder::create() diff --git a/src/Filter/Advanced/Canvas.php b/src/Filter/Advanced/Canvas.php index f8a98610f..ea04bf91e 100644 --- a/src/Filter/Advanced/Canvas.php +++ b/src/Filter/Advanced/Canvas.php @@ -52,7 +52,7 @@ class Canvas implements FilterInterface * @param \Imagine\Image\PointInterface $placement * @param \Imagine\Image\Palette\Color\ColorInterface $background */ - public function __construct(ImagineInterface $imagine, BoxInterface $size, PointInterface $placement = null, ColorInterface $background = null) + public function __construct(ImagineInterface $imagine, BoxInterface $size, ?PointInterface $placement = null, ?ColorInterface $background = null) { $this->imagine = $imagine; $this->size = $size; diff --git a/src/Filter/Basic/Rotate.php b/src/Filter/Basic/Rotate.php index 9992a8f00..96bbdff6b 100644 --- a/src/Filter/Basic/Rotate.php +++ b/src/Filter/Basic/Rotate.php @@ -36,7 +36,7 @@ class Rotate implements FilterInterface * @param int $angle * @param \Imagine\Image\Palette\Color\ColorInterface $background */ - public function __construct($angle, ColorInterface $background = null) + public function __construct($angle, ?ColorInterface $background = null) { $this->angle = $angle; $this->background = $background; diff --git a/src/Filter/Transformation.php b/src/Filter/Transformation.php index b7861d017..763651e0e 100644 --- a/src/Filter/Transformation.php +++ b/src/Filter/Transformation.php @@ -60,7 +60,7 @@ final class Transformation implements FilterInterface, ManipulatorInterface * * @param \Imagine\Image\ImageInterface|null $imagine An ImagineInterface instance */ - public function __construct(ImagineInterface $imagine = null) + public function __construct(?ImagineInterface $imagine = null) { $this->imagine = $imagine; } @@ -215,7 +215,7 @@ public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDE * * @see \Imagine\Image\ManipulatorInterface::rotate() */ - public function rotate($angle, ColorInterface $background = null) + public function rotate($angle, ?ColorInterface $background = null) { return $this->add(new Rotate($angle, $background)); } diff --git a/src/Gd/Image.php b/src/Gd/Image.php index 6c9d21d61..e418576e4 100644 --- a/src/Gd/Image.php +++ b/src/Gd/Image.php @@ -239,7 +239,7 @@ final public function resize(BoxInterface $size, $filter = ImageInterface::FILTE * * @see \Imagine\Image\ManipulatorInterface::rotate() */ - final public function rotate($angle, ColorInterface $background = null) + final public function rotate($angle, ?ColorInterface $background = null) { if ($background === null) { $background = $this->palette->color('fff'); diff --git a/src/Gd/Imagine.php b/src/Gd/Imagine.php index bcb9a2fd7..bae32743d 100644 --- a/src/Gd/Imagine.php +++ b/src/Gd/Imagine.php @@ -55,7 +55,7 @@ public static function getDriverInfo($required = true) * * @see \Imagine\Image\ImagineInterface::create() */ - public function create(BoxInterface $size, ColorInterface $color = null) + public function create(BoxInterface $size, ?ColorInterface $color = null) { $width = $size->getWidth(); $height = $size->getHeight(); diff --git a/src/Gmagick/Image.php b/src/Gmagick/Image.php index 0ef178302..e67d46f38 100644 --- a/src/Gmagick/Image.php +++ b/src/Gmagick/Image.php @@ -275,7 +275,7 @@ public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDE * * @see \Imagine\Image\ManipulatorInterface::rotate() */ - public function rotate($angle, ColorInterface $background = null) + public function rotate($angle, ?ColorInterface $background = null) { try { if ($background === null) { diff --git a/src/Gmagick/Imagine.php b/src/Gmagick/Imagine.php index d1159b13f..dfaae804b 100644 --- a/src/Gmagick/Imagine.php +++ b/src/Gmagick/Imagine.php @@ -81,7 +81,7 @@ public function open($path) * * @see \Imagine\Image\ImagineInterface::create() */ - public function create(BoxInterface $size, ColorInterface $color = null) + public function create(BoxInterface $size, ?ColorInterface $color = null) { $width = $size->getWidth(); $height = $size->getHeight(); diff --git a/src/Image/Box.php b/src/Image/Box.php index fee2fdef3..b8ba74652 100644 --- a/src/Image/Box.php +++ b/src/Image/Box.php @@ -99,7 +99,7 @@ public function increase($size) * * @see \Imagine\Image\BoxInterface::contains() */ - public function contains(BoxInterface $box, PointInterface $start = null) + public function contains(BoxInterface $box, ?PointInterface $start = null) { $start = $start ? $start : new Point(0, 0); diff --git a/src/Image/BoxInterface.php b/src/Image/BoxInterface.php index b963777a5..a882ab876 100644 --- a/src/Image/BoxInterface.php +++ b/src/Image/BoxInterface.php @@ -57,7 +57,7 @@ public function increase($size); * * @return bool */ - public function contains(BoxInterface $box, PointInterface $start = null); + public function contains(BoxInterface $box, ?PointInterface $start = null); /** * Gets current box square, useful for getting total number of pixels in a diff --git a/src/Image/ImagineInterface.php b/src/Image/ImagineInterface.php index 7a41cee4e..ab0b07cfd 100644 --- a/src/Image/ImagineInterface.php +++ b/src/Image/ImagineInterface.php @@ -33,7 +33,7 @@ interface ImagineInterface extends ClassFactoryAwareInterface * * @return \Imagine\Image\ImageInterface */ - public function create(BoxInterface $size, ColorInterface $color = null); + public function create(BoxInterface $size, ?ColorInterface $color = null); /** * Opens an existing image from $path. diff --git a/src/Image/ManipulatorInterface.php b/src/Image/ManipulatorInterface.php index 23f033fbb..f889a20c9 100644 --- a/src/Image/ManipulatorInterface.php +++ b/src/Image/ManipulatorInterface.php @@ -94,7 +94,7 @@ public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDE * * @return $this */ - public function rotate($angle, ColorInterface $background = null); + public function rotate($angle, ?ColorInterface $background = null); /** * Pastes an image into a parent image diff --git a/src/Imagick/Image.php b/src/Imagick/Image.php index 98435ceb0..bab72106d 100644 --- a/src/Imagick/Image.php +++ b/src/Imagick/Image.php @@ -305,7 +305,7 @@ public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDE * * @see \Imagine\Image\ManipulatorInterface::rotate() */ - public function rotate($angle, ColorInterface $background = null) + public function rotate($angle, ?ColorInterface $background = null) { if ($background === null) { $background = $this->palette->color('fff'); diff --git a/src/Imagick/Imagine.php b/src/Imagick/Imagine.php index 0bb36ba66..e63b67f21 100644 --- a/src/Imagick/Imagine.php +++ b/src/Imagick/Imagine.php @@ -88,7 +88,7 @@ public function open($path) * * @see \Imagine\Image\ImagineInterface::create() */ - public function create(BoxInterface $size, ColorInterface $color = null) + public function create(BoxInterface $size, ?ColorInterface $color = null) { $width = $size->getWidth(); $height = $size->getHeight(); diff --git a/tests/tests/Constraint/IsImageEqual.php b/tests/tests/Constraint/IsImageEqual.php index 5e5d7adac..224188256 100644 --- a/tests/tests/Constraint/IsImageEqual.php +++ b/tests/tests/Constraint/IsImageEqual.php @@ -59,7 +59,7 @@ class IsImageEqual extends Constraint * * @throws \InvalidArgumentException */ - public function __construct($expected, $delta = 0.1, ImagineInterface $imagine = null, $buckets = 4) + public function __construct($expected, $delta = 0.1, ?ImagineInterface $imagine = null, $buckets = 4) { parent::__construct(); $this->imagine = $imagine; diff --git a/tests/tests/Filter/Advanced/CanvasTest.php b/tests/tests/Filter/Advanced/CanvasTest.php index fdd7f4742..f3ac3a7b3 100644 --- a/tests/tests/Filter/Advanced/CanvasTest.php +++ b/tests/tests/Filter/Advanced/CanvasTest.php @@ -30,7 +30,7 @@ class CanvasTest extends FilterTestCase * @param PointInterface $placement * @param ColorInterface $background */ - public function testShouldCanvasImageAndReturnResult(BoxInterface $size, PointInterface $placement = null, ColorInterface $background = null) + public function testShouldCanvasImageAndReturnResult(BoxInterface $size, ?PointInterface $placement = null, ?ColorInterface $background = null) { $placement = $placement ?: new Point(0, 0); $image = $this->getImage(); diff --git a/tests/tests/Image/Fill/Gradient/HorizontalTest.php b/tests/tests/Image/Fill/Gradient/HorizontalTest.php index e6b02af95..53949f7e4 100644 --- a/tests/tests/Image/Fill/Gradient/HorizontalTest.php +++ b/tests/tests/Image/Fill/Gradient/HorizontalTest.php @@ -1,4 +1,5 @@ Date: Mon, 2 Dec 2024 18:09:58 +0100 Subject: [PATCH 2/8] Fix deprecated github action --- .github/workflows/phpunit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 552b3ad8e..580a44b30 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -71,7 +71,7 @@ jobs: run: composer run test --ansi --no-interaction -- --exclude-group "${{ steps.inspect.outputs.excluded-groups }}" - name: Save tests temporary files if: always() && env.IMAGINE_TEST_KEEP_TEMPFILES == 'yes' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: windows-${{ matrix.php-version }}-${{ matrix.extensions }} path: tests/tmp/ @@ -129,7 +129,7 @@ jobs: run: composer run test --ansi --no-interaction -- --exclude-group "${{ steps.inspect.outputs.excluded-groups }}" - name: Save tests temporary files if: always() && env.IMAGINE_TEST_KEEP_TEMPFILES == 'yes' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: docker-${{ matrix.php-version }}-${{ matrix.image-suffix }} path: tests/tmp/ From c2cb94c995842ab8eec71440f44e57451a0a634c Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Mon, 2 Dec 2024 20:50:47 +0100 Subject: [PATCH 3/8] Increase required PHP version to 7.1 --- .github/workflows/phpunit.yml | 6 +++--- composer.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 580a44b30..93e0a6fb9 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -84,15 +84,15 @@ jobs: fail-fast: false matrix: php-version: - - "5.5" - - "5.6" - - "7.0" - "7.1" - "7.2" - "7.3" - "7.4" - "8.0" - "8.1" + - "8.2" + - "8.3" + - "8.4" image-suffix: - gd-gmagick - gd-imagick diff --git a/composer.json b/composer.json index 37e02b3be..2e47c0639 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": ">=5.5" + "php": ">=7.1" }, "require-dev": { "phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.5 || ^8.4 || ^9.3" From f5188d3b28f9877b6dd11177b8acfee6f1f81458 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Mon, 2 Dec 2024 20:53:35 +0100 Subject: [PATCH 4/8] Use specific ubuntu version --- .github/workflows/phpunit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 93e0a6fb9..50100fb74 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -79,7 +79,7 @@ jobs: docker: name: PHP ${{ matrix.php-version }} - ${{ matrix.image-suffix }} (Docker) - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: From 3704e6bd5c272637429f632b18c4b0abce31da5d Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Tue, 3 Dec 2024 11:48:20 +0100 Subject: [PATCH 5/8] Add hint about supported PHP versions --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a824a5213..cfb85b181 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,12 @@ libraries. The Imagine library has the following requirements: - - PHP 5.5+ + - PHP 7.1+ + +Older version of the library support also older PHP Version: + + - PHP 5.5 - 7.0 use version ^1.3 + - PHP 5.3 - 5.4 use version ^1.2 Depending on the chosen Image implementation, you may need one of the following PHP extensions: From 57adb89db549356dbd1505e9ee1f8a989f2adeed Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Tue, 3 Dec 2024 11:55:00 +0100 Subject: [PATCH 6/8] Fix gmackig mock --- tests/tests/Gmagick/LayersTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/tests/Gmagick/LayersTest.php b/tests/tests/Gmagick/LayersTest.php index c9eab4ebe..189fdd306 100644 --- a/tests/tests/Gmagick/LayersTest.php +++ b/tests/tests/Gmagick/LayersTest.php @@ -86,9 +86,11 @@ public function testCount() public function testWebpFormatIsAllowedAsAnimatedFormat() { - $palette = new RGB(); + $this->checkGmagickMockable(); $resource = $this->getMockBuilder('\Gmagick')->getMock(); + $palette = new RGB(); + $resource->expects($this->atLeastOnce()) ->method('getNumberImages') ->will($this->returnValue(42)); From 25b8f450a1ed8ef4368747a2b21c7fb8db092edb Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Tue, 3 Dec 2024 14:04:49 +0100 Subject: [PATCH 7/8] Add getImage to mock in testWebpFormatIsAllowedAsAnimatedFormat --- tests/tests/Imagick/LayersTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/tests/Imagick/LayersTest.php b/tests/tests/Imagick/LayersTest.php index 15d964d3f..a5e5b4b4f 100644 --- a/tests/tests/Imagick/LayersTest.php +++ b/tests/tests/Imagick/LayersTest.php @@ -92,6 +92,10 @@ public function testWebpFormatIsAllowedAsAnimatedFormat() ->method('getNumberImages') ->will($this->returnValue(42)); + $resource->expects($this->atLeastOnce()) + ->method('getImage') + ->will($this->returnValue($resource)); + $layers = new Layers(new Image($resource, $palette, new MetadataBag()), $palette, $resource); $layers->animate('webp', 200, 0); From 15eea8732491d6f07552503da4462431fd04a4d6 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Tue, 3 Dec 2024 14:05:33 +0100 Subject: [PATCH 8/8] Remove mock from imagick testWebpFormatIsAllowedAsAnimatedFormat --- tests/tests/Imagick/LayersTest.php | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/tests/tests/Imagick/LayersTest.php b/tests/tests/Imagick/LayersTest.php index a5e5b4b4f..3de8d9eeb 100644 --- a/tests/tests/Imagick/LayersTest.php +++ b/tests/tests/Imagick/LayersTest.php @@ -85,20 +85,12 @@ public function testCount() public function testWebpFormatIsAllowedAsAnimatedFormat() { - $palette = new RGB(); - $resource = $this->getMockBuilder('\Imagick')->getMock(); - - $resource->expects($this->atLeastOnce()) - ->method('getNumberImages') - ->will($this->returnValue(42)); - - $resource->expects($this->atLeastOnce()) - ->method('getImage') - ->will($this->returnValue($resource)); - - $layers = new Layers(new Image($resource, $palette, new MetadataBag()), $palette, $resource); - - $layers->animate('webp', 200, 0); + $image = $this->getImagine()->open(IMAGINE_TEST_FIXTURESFOLDER . '/anima3.gif'); + $originalDelayInTicks = $image->layers()->get(0)->getImagick()->getImageDelay(); + $image->layers()->animate('webp', (int) (1000 + $originalDelayInTicks * 1000 / 20), 0); + $this->assertSame('webp', $image->getImagick()->getFormat()); + $newDelayInTicks = $image->layers()->get(0)->getImagick()->getImageDelay(); + $this->assertNotEquals($originalDelayInTicks, $newDelayInTicks); } public function testGetLayer()