Completed
Push — master ( 8c5b1a...9a26dd )
by Tomáš
17:38
created

ConfigurationResolverTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 53.73 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 4
c 2
b 1
f 1
lcom 1
cbo 3
dl 36
loc 67
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testResolveDefaults() 0 16 1
A testOverrideDefaults() 18 18 1
A testAddNewValues() 18 18 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Symplify\DefaultAutowire\Tests\Config\Definition;
4
5
use PHPUnit\Framework\TestCase;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symplify\DefaultAutowire\Config\Definition\ConfigurationResolver;
8
use Symplify\DefaultAutowire\SymplifyDefaultAutowireBundle;
9
10
final class ConfigurationResolverTest extends TestCase
11
{
12
    /**
13
     * @var ConfigurationResolver
14
     */
15
    private $configurationResolver;
16
17
    protected function setUp()
18
    {
19
        $this->configurationResolver = new ConfigurationResolver();
20
    }
21
22
    public function testResolveDefaults()
23
    {
24
        $resolvedConfiguration = $this->configurationResolver->resolveFromContainerBuilder(new ContainerBuilder());
25
26
        $this->assertCount(6, $resolvedConfiguration['autowire_types']);
27
        $this->assertSame([
28
            'autowire_types' => [
29
                'Doctrine\ORM\EntityManager' => 'doctrine.orm.default_entity_manager',
30
                'Doctrine\ORM\EntityManagerInterface' => 'doctrine.orm.default_entity_manager',
31
                'Doctrine\Portability\Connection' => 'database_connection',
32
                'Symfony\Component\EventDispatcher\EventDispatcher' => 'event_dispatcher',
33
                'Symfony\Component\EventDispatcher\EventDispatcherInterface' => 'event_dispatcher',
34
                'Symfony\Component\Translation\TranslatorInterface' => 'translator',
35
            ],
36
        ], $resolvedConfiguration);
37
    }
38
39 View Code Duplication
    public function testOverrideDefaults()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        $containerBuilder = new ContainerBuilder();
42
43
        $containerBuilder->prependExtensionConfig(SymplifyDefaultAutowireBundle::ALIAS, [
44
            'autowire_types' => [
45
                'Doctrine\ORM\EntityManager' => 'other_entity_manager',
46
            ],
47
        ]);
48
49
        $resolvedConfiguration = $this->configurationResolver->resolveFromContainerBuilder(
50
            $containerBuilder
51
        );
52
53
        $autowireTypes = $resolvedConfiguration['autowire_types'];
54
        $this->assertCount(6, $autowireTypes);
55
        $this->assertSame('other_entity_manager', $autowireTypes['Doctrine\ORM\EntityManager']);
56
    }
57
58 View Code Duplication
    public function testAddNewValues()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $containerBuilder = new ContainerBuilder();
61
62
        $containerBuilder->prependExtensionConfig(SymplifyDefaultAutowireBundle::ALIAS, [
63
            'autowire_types' => [
64
                'SomeInterface' => 'some_service',
65
            ],
66
        ]);
67
68
        $resolvedConfiguration = $this->configurationResolver->resolveFromContainerBuilder(
69
            $containerBuilder
70
        );
71
72
        $autowireTypes = $resolvedConfiguration['autowire_types'];
73
        $this->assertCount(7, $autowireTypes);
74
        $this->assertSame('some_service', $autowireTypes['SomeInterface']);
75
    }
76
}
77