AddTemplatesCompilerPassTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetThemes() 0 43 1
A registerCompilerPass() 0 4 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\DoctrineMongoDBAdminBundle\Tests\DependencyInjection\Compiler;
15
16
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
17
use Sonata\DoctrineMongoDBAdminBundle\DependencyInjection\Compiler\AddTemplatesCompilerPass;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Definition;
20
21
final class AddTemplatesCompilerPassTest extends AbstractCompilerPassTestCase
22
{
23
    public function testSetThemes(): void
24
    {
25
        $adminServiceId = 'admin_id';
26
        $adminService = new Definition();
27
        $adminService->addTag('sonata.admin', ['manager_type' => 'doctrine_mongodb']);
28
        $this->setDefinition($adminServiceId, $adminService);
29
30
        $adminServiceNotManagedId = 'admin_not_managed_id';
31
        $adminServiceNotManaged = new Definition();
32
        $adminServiceNotManaged->addTag('sonata.admin', ['manager_type' => 'type']);
33
        $this->setDefinition($adminServiceNotManagedId, $adminServiceNotManaged);
34
35
        $formTemplates = [
36
            'form.html.twig',
37
        ];
38
        $filterTemplates = [
39
            'filter.html.twig',
40
        ];
41
        $templates = [
42
            'form' => $formTemplates,
43
            'filter' => $filterTemplates,
44
        ];
45
46
        $this->setParameter('sonata_doctrine_mongodb_admin.templates', $templates);
47
48
        $this->compile();
49
50
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
51
            $adminServiceId,
52
            'setFormTheme',
53
            [
54
                $formTemplates,
55
            ]
56
        );
57
58
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
59
            $adminServiceId,
60
            'setFilterTheme',
61
            [
62
                $filterTemplates,
63
            ]
64
        );
65
    }
66
67
    protected function registerCompilerPass(ContainerBuilder $container): void
68
    {
69
        $container->addCompilerPass(new AddTemplatesCompilerPass());
70
    }
71
}
72