1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\MediaBundle\Tests\DependencyInjection\Compiler; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Sonata\MediaBundle\DependencyInjection\Compiler\ThumbnailCompilerPass; |
18
|
|
|
use Sonata\MediaBundle\Thumbnail\ConsumerThumbnail; |
19
|
|
|
use Sonata\MediaBundle\Thumbnail\FormatThumbnail; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
22
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
23
|
|
|
|
24
|
|
|
final class ThumbnailCompilerPassTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @dataProvider processProvider |
28
|
|
|
*/ |
29
|
|
|
public function testProcess(bool $expected, string $class, ?ParameterBagInterface $parameterBag = null): void |
30
|
|
|
{ |
31
|
|
|
$container = new ContainerBuilder($parameterBag); |
32
|
|
|
$container |
33
|
|
|
->register('foobar') |
34
|
|
|
->addTag('sonata.media.resizer'); |
35
|
|
|
$thumbnailDefinition = $container->register('sonata.media.thumbnail.format', $class); |
36
|
|
|
|
37
|
|
|
(new ThumbnailCompilerPass())->process($container); |
38
|
|
|
|
39
|
|
|
$this->assertSame($expected, $thumbnailDefinition->hasMethodCall('addResizer')); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function processProvider(): array |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
[true, FormatThumbnail::class], |
46
|
|
|
[false, ConsumerThumbnail::class], |
47
|
|
|
[true, '%foo%', new ParameterBag(['foo' => FormatThumbnail::class])], |
48
|
|
|
[false, '%bar%', new ParameterBag(['bar' => TestUncallableAddResizerMethod::class])], |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
final class TestUncallableAddResizerMethod |
54
|
|
|
{ |
55
|
|
|
private function addResizer(): void |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|