Completed
Push — master ( 4e4cd8...063296 )
by Maksim
16s
created

PreInsertObjectsEventTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 118
Duplicated Lines 6.78 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 2
dl 8
loc 118
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A testShouldBeSubClassOfEventClass() 0 6 1
A testShouldFinal() 0 6 1
A testCouldBeConstructedWithPagerAndObjectPersisterAndObjectsAndOptions() 0 9 1
A testShouldAllowGetPagerSetInConstructor() 0 8 1
A testShouldAllowGetPreviouslySetPager() 0 9 1
A testShouldAllowGetObjectPersisterSetInConstructor() 0 8 1
A testShouldAllowGetPreviouslySetObjectsPersister() 0 9 1
A testShouldAllowGetOptionsSetInConstructor() 0 8 1
A testShouldAllowGetPreviouslySetOptions() 0 9 1
A testShouldAllowGetObjectsSetInConstructor() 8 8 1
A testShouldAllowGetPreviouslySetObjects() 0 9 1
A createObjectPersisterMock() 0 4 1
A createPagerMock() 0 4 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
namespace FOS\ElasticaBundle\Tests\Persister\Event;
3
4
use FOS\ElasticaBundle\Persister\Event\PreInsertObjectsEvent;
5
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
6
use FOS\ElasticaBundle\Provider\PagerInterface;
7
use Symfony\Component\EventDispatcher\Event;
8
9
final class PreInsertObjectsEventTest extends \PHPUnit_Framework_TestCase
10
{
11
    public function testShouldBeSubClassOfEventClass()
12
    {
13
        $rc = new \ReflectionClass(PreInsertObjectsEvent::class);
14
15
        $this->assertTrue($rc->isSubclassOf(Event::class));
16
    }
17
18
    public function testShouldFinal()
19
    {
20
        $rc = new \ReflectionClass(PreInsertObjectsEvent::class);
21
22
        $this->assertTrue($rc->isFinal());
23
    }
24
25
    public function testCouldBeConstructedWithPagerAndObjectPersisterAndObjectsAndOptions()
26
    {
27
        new PreInsertObjectsEvent(
28
            $this->createPagerMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->createPagerMock() targeting FOS\ElasticaBundle\Tests...Test::createPagerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...rovider\PagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
29
            $this->createObjectPersisterMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->createObjectPersisterMock() targeting FOS\ElasticaBundle\Tests...teObjectPersisterMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...jectPersisterInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
30
            $objects = [],
31
            $options = []
32
        );
33
    }
34
35
    public function testShouldAllowGetPagerSetInConstructor()
36
    {
37
        $expectedPager = $this->createPagerMock();
38
39
        $event = new PreInsertObjectsEvent($expectedPager, $this->createObjectPersisterMock(), [], []);
0 ignored issues
show
Bug introduced by
It seems like $this->createObjectPersisterMock() targeting FOS\ElasticaBundle\Tests...teObjectPersisterMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...jectPersisterInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
40
41
        $this->assertSame($expectedPager, $event->getPager());
42
    }
43
44
    public function testShouldAllowGetPreviouslySetPager()
45
    {
46
        $event = new PreInsertObjectsEvent($this->createPagerMock(), $this->createObjectPersisterMock(), [], []);
0 ignored issues
show
Bug introduced by
It seems like $this->createPagerMock() targeting FOS\ElasticaBundle\Tests...Test::createPagerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...rovider\PagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->createObjectPersisterMock() targeting FOS\ElasticaBundle\Tests...teObjectPersisterMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...jectPersisterInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
47
48
        $expectedPager = $this->createPagerMock();
49
        $event->setPager($expectedPager);
50
51
        $this->assertSame($expectedPager, $event->getPager());
52
    }
53
54
    public function testShouldAllowGetObjectPersisterSetInConstructor()
55
    {
56
        $expectedPersister = $this->createObjectPersisterMock();
57
58
        $event = new PreInsertObjectsEvent($this->createPagerMock(), $expectedPersister, [], []);
0 ignored issues
show
Bug introduced by
It seems like $this->createPagerMock() targeting FOS\ElasticaBundle\Tests...Test::createPagerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...rovider\PagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
59
60
        $this->assertSame($expectedPersister, $event->getObjectPersister());
61
    }
62
63
    public function testShouldAllowGetPreviouslySetObjectsPersister()
64
    {
65
        $event = new PreInsertObjectsEvent($this->createPagerMock(), $this->createObjectPersisterMock(), [], []);
0 ignored issues
show
Bug introduced by
It seems like $this->createPagerMock() targeting FOS\ElasticaBundle\Tests...Test::createPagerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...rovider\PagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->createObjectPersisterMock() targeting FOS\ElasticaBundle\Tests...teObjectPersisterMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...jectPersisterInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
66
67
        $expectedPersister = $this->createObjectPersisterMock();
68
        $event->setObjectPersister($expectedPersister);
69
70
        $this->assertSame($expectedPersister, $event->getObjectPersister());
71
    }
72
73
    public function testShouldAllowGetOptionsSetInConstructor()
74
    {
75
        $expectedOptions = ['foo' => 'fooVal', 'bar' => 'barVal'];
76
77
        $event = new PreInsertObjectsEvent($this->createPagerMock(), $this->createObjectPersisterMock(), [], $expectedOptions);
0 ignored issues
show
Bug introduced by
It seems like $this->createPagerMock() targeting FOS\ElasticaBundle\Tests...Test::createPagerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...rovider\PagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->createObjectPersisterMock() targeting FOS\ElasticaBundle\Tests...teObjectPersisterMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...jectPersisterInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
78
79
        $this->assertSame($expectedOptions, $event->getOptions());
80
    }
81
82
    public function testShouldAllowGetPreviouslySetOptions()
83
    {
84
        $event = new PreInsertObjectsEvent($this->createPagerMock(), $this->createObjectPersisterMock(), [], ['foo' => 'fooVal', 'bar' => 'barVal']);
0 ignored issues
show
Bug introduced by
It seems like $this->createPagerMock() targeting FOS\ElasticaBundle\Tests...Test::createPagerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...rovider\PagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->createObjectPersisterMock() targeting FOS\ElasticaBundle\Tests...teObjectPersisterMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...jectPersisterInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
85
86
        $expectedOptions = ['foo' => 'fooNewVal', 'bar' => 'barnewVal'];
87
        $event->setOptions($expectedOptions);
88
89
        $this->assertSame($expectedOptions, $event->getOptions());
90
    }
91
92 View Code Duplication
    public function testShouldAllowGetObjectsSetInConstructor()
93
    {
94
        $expectedObjects = [new \stdClass(), new \stdClass()];
95
96
        $event = new PreInsertObjectsEvent($this->createPagerMock(), $this->createObjectPersisterMock(), $expectedObjects, []);
0 ignored issues
show
Bug introduced by
It seems like $this->createPagerMock() targeting FOS\ElasticaBundle\Tests...Test::createPagerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...rovider\PagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->createObjectPersisterMock() targeting FOS\ElasticaBundle\Tests...teObjectPersisterMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...jectPersisterInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
97
98
        $this->assertSame($expectedObjects, $event->getObjects());
99
    }
100
101
    public function testShouldAllowGetPreviouslySetObjects()
102
    {
103
        $event = new PreInsertObjectsEvent($this->createPagerMock(), $this->createObjectPersisterMock(), [new \stdClass(), new \stdClass()], []);
0 ignored issues
show
Bug introduced by
It seems like $this->createPagerMock() targeting FOS\ElasticaBundle\Tests...Test::createPagerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...rovider\PagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->createObjectPersisterMock() targeting FOS\ElasticaBundle\Tests...teObjectPersisterMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, FOS\ElasticaBundle\Persi...ctsEvent::__construct() does only seem to accept object<FOS\ElasticaBundl...jectPersisterInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
104
105
        $expectedObjects = [new \stdClass(), new \stdClass()];
106
        $event->setObjects($expectedObjects);
107
108
        $this->assertSame($expectedObjects, $event->getObjects());
109
    }
110
111
    /**
112
     * @return ObjectPersisterInterface|\PHPUnit_Framework_MockObject_MockObject
113
     */
114
    private function createObjectPersisterMock()
115
    {
116
        return $this->getMock(ObjectPersisterInterface::class, [], [], '', false);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
117
    }
118
119
    /**
120
     * @return PagerInterface|\PHPUnit_Framework_MockObject_MockObject
121
     */
122
    private function createPagerMock()
123
    {
124
        return $this->getMock(PagerInterface::class, [], [], '', false);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
125
    }
126
}
127