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

testShouldAllowGetOptionsSetInConstructor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace FOS\ElasticaBundle\Tests\Persister\Event;
3
4
use FOS\ElasticaBundle\Persister\Event\OnExceptionEvent;
5
use FOS\ElasticaBundle\Persister\Event\PersistEvent;
6
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
7
use FOS\ElasticaBundle\Provider\PagerInterface;
8
use Symfony\Component\EventDispatcher\Event;
9
10
final class OnExceptionEventTest extends \PHPUnit_Framework_TestCase
11
{
12
    public function testShouldBeSubClassOfEventClass()
13
    {
14
        $rc = new \ReflectionClass(OnExceptionEvent::class);
15
16
        $this->assertTrue($rc->isSubclassOf(Event::class));
17
    }
18
19
    public function testShouldImplementPersistEventInterface()
20
    {
21
        $rc = new \ReflectionClass(OnExceptionEvent::class);
22
23
        $this->assertTrue($rc->implementsInterface(PersistEvent::class));
24
    }
25
26
    public function testShouldFinal()
27
    {
28
        $rc = new \ReflectionClass(OnExceptionEvent::class);
29
30
        $this->assertTrue($rc->isFinal());
31
    }
32
33
    public function testCouldBeConstructedWithExpectedArguments()
34
    {
35
        new OnExceptionEvent(
36
            $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...ionEvent::__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...
37
            $this->createObjectPersisterMock(), new \Exception(),
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...ionEvent::__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...
38
            $objects = [],
39
            $options = []
40
        );
41
    }
42
43
    public function testShouldAllowGetPagerSetInConstructor()
44
    {
45
        $expectedPager = $this->createPagerMock();
46
47
        $event = new OnExceptionEvent($expectedPager, $this->createObjectPersisterMock(), new \Exception(), [], []);
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...ionEvent::__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...
48
49
        $this->assertSame($expectedPager, $event->getPager());
50
    }
51
52
    public function testShouldAllowGetObjectPersisterSetInConstructor()
53
    {
54
        $expectedPersister = $this->createObjectPersisterMock();
55
56
        $event = new OnExceptionEvent($this->createPagerMock(), $expectedPersister, new \Exception(), [], []);
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...ionEvent::__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...
57
58
        $this->assertSame($expectedPersister, $event->getObjectPersister());
59
    }
60
61
    public function testShouldAllowGetOptionsSetInConstructor()
62
    {
63
        $expectedOptions = ['foo' => 'fooVal', 'bar' => 'barVal'];
64
65
        $event = new OnExceptionEvent($this->createPagerMock(), $this->createObjectPersisterMock(), new \Exception(), [], $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...ionEvent::__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...ionEvent::__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
        $this->assertSame($expectedOptions, $event->getOptions());
68
    }
69
70 View Code Duplication
    public function testShouldAllowGetObjectsSetInConstructor()
71
    {
72
        $expectedObjects = [new \stdClass(), new \stdClass()];
73
74
        $event = new OnExceptionEvent($this->createPagerMock(), $this->createObjectPersisterMock(), new \Exception(), $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...ionEvent::__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...ionEvent::__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...
75
76
        $this->assertSame($expectedObjects, $event->getObjects());
77
    }
78
79
    public function testShouldAllowGetExceptionSetInConstructor()
80
    {
81
        $expectedException = new \Exception();
82
83
        $event = new OnExceptionEvent($this->createPagerMock(), $this->createObjectPersisterMock(), $expectedException, [], []);
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...ionEvent::__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...ionEvent::__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...
84
85
        $this->assertSame($expectedException, $event->getException());
86
    }
87
88
    public function testShouldAllowGetPreviouslySetException()
89
    {
90
        $event = new OnExceptionEvent($this->createPagerMock(), $this->createObjectPersisterMock(), new \Exception(), [], []);
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...ionEvent::__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...ionEvent::__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...
91
92
        $expectedException = new \Exception();
93
        $event->setException($expectedException);
94
95
        $this->assertSame($expectedException, $event->getException());
96
    }
97
98
    public function testShouldNotIgnoreExceptionByDefault()
99
    {
100
        $event = new OnExceptionEvent($this->createPagerMock(), $this->createObjectPersisterMock(), new \Exception(), [], []);
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...ionEvent::__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...ionEvent::__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...
101
102
        $this->assertFalse($event->isIgnored());
103
    }
104
105
    public function testShouldAllowIgnoreException()
106
    {
107
        $event = new OnExceptionEvent($this->createPagerMock(), $this->createObjectPersisterMock(), new \Exception(), [], []);
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...ionEvent::__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...ionEvent::__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...
108
109
        $event->setIgnore(true);
110
111
        $this->assertTrue($event->isIgnored());
112
    }
113
114
    /**
115
     * @return ObjectPersisterInterface|\PHPUnit_Framework_MockObject_MockObject
116
     */
117
    private function createObjectPersisterMock()
118
    {
119
        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...
120
    }
121
122
    /**
123
     * @return PagerInterface|\PHPUnit_Framework_MockObject_MockObject
124
     */
125
    private function createPagerMock()
126
    {
127
        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...
128
    }
129
}
130