Completed
Push — master ( 0aa154...6fc129 )
by Maksim
05:50
created

testShouldImplementPersistEventInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
namespace FOS\ElasticaBundle\Tests\Persister\Event;
3
4
use FOS\ElasticaBundle\Persister\Event\PersistEvent;
5
use FOS\ElasticaBundle\Persister\Event\PrePersistEvent;
6
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
7
use FOS\ElasticaBundle\Provider\PagerInterface;
8
use Symfony\Component\EventDispatcher\Event;
9
10 View Code Duplication
final class PrePersistEventTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
11
{
12
    public function testShouldBeSubClassOfEventClass()
13
    {
14
        $rc = new \ReflectionClass(PrePersistEvent::class);
15
16
        $this->assertTrue($rc->isSubclassOf(Event::class));
17
    }
18
19
    public function testShouldImplementPersistEventInterface()
20
    {
21
        $rc = new \ReflectionClass(PrePersistEvent::class);
22
23
        $this->assertTrue($rc->implementsInterface(PersistEvent::class));
24
    }
25
26
    public function testShouldFinal()
27
    {
28
        $rc = new \ReflectionClass(PrePersistEvent::class);
29
30
        $this->assertTrue($rc->isFinal());
31
    }
32
33
    public function testCouldBeConstructedWithPagerAndObjectPersisterAndOptions()
34
    {
35
        new PrePersistEvent($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...istEvent::__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...istEvent::__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...
36
    }
37
38
    public function testShouldAllowGetPagerSetInConstructor()
39
    {
40
        $expectedPager = $this->createPagerMock();
41
42
        $event = new PrePersistEvent($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...istEvent::__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...
43
44
        $this->assertSame($expectedPager, $event->getPager());
45
    }
46
47
    public function testShouldAllowGetPreviouslySetPager()
48
    {
49
        $event = new PrePersistEvent($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...istEvent::__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...istEvent::__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...
50
51
        $expectedPager = $this->createPagerMock();
52
        $event->setPager($expectedPager);
53
54
        $this->assertSame($expectedPager, $event->getPager());
55
    }
56
57
    public function testShouldAllowGetObjectPersisterSetInConstructor()
58
    {
59
        $expectedPersister = $this->createObjectPersisterMock();
60
61
        $event = new PrePersistEvent($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...istEvent::__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...
62
63
        $this->assertSame($expectedPersister, $event->getObjectPersister());
64
    }
65
66
    public function testShouldAllowGetPreviouslySetObjectsPersister()
67
    {
68
        $event = new PrePersistEvent($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...istEvent::__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...istEvent::__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...
69
70
        $expectedPersister = $this->createObjectPersisterMock();
71
        $event->setObjectPersister($expectedPersister);
72
73
        $this->assertSame($expectedPersister, $event->getObjectPersister());
74
    }
75
76
    public function testShouldAllowGetOptionsSetInConstructor()
77
    {
78
        $expectedOptions = ['foo' => 'fooVal', 'bar' => 'barVal'];
79
80
        $event = new PrePersistEvent($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...istEvent::__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...istEvent::__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...
81
82
        $this->assertSame($expectedOptions, $event->getOptions());
83
    }
84
85
    public function testShouldAllowGetPreviouslySetOptions()
86
    {
87
        $event = new PrePersistEvent($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...istEvent::__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...istEvent::__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...
88
89
        $expectedOptions = ['foo' => 'fooNewVal', 'bar' => 'barnewVal'];
90
        $event->setOptions($expectedOptions);
91
92
        $this->assertSame($expectedOptions, $event->getOptions());
93
    }
94
95
    /**
96
     * @return ObjectPersisterInterface|\PHPUnit_Framework_MockObject_MockObject
97
     */
98
    private function createObjectPersisterMock()
99
    {
100
        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...
101
    }
102
103
    /**
104
     * @return PagerInterface|\PHPUnit_Framework_MockObject_MockObject
105
     */
106
    private function createPagerMock()
107
    {
108
        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...
109
    }
110
}
111