Completed
Push — master ( 31a9ea...5d6556 )
by
unknown
03:38 queued 11s
created

ThumbnailCompilerPassTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testProcess() 0 12 1
A processProvider() 0 9 1
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
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
56
    {
57
    }
58
}
59