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(), |
|
|
|
|
37
|
|
|
$this->createObjectPersisterMock(), new \Exception(), |
|
|
|
|
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(), [], []); |
|
|
|
|
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(), [], []); |
|
|
|
|
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); |
|
|
|
|
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, []); |
|
|
|
|
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, [], []); |
|
|
|
|
84
|
|
|
|
85
|
|
|
$this->assertSame($expectedException, $event->getException()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testShouldAllowGetPreviouslySetException() |
89
|
|
|
{ |
90
|
|
|
$event = new OnExceptionEvent($this->createPagerMock(), $this->createObjectPersisterMock(), new \Exception(), [], []); |
|
|
|
|
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(), [], []); |
|
|
|
|
101
|
|
|
|
102
|
|
|
$this->assertFalse($event->isIgnored()); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testShouldAllowIgnoreException() |
106
|
|
|
{ |
107
|
|
|
$event = new OnExceptionEvent($this->createPagerMock(), $this->createObjectPersisterMock(), new \Exception(), [], []); |
|
|
|
|
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); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return PagerInterface|\PHPUnit_Framework_MockObject_MockObject |
124
|
|
|
*/ |
125
|
|
|
private function createPagerMock() |
126
|
|
|
{ |
127
|
|
|
return $this->getMock(PagerInterface::class, [], [], '', false); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
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.