Completed
Push — refonte ( 1e3261...545937 )
by Arnaud
02:13
created

ActionFactoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 119
Duplicated Lines 73.95 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 88
loc 119
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreate() 43 43 1
A testCreateWithMissingAction() 0 26 1
A testCreateWithWrongActionClass() 45 45 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 LAG\AdminBundle\Tests\Factory;
4
5
use LAG\AdminBundle\Configuration\ActionConfiguration;
6
use LAG\AdminBundle\Configuration\AdminConfiguration;
7
use LAG\AdminBundle\Exception\Exception;
8
use LAG\AdminBundle\Factory\ActionFactory;
9
use LAG\AdminBundle\Factory\ConfigurationFactory;
10
use LAG\AdminBundle\Resource\ResourceCollection;
11
use LAG\AdminBundle\Tests\AdminTestBase;
12
use LAG\AdminBundle\Tests\Fixtures\ActionFixture;
13
use LAG\AdminBundle\Tests\Fixtures\EntityFixture;
14
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
15
16
class ActionFactoryTest extends AdminTestBase
17
{
18 View Code Duplication
    public function testCreate()
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...
19
    {
20
        $resourceCollection = $this->getMockWithoutConstructor(ResourceCollection::class);
21
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
22
23
        $adminConfiguration = $this->getMockWithoutConstructor(AdminConfiguration::class);
24
        $adminConfiguration
25
            ->expects($this->atLeastOnce())
26
            ->method('getParameter')
27
            ->willReturnMap([
28
                ['actions', [
29
                    'list' => [],
30
                ]],
31
                ['entity', 'MyLittleTauntaun'],
32
                ['class', EntityFixture::class],
33
            ])
34
        ;
35
36
        $actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class);
37
        $actionConfiguration
38
            ->expects($this->once())
39
            ->method('getParameter')
40
            ->willReturnMap([
41
                ['class', ActionFixture::class],
42
            ])
43
        ;
44
45
        $configurationFactory = $this->getMockWithoutConstructor(ConfigurationFactory::class);
46
        $configurationFactory
47
            ->expects($this->once())
48
            ->method('createActionConfiguration')
49
            ->with('list',  [], 'tauntaun', $adminConfiguration)
50
            ->willReturn($actionConfiguration)
51
        ;
52
53
        $factory = new ActionFactory(
54
            $resourceCollection,
55
            $eventDispatcher,
56
            $configurationFactory
57
        );
58
59
        $factory->create('list', 'tauntaun', $adminConfiguration);
60
    }
61
62
    public function testCreateWithMissingAction()
63
    {
64
        $resourceCollection = $this->getMockWithoutConstructor(ResourceCollection::class);
65
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
66
        $configurationFactory = $this->getMockWithoutConstructor(ConfigurationFactory::class);
67
68
        $factory = new ActionFactory(
69
            $resourceCollection,
70
            $eventDispatcher,
71
            $configurationFactory
72
        );
73
74
        $adminConfiguration = $this->getMockWithoutConstructor(AdminConfiguration::class);
75
        $adminConfiguration
76
            ->expects($this->atLeastOnce())
77
            ->method('getParameter')
78
            ->willReturnMap([
79
                ['actions', []],
80
                ['entity', 'MyLittleTauntaun'],
81
            ])
82
        ;
83
84
        $this->assertExceptionRaised(Exception::class, function () use ($factory, $adminConfiguration) {
85
            $factory->create('list', 'tauntaun', $adminConfiguration);
86
        });
87
    }
88
89 View Code Duplication
    public function testCreateWithWrongActionClass()
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...
90
    {
91
        $resourceCollection = $this->getMockWithoutConstructor(ResourceCollection::class);
92
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
93
94
        $adminConfiguration = $this->getMockWithoutConstructor(AdminConfiguration::class);
95
        $adminConfiguration
96
            ->expects($this->atLeastOnce())
97
            ->method('getParameter')
98
            ->willReturnMap([
99
                ['actions', [
100
                    'list' => [],
101
                ]],
102
                ['entity', 'MyLittleTauntaun'],
103
                ['class', EntityFixture::class],
104
            ])
105
        ;
106
107
        $actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class);
108
        $actionConfiguration
109
            ->expects($this->once())
110
            ->method('getParameter')
111
            ->willReturnMap([
112
                ['class', EntityFixture::class],
113
            ])
114
        ;
115
116
        $configurationFactory = $this->getMockWithoutConstructor(ConfigurationFactory::class);
117
        $configurationFactory
118
            ->expects($this->once())
119
            ->method('createActionConfiguration')
120
            ->with('list',  [], 'tauntaun', $adminConfiguration)
121
            ->willReturn($actionConfiguration)
122
        ;
123
124
        $factory = new ActionFactory(
125
            $resourceCollection,
126
            $eventDispatcher,
127
            $configurationFactory
128
        );
129
130
        $this->assertExceptionRaised(Exception::class, function () use ($factory, $adminConfiguration) {
131
            $factory->create('list', 'tauntaun', $adminConfiguration);
132
        });
133
    }
134
}
135