Completed
Pull Request — 5.0 (#2091)
by Jeroen
10:56
created

NodeIndexUpdateEventListenerTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 135
Duplicated Lines 52.59 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 71
loc 135
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testUpdateOfChildPageWithStructuredNodeParent() 25 25 1
A testUpdateOfChildPageWithStructuredNodeParentAndOfflineParent() 0 31 1
A testUpdateOfChildPageWithOfflineParent() 23 23 1
A testUpdateOfChildPageWithOnlineParent() 23 23 1
A getContainer() 0 13 1
A getSearchConfiguration() 0 11 2

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 Kunstmaan\NodeSearchBundle\Tests\EventListener;
4
5
use Kunstmaan\NodeBundle\Entity\Node;
6
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
7
use Kunstmaan\NodeBundle\Entity\StructureNode;
8
use Kunstmaan\NodeBundle\Event\NodeEvent;
9
use Kunstmaan\NodeSearchBundle\Configuration\NodePagesConfiguration;
10
use Kunstmaan\NodeSearchBundle\EventListener\NodeIndexUpdateEventListener;
11
12
class NodeIndexUpdateEventListenerTest extends \PHPUnit_Framework_TestCase
13
{
14 View Code Duplication
    public function testUpdateOfChildPageWithStructuredNodeParent()
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...
15
    {
16
        $parentNodeTranslation = $this->createMock(StructureNode::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
17
        $parentNodeTranslation->method('isOnline')->willReturn(false);
18
19
        $parentNode = $this->createMock(Node::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
20
        $parentNode->method('getNodeTranslation')->willReturn($parentNodeTranslation);
21
22
        $node = $this->createMock(Node::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
        $node->method('getParents')->willReturn([
24
            $parentNode
25
        ]);
26
27
        $nodeTranslation = $this->createMock(NodeTranslation::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
        $nodeTranslation->method('getId')->willReturn(1);
29
        $nodeTranslation->method('getLang')->willReturn('nl');
30
        $nodeTranslation->method('getNode')->willReturn($node);
31
32
        $nodeEvent = $this->getMockBuilder(NodeEvent::class)->disableOriginalConstructor()->getMock();
33
34
        $nodeEvent->method('getNodeTranslation')->willReturn($nodeTranslation);
35
36
        $listener = new NodeIndexUpdateEventListener($this->getContainer($this->getSearchConfiguration(true)));
37
        $listener->onPostPersist($nodeEvent);
38
    }
39
40
    public function testUpdateOfChildPageWithStructuredNodeParentAndOfflineParent()
41
    {
42
        $parentNodeTranslation = $this->createMock(StructureNode::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
        $parentNodeTranslation->method('isOnline')->willReturn(false);
44
45
        $parentNodeTranslation2 = $this->createMock(NodeTranslation::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
        $parentNodeTranslation2->method('isOnline')->willReturn(false);
47
48
        $parentNode1 = $this->createMock(Node::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
        $parentNode1->method('getNodeTranslation')->willReturn($parentNodeTranslation);
50
        $parentNode2 = $this->createMock(Node::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
        $parentNode2->method('getNodeTranslation')->willReturn($parentNodeTranslation2);
52
53
        $node = $this->createMock(Node::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
        $node->method('getParents')->willReturn([
55
            $parentNode1,
56
            $parentNode2,
57
        ]);
58
59
        $nodeTranslation = $this->createMock(NodeTranslation::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
        $nodeTranslation->method('getId')->willReturn(1);
61
        $nodeTranslation->method('getLang')->willReturn('nl');
62
        $nodeTranslation->method('getNode')->willReturn($node);
63
64
        $nodeEvent = $this->getMockBuilder(NodeEvent::class)->disableOriginalConstructor()->getMock();
65
66
        $nodeEvent->method('getNodeTranslation')->willReturn($nodeTranslation);
67
68
        $listener = new NodeIndexUpdateEventListener($this->getContainer($this->getSearchConfiguration(false)));
69
        $listener->onPostPersist($nodeEvent);
70
    }
71
72 View Code Duplication
    public function testUpdateOfChildPageWithOfflineParent()
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...
73
    {
74
        $parentNodeTranslation = $this->createMock(NodeTranslation::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
        $parentNodeTranslation->method('isOnline')->willReturn(false);
76
77
        $parentNode = $this->createMock(Node::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
        $parentNode->method('getNodeTranslation')->willReturn($parentNodeTranslation);
79
80
        $node = $this->createMock(Node::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
81
        $node->method('getParents')->willReturn([$parentNode]);
82
83
        $nodeTranslation = $this->createMock(NodeTranslation::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
        $nodeTranslation->method('getId')->willReturn(1);
85
        $nodeTranslation->method('getLang')->willReturn('nl');
86
        $nodeTranslation->method('getNode')->willReturn($node);
87
88
        $nodeEvent = $this->getMockBuilder(NodeEvent::class)->disableOriginalConstructor()->getMock();
89
90
        $nodeEvent->method('getNodeTranslation')->willReturn($nodeTranslation);
91
92
        $listener = new NodeIndexUpdateEventListener($this->getContainer($this->getSearchConfiguration(false)));
93
        $listener->onPostPersist($nodeEvent);
94
    }
95
96
97 View Code Duplication
    public function testUpdateOfChildPageWithOnlineParent()
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...
98
    {
99
        $parentNodeTranslation = $this->createMock(NodeTranslation::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
        $parentNodeTranslation->method('isOnline')->willReturn(true);
101
102
        $parentNode = $this->createMock(Node::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
103
        $parentNode->method('getNodeTranslation')->willReturn($parentNodeTranslation);
104
105
        $node = $this->createMock(Node::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
106
        $node->method('getParents')->willReturn([$parentNode]);
107
108
        $nodeTranslation = $this->createMock(NodeTranslation::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
109
        $nodeTranslation->method('getId')->willReturn(1);
110
        $nodeTranslation->method('getLang')->willReturn('nl');
111
        $nodeTranslation->method('getNode')->willReturn($node);
112
113
        $nodeEvent = $this->getMockBuilder(NodeEvent::class)->disableOriginalConstructor()->getMock();
114
115
        $nodeEvent->method('getNodeTranslation')->willReturn($nodeTranslation);
116
117
        $listener = new NodeIndexUpdateEventListener($this->getContainer($this->getSearchConfiguration(true)));
118
        $listener->onPostPersist($nodeEvent);
119
    }
120
121
    private function getContainer($searchConfigMock)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
122
    {
123
        $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
124
125
        $container
126
            ->expects($this->any())
127
            ->method('get')
128
            ->with($this->equalTo('kunstmaan_node_search.search_configuration.node'))
129
            ->willReturn($searchConfigMock)
130
        ;
131
132
        return $container;
133
    }
134
135
    private function getSearchConfiguration($expectCall)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
136
    {
137
        $searchConfig = $this->createMock(NodePagesConfiguration::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Kunstmaan\NodeSea...pdateEventListenerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
138
        $searchConfig
139
            ->expects($expectCall ? $this->once() : $this->never())
140
            ->method('indexNodeTranslation')
141
            ->willReturn(null)
142
        ;
143
144
        return $searchConfig;
145
    }
146
}
147