|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @copyright Copyright (C) Ibexa AS. All rights reserved. |
| 5 | + * @license For full copyright and license information view LICENSE file distributed with this source code. |
| 6 | + */ |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Ibexa\Tests\Bundle\IO\FieldType\Image; |
| 10 | + |
| 11 | +use Ibexa\Contracts\Core\Repository\Values\Content\Field; |
| 12 | +use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; |
| 13 | +use Ibexa\Core\FieldType\Image\ImageThumbnailProxyStrategy; |
| 14 | +use Ibexa\Core\FieldType\Image\ImageThumbnailStrategy; |
| 15 | +use Ibexa\Core\Repository\ProxyFactory\ProxyGenerator; |
| 16 | +use PHPUnit\Framework\MockObject\MockObject; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | +use RuntimeException; |
| 19 | + |
| 20 | +final class ImageThumbnailProxyStrategyTest extends TestCase |
| 21 | +{ |
| 22 | + private ImageThumbnailStrategy & MockObject $imageThumbnailStrategyMock; |
| 23 | + |
| 24 | + private ImageThumbnailProxyStrategy $strategy; |
| 25 | + |
| 26 | + protected function setUp(): void |
| 27 | + { |
| 28 | + $this->imageThumbnailStrategyMock = $this->createMock(ImageThumbnailStrategy::class); |
| 29 | + $proxyGenerator = new ProxyGenerator(__DIR__ . '/../../../../../var/proxy'); |
| 30 | + |
| 31 | + $this->strategy = new ImageThumbnailProxyStrategy( |
| 32 | + $this->imageThumbnailStrategyMock, |
| 33 | + $proxyGenerator, |
| 34 | + ); |
| 35 | + } |
| 36 | + |
| 37 | + public function testGetThumbnailThrowsExceptionIfWrappedObjectIsNull(): void |
| 38 | + { |
| 39 | + $field = $this->createMock(Field::class); |
| 40 | + $field->method('getId')->willReturn(123); |
| 41 | + $field->method('getFieldTypeIdentifier')->willReturn('ezimage'); |
| 42 | + |
| 43 | + $versionInfo = $this->createMock(VersionInfo::class); |
| 44 | + |
| 45 | + $this->imageThumbnailStrategyMock |
| 46 | + ->expects(self::once()) |
| 47 | + ->method('getThumbnail') |
| 48 | + ->with($field, $versionInfo) |
| 49 | + ->willReturn(null); |
| 50 | + |
| 51 | + $thumbnail = $this->strategy->getThumbnail($field, $versionInfo); |
| 52 | + |
| 53 | + $this->expectException(RuntimeException::class); |
| 54 | + $this->expectExceptionMessage('Failed to prepare thumbnail for field type "123" (ID: ezimage) using'); |
| 55 | + |
| 56 | + // Initialize proxy |
| 57 | + // @phpstan-ignore expr.resultUnused |
| 58 | + $thumbnail->mimeType; |
| 59 | + } |
| 60 | +} |
0 commit comments