AnonymizeCommandPassTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
c 1
b 0
f 0
dl 0
loc 70
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testAnnotationReaderPassed() 0 12 1
A testDoctrinePassed() 0 10 1
A testConfigPassed() 0 15 1
A registerCompilerPass() 0 4 1
A getConfig() 0 10 1
1
<?php
2
3
namespace WebnetFr\DatabaseAnonymizerBundle\Tests\System\DependencyInjection\Compiler;
4
5
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
use WebnetFr\DatabaseAnonymizerBundle\Command\AnonymizeCommand;
10
use WebnetFr\DatabaseAnonymizerBundle\Config\AnnotationConfigFactory;
11
use WebnetFr\DatabaseAnonymizerBundle\DependencyInjection\Compiler\AnonymizeCommandPass;
12
13
/**
14
 * @see AnonymizeCommandPass
15
 *
16
 * @author Vlad Riabchenko <[email protected]>
17
 */
18
class AnonymizeCommandPassTest extends AbstractCompilerPassTestCase
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function registerCompilerPass(ContainerBuilder $container)
24
    {
25
        $container->addCompilerPass(new AnonymizeCommandPass());
26
        $container->prependExtensionConfig('webnet_fr_database_anonymizer', $this->getConfig());
27
    }
28
29
    public function testConfigPassed()
30
    {
31
        $this->setDefinition(AnonymizeCommand::class, new Definition());
32
        $this->compile();
33
34
        $expectedConfig = [
35
            'connections' => [
36
                'default' => $this->getConfig(),
37
            ]
38
        ];
39
40
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
41
            AnonymizeCommand::class,
42
            'setDefaultConfig',
43
            [$expectedConfig]
44
        );
45
    }
46
47
    public function testDoctrinePassed()
48
    {
49
        $this->setDefinition(AnonymizeCommand::class, new Definition());
50
        $this->setDefinition('doctrine', new Definition());
51
        $this->compile();
52
53
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
54
            AnonymizeCommand::class,
55
            'setRegistry',
56
            [new Reference('doctrine')]
57
        );
58
    }
59
60
    public function testAnnotationReaderPassed()
61
    {
62
        $this->setDefinition(AnonymizeCommand::class, new Definition());
63
        $this->setDefinition('annotations.reader', new Definition());
64
        $this->compile();
65
66
        $this->assertContainerBuilderHasService(AnnotationConfigFactory::class);
67
68
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
69
            AnonymizeCommand::class,
70
            'enableAnnotations',
71
            [new Reference(AnnotationConfigFactory::class)]
72
        );
73
    }
74
75
    /**
76
     * @return array
77
     */
78
    private function getConfig()
79
    {
80
        return [
81
            'defaults' => [
82
                'locale' => 'fr_FR',
83
            ],
84
            'tables' => [
85
                'users' => [
86
                    'fields' => [],
87
                    'primary_key' => [],
88
                ],
89
            ],
90
        ];
91
    }
92
}
93