MigrationExtensionManagerTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 162
Duplicated Lines 85.19 %

Coupling/Cohesion

Components 2
Dependencies 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 2
cbo 12
dl 138
loc 162
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
B testValidExtension() 27 27 1
B testAnotherValidExtension() 27 27 1
A testValidExtensionWithDependencies() 19 19 1
A testAnotherValidExtensionWithDependencies() 19 19 1
A testExtensionDependedToOtherExtension() 0 14 1
A testExtensionWithNoAwareInterface() 16 16 1
A testAnotherExtensionWithNoAwareInterface() 15 15 1
A testExtensionWithInvalidAwareInterface() 15 15 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 RDV\Bundle\MigrationBundle\Tests\Unit\Migration;
4
5
use Doctrine\DBAL\Platforms\MySqlPlatform;
6
use RDV\Bundle\MigrationBundle\Migration\MigrationExtensionManager;
7
use RDV\Bundle\MigrationBundle\Tests\Unit\Migration\Fixtures\Extension\InvalidAwareInterfaceExtension;
8
use RDV\Bundle\MigrationBundle\Tests\Unit\Migration\Fixtures\Extension\TestExtension;
9
use RDV\Bundle\MigrationBundle\Tests\Unit\Migration\Fixtures\Extension\AnotherTestExtension;
10
use RDV\Bundle\MigrationBundle\Tests\Unit\Migration\Fixtures\Extension\TestExtensionDepended;
11
use RDV\Bundle\MigrationBundle\Tests\Unit\Migration\Fixtures\MigrationWithTestExtension;
12
use RDV\Bundle\MigrationBundle\Tests\Unit\Migration\Fixtures\Extension\NoAwareInterfaceExtension;
13
use RDV\Bundle\MigrationBundle\Tests\Unit\Migration\Fixtures\Extension\AnotherNoAwareInterfaceExtension;
14
use RDV\Bundle\MigrationBundle\Tests\Unit\Migration\Fixtures\MigrationWithTestExtensionDepended;
15
use RDV\Bundle\MigrationBundle\Tools\DbIdentifierNameGenerator;
16
17
class MigrationExtensionManagerTest extends \PHPUnit_Framework_TestCase
18
{
19 View Code Duplication
    public function testValidExtension()
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...
20
    {
21
        $migration = new MigrationWithTestExtension();
22
        $extension = new TestExtension();
23
        $platform = new MySqlPlatform();
24
        $nameGenerator = new DbIdentifierNameGenerator();
25
26
        $manager = new MigrationExtensionManager();
27
        $manager->addExtension('test', $extension);
28
        $manager->applyExtensions($migration);
29
30
        $this->assertSame($extension, $migration->getTestExtension());
31
        $this->assertNull($extension->getDatabasePlatform());
32
        $this->assertNull($extension->getNameGenerator());
33
34
        $manager->setDatabasePlatform($platform);
35
        $this->assertSame($platform, $extension->getDatabasePlatform());
36
37
        $manager->setNameGenerator($nameGenerator);
38
        $this->assertSame($nameGenerator, $extension->getNameGenerator());
39
40
        $this->assertNull($migration->getDatabasePlatform());
41
        $this->assertNull($migration->getNameGenerator());
42
        $manager->applyExtensions($migration);
43
        $this->assertSame($platform, $migration->getDatabasePlatform());
44
        $this->assertSame($nameGenerator, $migration->getNameGenerator());
45
    }
46
47 View Code Duplication
    public function testAnotherValidExtension()
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...
48
    {
49
        $migration = new MigrationWithTestExtension();
50
        $extension = new AnotherTestExtension();
51
        $platform = new MySqlPlatform();
52
        $nameGenerator = new DbIdentifierNameGenerator();
53
54
        $manager = new MigrationExtensionManager();
55
        $manager->addExtension('test', $extension);
56
        $manager->applyExtensions($migration);
57
58
        $this->assertSame($extension, $migration->getTestExtension());
59
        $this->assertNull($extension->getDatabasePlatform());
60
        $this->assertNull($extension->getNameGenerator());
61
62
        $manager->setDatabasePlatform($platform);
63
        $this->assertSame($platform, $extension->getDatabasePlatform());
64
65
        $manager->setNameGenerator($nameGenerator);
66
        $this->assertSame($nameGenerator, $extension->getNameGenerator());
67
68
        $this->assertNull($migration->getDatabasePlatform());
69
        $this->assertNull($migration->getNameGenerator());
70
        $manager->applyExtensions($migration);
71
        $this->assertSame($platform, $migration->getDatabasePlatform());
72
        $this->assertSame($nameGenerator, $migration->getNameGenerator());
73
    }
74
75 View Code Duplication
    public function testValidExtensionWithDependencies()
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...
76
    {
77
        $migration = new MigrationWithTestExtension();
78
        $extension = new TestExtension();
79
        $platform = new MySqlPlatform();
80
        $nameGenerator = new DbIdentifierNameGenerator();
81
82
        $manager = new MigrationExtensionManager();
83
        $manager->setDatabasePlatform($platform);
84
        $manager->setNameGenerator($nameGenerator);
85
        $manager->addExtension('test', $extension);
86
        $manager->applyExtensions($migration);
87
88
        $this->assertSame($extension, $migration->getTestExtension());
89
        $this->assertSame($platform, $extension->getDatabasePlatform());
90
        $this->assertSame($nameGenerator, $extension->getNameGenerator());
91
        $this->assertSame($platform, $migration->getDatabasePlatform());
92
        $this->assertSame($nameGenerator, $migration->getNameGenerator());
93
    }
94
95 View Code Duplication
    public function testAnotherValidExtensionWithDependencies()
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...
96
    {
97
        $migration = new MigrationWithTestExtension();
98
        $extension = new AnotherTestExtension();
99
        $platform = new MySqlPlatform();
100
        $nameGenerator = new DbIdentifierNameGenerator();
101
102
        $manager = new MigrationExtensionManager();
103
        $manager->setDatabasePlatform($platform);
104
        $manager->setNameGenerator($nameGenerator);
105
        $manager->addExtension('test', $extension);
106
        $manager->applyExtensions($migration);
107
108
        $this->assertSame($extension, $migration->getTestExtension());
109
        $this->assertSame($platform, $extension->getDatabasePlatform());
110
        $this->assertSame($nameGenerator, $extension->getNameGenerator());
111
        $this->assertSame($platform, $migration->getDatabasePlatform());
112
        $this->assertSame($nameGenerator, $migration->getNameGenerator());
113
    }
114
115
    public function testExtensionDependedToOtherExtension()
116
    {
117
        $migration = new MigrationWithTestExtensionDepended();
118
        $otherExtension = new TestExtension();
119
        $extension = new TestExtensionDepended();
120
121
        $manager = new MigrationExtensionManager();
122
        $manager->addExtension('test', $extension);
123
        $manager->addExtension('other', $otherExtension);
124
        $manager->applyExtensions($migration);
125
126
        $this->assertSame($extension, $migration->getTestExtensionDepended());
127
        $this->assertSame($otherExtension, $migration->getTestExtensionDepended()->getTestExtension());
128
    }
129
130 View Code Duplication
    public function testExtensionWithNoAwareInterface()
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...
131
    {
132
        $dir = 'RDV\Bundle\MigrationBundle\Tests\Unit\Migration\Fixtures\Extension';
133
        $this->setExpectedException(
134
            '\RuntimeException',
135
            sprintf(
136
                'The extension aware interface for "%s\NoAwareInterfaceExtension" was not found. '
137
                . 'Make sure that "%s\NoAwareInterfaceExtensionAwareInterface" interface is declared.',
138
                $dir,
139
                $dir
140
            )
141
        );
142
143
        $manager = new MigrationExtensionManager();
144
        $manager->addExtension('test', new NoAwareInterfaceExtension());
145
    }
146
147 View Code Duplication
    public function testAnotherExtensionWithNoAwareInterface()
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...
148
    {
149
        $dir = 'RDV\Bundle\MigrationBundle\Tests\Unit\Migration\Fixtures\Extension';
150
        $this->setExpectedException(
151
            '\RuntimeException',
152
            sprintf(
153
                'The extension aware interface for neither "%s\AnotherNoAwareInterfaceExtension"'
154
                . ' not one of its parent classes was not found.',
155
                $dir
156
            )
157
        );
158
159
        $manager = new MigrationExtensionManager();
160
        $manager->addExtension('test', new AnotherNoAwareInterfaceExtension());
161
    }
162
163 View Code Duplication
    public function testExtensionWithInvalidAwareInterface()
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...
164
    {
165
        $dir = 'RDV\Bundle\MigrationBundle\Tests\Unit\Migration\Fixtures\Extension';
166
        $this->setExpectedException(
167
            '\RuntimeException',
168
            sprintf(
169
                'The method "%s\InvalidAwareInterfaceExtensionAwareInterface::setInvalidAwareInterfaceExtension"'
170
                . ' was not found.',
171
                $dir
172
            )
173
        );
174
175
        $manager = new MigrationExtensionManager();
176
        $manager->addExtension('test', new InvalidAwareInterfaceExtension());
177
    }
178
}
179