54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Service;
|
|
|
|
use App\BusProNet\Model\VoucherTemplate;
|
|
use App\Service\VoucherThumbnailResolver;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class VoucherThumbnailResolverTest extends TestCase
|
|
{
|
|
private string $manifestPath;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->manifestPath = tempnam(sys_get_temp_dir(), 'manifest');
|
|
file_put_contents($this->manifestPath, json_encode([
|
|
'build/images/vouchers/muster_3.jpg' => '/build/images/vouchers/muster_3.0a1b2c3d.jpg',
|
|
]));
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
@unlink($this->manifestPath);
|
|
}
|
|
|
|
public function testAThumbnailIsFoundByTheTemplateId(): void
|
|
{
|
|
$logger = $this->createMock(LoggerInterface::class);
|
|
$logger->expects(self::never())->method('warning');
|
|
|
|
$resolver = new VoucherThumbnailResolver($this->manifestPath, $logger);
|
|
|
|
self::assertSame('build/images/vouchers/muster_3.jpg', $resolver->resolve(new VoucherTemplate(3, 'K', 'Allgemein')));
|
|
}
|
|
|
|
public function testANewDesignWithoutAThumbnailRendersWithoutOneAndIsReported(): void
|
|
{
|
|
$logger = $this->createMock(LoggerInterface::class);
|
|
$logger->expects(self::once())->method('warning')->with('No thumbnail for voucher template', self::callback(
|
|
static fn (array $context) => 6 === $context['template_id'] && 'assets/vouchers/muster_6.jpg' === $context['expected_source']
|
|
));
|
|
|
|
$resolver = new VoucherThumbnailResolver($this->manifestPath, $logger);
|
|
|
|
self::assertSame(
|
|
[3 => 'build/images/vouchers/muster_3.jpg', 6 => null],
|
|
$resolver->resolveAll([new VoucherTemplate(3, 'K', 'Allgemein'), new VoucherTemplate(6, 'K', 'Ostern')]),
|
|
);
|
|
}
|
|
}
|