1
|
|
|
<?php |
2
|
|
|
namespace FOS\ElasticaBundle\Tests\Persister\Event; |
3
|
|
|
|
4
|
|
|
use FOS\ElasticaBundle\Persister\Event\PostPersistEvent; |
5
|
|
|
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface; |
6
|
|
|
use FOS\ElasticaBundle\Provider\PagerInterface; |
7
|
|
|
use Symfony\Component\EventDispatcher\Event; |
8
|
|
|
|
9
|
|
|
final class PostPersistEventTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
public function testShouldBeSubClassOfEventClass() |
12
|
|
|
{ |
13
|
|
|
$rc = new \ReflectionClass(PostPersistEvent::class); |
14
|
|
|
|
15
|
|
|
$this->assertTrue($rc->isSubclassOf(Event::class)); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testShouldFinal() |
19
|
|
|
{ |
20
|
|
|
$rc = new \ReflectionClass(PostPersistEvent::class); |
21
|
|
|
|
22
|
|
|
$this->assertTrue($rc->isFinal()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testCouldBeConstructedWithPagerAndObjectPersisterAndOptions() |
26
|
|
|
{ |
27
|
|
|
new PostPersistEvent($this->createPagerMock(), $this->createObjectPersisterMock(), []); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testShouldAllowGetPagerSetInConstructor() |
31
|
|
|
{ |
32
|
|
|
$expectedPager = $this->createPagerMock(); |
33
|
|
|
|
34
|
|
|
$event = new PostPersistEvent($expectedPager, $this->createObjectPersisterMock(), []); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$this->assertSame($expectedPager, $event->getPager()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testShouldAllowGetObjectPersisterSetInConstructor() |
40
|
|
|
{ |
41
|
|
|
$expectedPersister = $this->createObjectPersisterMock(); |
42
|
|
|
|
43
|
|
|
$event = new PostPersistEvent($this->createPagerMock(), $expectedPersister, []); |
|
|
|
|
44
|
|
|
|
45
|
|
|
$this->assertSame($expectedPersister, $event->getObjectPersister()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testShouldAllowGetOptionsSetInConstructor() |
49
|
|
|
{ |
50
|
|
|
$expectedOptions = ['foo' => 'fooVal', 'bar' => 'barVal']; |
51
|
|
|
|
52
|
|
|
$event = new PostPersistEvent($this->createPagerMock(), $this->createObjectPersisterMock(), $expectedOptions); |
|
|
|
|
53
|
|
|
|
54
|
|
|
$this->assertSame($expectedOptions, $event->getOptions()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return ObjectPersisterInterface|\PHPUnit_Framework_MockObject_MockObject |
59
|
|
|
*/ |
60
|
|
|
private function createObjectPersisterMock() |
61
|
|
|
{ |
62
|
|
|
return $this->getMock(ObjectPersisterInterface::class, [], [], '', false); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return PagerInterface|\PHPUnit_Framework_MockObject_MockObject |
67
|
|
|
*/ |
68
|
|
|
private function createPagerMock() |
69
|
|
|
{ |
70
|
|
|
return $this->getMock(PagerInterface::class, [], [], '', false); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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.