Completed
Push — develop ( 7f6ad2...eb155e )
by Baptiste
02:38
created

InnmindNeo4jExtensionTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 128
Duplicated Lines 27.34 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 35
loc 128
ccs 0
cts 100
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 22 1
A testPersister() 7 7 1
A testConnection() 0 17 1
A testTypes() 0 11 1
A testMetadataConfiguration() 7 7 1
A testDefaultPersister() 12 12 1
A testDefaultConnection() 0 20 1
A testDefaultTypes() 0 9 1
A testDefaultMetadataConfiguration() 9 9 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
declare(strict_types = 1);
3
4
namespace Tests\Innmind\Neo4jBundle\DependencyInjection;
5
6
use Innmind\Neo4jBundle\DependencyInjection\InnmindNeo4jExtension;
7
use Innmind\Neo4j\DBAL\{
8
    Server,
9
    Authentication
10
};
11
use Symfony\Component\DependencyInjection\{
12
    ContainerBuilder,
13
    Reference
14
};
15
16
class InnmindNeo4jExtensionTest extends \PHPUnit_Framework_TestCase
17
{
18
    private $c;
19
    private $e;
20
21
    public function setUp()
22
    {
23
        $this->c = new ContainerBuilder;
24
        $this->e = new InnmindNeo4jExtension;
25
        $config = [
26
            'innmind_neo4j' => [
27
                'connection' => [
28
                    'scheme' => 'http',
29
                    'host' => 'docker',
30
                    'port' => 1337,
31
                    'timeout' => 42,
32
                    'user' => 'neo4j',
33
                    'password' => 'ci',
34
                ],
35
                'types' => ['foo', 'bar'],
36
                'persister' => 'another_service',
37
                'metadata_configuration' => 'config',
38
            ],
39
        ];
40
41
        $this->e->load($config, $this->c);
42
    }
43
44 View Code Duplication
    public function testPersister()
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...
45
    {
46
        $def = $this->c->getDefinition('innmind_neo4j.unit_of_work');
47
48
        $this->assertInstanceOf(Reference::class, $def->getArgument(5));
49
        $this->assertSame('another_service', (string) $def->getArgument(5));
50
    }
51
52
    public function testConnection()
53
    {
54
        $def = $this->c->getDefinition('innmind_neo4j.connection.server');
55
        $this->assertSame('http', $def->getArgument(0));
56
        $this->assertSame('docker', $def->getArgument(1));
57
        $this->assertSame(1337, $def->getArgument(2));
58
59
        $def = $this->c->getDefinition('innmind_neo4j.connection.authentication');
60
        $this->assertSame('neo4j', $def->getArgument(0));
61
        $this->assertSame('ci', $def->getArgument(1));
62
63
        $def = $this->c->getDefinition('innmind_neo4j.connection.transactions');
64
        $this->assertSame(42, $def->getArgument(2));
65
66
        $transport = $this->c->getDefinition('innmind_neo4j.connection.transport');
67
        $this->assertSame(42, $transport->getArgument(4));
68
    }
69
70
    public function testTypes()
71
    {
72
        $def = $this->c->getDefinition('innmind_neo4j.types');
73
        $calls = $def->getMethodCalls();
74
75
        $this->assertSame(2, count($calls));
76
        $this->assertSame('register', $calls[0][0]);
77
        $this->assertSame('foo', $calls[0][1][0]);
78
        $this->assertSame('register', $calls[1][0]);
79
        $this->assertSame('bar', $calls[1][1][0]);
80
    }
81
82 View Code Duplication
    public function testMetadataConfiguration()
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...
83
    {
84
        $def = $this->c->getDefinition('innmind_neo4j.metadata_builder');
85
86
        $this->assertInstanceOf(Reference::class, $def->getArgument(2));
87
        $this->assertSame('config', (string) $def->getArgument(2));
88
    }
89
90 View Code Duplication
    public function testDefaultPersister()
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...
91
    {
92
        $c = new ContainerBuilder;
93
        $this->e->load([], $c);
94
        $def = $c->getDefinition('innmind_neo4j.unit_of_work');
95
96
        $this->assertInstanceOf(Reference::class, $def->getArgument(5));
97
        $this->assertSame(
98
            'innmind_neo4j.persister.delegation',
99
            (string) $def->getArgument(5)
100
        );
101
    }
102
103
    public function testDefaultConnection()
104
    {
105
        $c = new ContainerBuilder;
106
        $this->e->load([], $c);
107
108
        $def = $this->c->getDefinition('innmind_neo4j.connection.server');
109
        $this->assertSame('http', $def->getArgument(0));
110
        $this->assertSame('docker', $def->getArgument(1));
111
        $this->assertSame(1337, $def->getArgument(2));
112
113
        $def = $this->c->getDefinition('innmind_neo4j.connection.authentication');
114
        $this->assertSame('neo4j', $def->getArgument(0));
115
        $this->assertSame('ci', $def->getArgument(1));
116
117
        $def = $c->getDefinition('innmind_neo4j.connection.transactions');
118
        $this->assertSame(60, $def->getArgument(2));
119
120
        $transport = $c->getDefinition('innmind_neo4j.connection.transport');
121
        $this->assertSame(60, $transport->getArgument(4));
122
    }
123
124
    public function testDefaultTypes()
125
    {
126
        $c = new ContainerBuilder;
127
        $this->e->load([], $c);
128
        $def = $c->getDefinition('innmind_neo4j.types');
129
        $calls = $def->getMethodCalls();
130
131
        $this->assertSame(0, count($calls));
132
    }
133
134 View Code Duplication
    public function testDefaultMetadataConfiguration()
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...
135
    {
136
        $c = new ContainerBuilder;
137
        $this->e->load([], $c);
138
        $def = $c->getDefinition('innmind_neo4j.metadata_builder');
139
140
        $this->assertInstanceOf(Reference::class, $def->getArgument(2));
141
        $this->assertSame('innmind_neo4j.metadata_builder.configuration', (string) $def->getArgument(2));
142
    }
143
}
144