From 7383c2b5df28bc3c803ecaa16dac5a0cd50be40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 22 Dec 2025 18:56:29 +0100 Subject: [PATCH 1/5] IBX-11130: Fixed proxy initializer returning `null` --- .../Repository/Values/Content/Thumbnail.php | 20 +++++++ .../Image/ImageThumbnailProxyStrategy.php | 18 ++++-- .../Image/ImageThumbnailProxyStrategyTest.php | 60 +++++++++++++++++++ 3 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php diff --git a/src/contracts/Repository/Values/Content/Thumbnail.php b/src/contracts/Repository/Values/Content/Thumbnail.php index 80caed993e..13841d7894 100644 --- a/src/contracts/Repository/Values/Content/Thumbnail.php +++ b/src/contracts/Repository/Values/Content/Thumbnail.php @@ -33,6 +33,26 @@ class Thumbnail extends ValueObject /** @var string|null */ protected $mimeType; + + public function getResource(): string + { + return $this->resource; + } + + public function getWidth(): ?int + { + return $this->width; + } + + public function getHeight(): ?int + { + return $this->height; + } + + public function getMimeType(): ?string + { + return $this->mimeType; + } } class_alias(Thumbnail::class, 'eZ\Publish\API\Repository\Values\Content\Thumbnail'); diff --git a/src/lib/FieldType/Image/ImageThumbnailProxyStrategy.php b/src/lib/FieldType/Image/ImageThumbnailProxyStrategy.php index eac301a992..ed363f34b4 100644 --- a/src/lib/FieldType/Image/ImageThumbnailProxyStrategy.php +++ b/src/lib/FieldType/Image/ImageThumbnailProxyStrategy.php @@ -14,14 +14,13 @@ use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; use Ibexa\Core\Repository\ProxyFactory\ProxyGeneratorInterface; use ProxyManager\Proxy\LazyLoadingInterface; +use RuntimeException; final class ImageThumbnailProxyStrategy implements FieldTypeBasedThumbnailStrategy { - /** @var \Ibexa\Core\FieldType\Image\ImageThumbnailStrategy */ - private $imageThumbnailStrategy; + private ImageThumbnailStrategy $imageThumbnailStrategy; - /** @var \Ibexa\Core\Repository\ProxyFactory\ProxyGeneratorInterface */ - private $proxyGenerator; + private ProxyGeneratorInterface $proxyGenerator; public function __construct( ImageThumbnailStrategy $imageThumbnailStrategy, @@ -36,7 +35,7 @@ public function getFieldTypeIdentifier(): string return $this->imageThumbnailStrategy->getFieldTypeIdentifier(); } - public function getThumbnail(Field $field, ?VersionInfo $versionInfo = null): ?Thumbnail + public function getThumbnail(Field $field, ?VersionInfo $versionInfo = null): Thumbnail { $initializer = function ( &$wrappedObject, @@ -49,6 +48,15 @@ public function getThumbnail(Field $field, ?VersionInfo $versionInfo = null): ?T $wrappedObject = $this->imageThumbnailStrategy->getThumbnail($field, $versionInfo); + if ($wrappedObject === null) { + throw new RuntimeException(sprintf( + 'Failed to prepare thumbnail for field type "%s" (ID: %s) using "%s" strategy.', + $field->getId(), + $field->getFieldTypeIdentifier(), + get_debug_type($this->imageThumbnailStrategy), + )); + } + return true; }; diff --git a/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php b/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php new file mode 100644 index 0000000000..3213349a83 --- /dev/null +++ b/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php @@ -0,0 +1,60 @@ +imageThumbnailStrategyMock = $this->createMock(ImageThumbnailStrategy::class); + $this->proxyGeneratorMock = new ProxyGenerator(__DIR__ . '/../../../../../var/proxy'); + + $this->strategy = new ImageThumbnailProxyStrategy( + $this->imageThumbnailStrategyMock, + $this->proxyGeneratorMock, + ); + } + + public function testGetThumbnailThrowsExceptionIfWrappedObjectIsNull(): void + { + $field = $this->createMock(Field::class); + $field->method('getId')->willReturn(123); + $field->method('getFieldTypeIdentifier')->willReturn('ezimage'); + + $versionInfo = $this->createMock(VersionInfo::class); + + $this->imageThumbnailStrategyMock + ->expects(self::once()) + ->method('getThumbnail') + ->with($field, $versionInfo) + ->willReturn(null); + + $thumbnail = $this->strategy->getThumbnail($field, $versionInfo); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Failed to prepare thumbnail for field type "123" (ID: ezimage) using'); + + $thumbnail->getMimeType(); + } +} From 674254c3db6c25c8deee8f24c560d2f0e49e5df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 22 Dec 2025 19:19:14 +0100 Subject: [PATCH 2/5] Fixed CI --- phpstan-baseline.neon | 6 ------ .../IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php | 1 - 2 files changed, 7 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6cedc78f98..3a59abe14b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -11304,12 +11304,6 @@ parameters: count: 1 path: src/lib/FieldType/Image/ImageStorage/Gateway/DoctrineStorage.php - - - message: '#^Method Ibexa\\Core\\FieldType\\Image\\ImageThumbnailProxyStrategy\:\:getThumbnail\(\) never returns null so it can be removed from the return type\.$#' - identifier: return.unusedType - count: 1 - path: src/lib/FieldType/Image/ImageThumbnailProxyStrategy.php - - message: '#^Parameter \#3 \$pad_string of function str_pad expects string, int given\.$#' identifier: argument.type diff --git a/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php b/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php index 3213349a83..7600d4f4af 100644 --- a/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php +++ b/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php @@ -4,7 +4,6 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ - namespace Ibexa\Tests\Bundle\IO\FieldType\Image; use Ibexa\Contracts\Core\Repository\Values\Content\Field; From 460bb8c88b39c9ffb5a6ea7707c11f853fadd60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 23 Dec 2025 12:40:23 +0100 Subject: [PATCH 3/5] Removed changes out of scope for the actual fix --- .../Repository/Values/Content/Thumbnail.php | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/contracts/Repository/Values/Content/Thumbnail.php b/src/contracts/Repository/Values/Content/Thumbnail.php index 13841d7894..80caed993e 100644 --- a/src/contracts/Repository/Values/Content/Thumbnail.php +++ b/src/contracts/Repository/Values/Content/Thumbnail.php @@ -33,26 +33,6 @@ class Thumbnail extends ValueObject /** @var string|null */ protected $mimeType; - - public function getResource(): string - { - return $this->resource; - } - - public function getWidth(): ?int - { - return $this->width; - } - - public function getHeight(): ?int - { - return $this->height; - } - - public function getMimeType(): ?string - { - return $this->mimeType; - } } class_alias(Thumbnail::class, 'eZ\Publish\API\Repository\Values\Content\Thumbnail'); From 0a286b6e8e961b2c3a1be95b043f2398f5897663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 29 Dec 2025 10:45:54 +0100 Subject: [PATCH 4/5] Removed changes out of scope for the actual fix --- .../IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php b/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php index 7600d4f4af..a31635509c 100644 --- a/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php +++ b/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php @@ -54,6 +54,7 @@ public function testGetThumbnailThrowsExceptionIfWrappedObjectIsNull(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Failed to prepare thumbnail for field type "123" (ID: ezimage) using'); - $thumbnail->getMimeType(); + // Initialize proxy + $thumbnail->mimeType; } } From 972e4c1cbb1b9f57f33cd05f1eaeff865a8c4630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 30 Dec 2025 11:11:56 +0100 Subject: [PATCH 5/5] Removed changes out of scope for the actual fix --- .../IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php b/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php index a31635509c..0a9a468a89 100644 --- a/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php +++ b/tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php @@ -55,6 +55,7 @@ public function testGetThumbnailThrowsExceptionIfWrappedObjectIsNull(): void $this->expectExceptionMessage('Failed to prepare thumbnail for field type "123" (ID: ezimage) using'); // Initialize proxy + // @phpstan-ignore expr.resultUnused $thumbnail->mimeType; } }