Skip to content
Open
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
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions src/lib/FieldType/Image/ImageThumbnailProxyStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* @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;
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
use Ibexa\Core\FieldType\Image\ImageThumbnailProxyStrategy;
use Ibexa\Core\FieldType\Image\ImageThumbnailStrategy;
use Ibexa\Core\Repository\ProxyFactory\ProxyGenerator;
use Ibexa\Core\Repository\ProxyFactory\ProxyGeneratorInterface;
use PHPUnit\Framework\TestCase;
use RuntimeException;

final class ImageThumbnailProxyStrategyTest extends TestCase
{
/** @var \Ibexa\Core\FieldType\Image\ImageThumbnailStrategy&\PHPUnit\Framework\MockObject\MockObject */
private ImageThumbnailStrategy $imageThumbnailStrategyMock;

private ProxyGeneratorInterface $proxyGeneratorMock;

private ImageThumbnailProxyStrategy $strategy;

protected function setUp(): void
{
$this->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();

Check failure on line 57 in tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Call to an undefined method Ibexa\Contracts\Core\Repository\Values\Content\Thumbnail::getMimeType().

Check failure on line 57 in tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Call to an undefined method Ibexa\Contracts\Core\Repository\Values\Content\Thumbnail::getMimeType().

Check failure on line 57 in tests/bundle/IO/FieldType/Image/ImageThumbnailProxyStrategyTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Call to an undefined method Ibexa\Contracts\Core\Repository\Values\Content\Thumbnail::getMimeType().
}
}
Loading