1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2017 Gerrit Addiks. |
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
7
|
|
|
* @license GPL-3.0 |
8
|
|
|
* @author Gerrit Addiks <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Addiks\SymfonyGenerics\Events; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Addiks\SymfonyGenerics\Events\EntityInteractionEvent; |
15
|
|
|
use stdClass; |
16
|
|
|
use InvalidArgumentException; |
17
|
|
|
|
18
|
|
|
final class EntityInteractionEventTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var EntityInteractionEvent |
23
|
|
|
*/ |
24
|
|
|
private $event; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var stdClass |
28
|
|
|
*/ |
29
|
|
|
private $entity; |
30
|
|
|
|
31
|
|
|
public function setUp() |
32
|
|
|
{ |
33
|
|
|
$this->entity = $this->createMock(stdClass::class); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$this->event = new EntityInteractionEvent( |
36
|
|
|
"stdClass", |
37
|
|
|
"some-entity-id", |
38
|
|
|
$this->entity, |
39
|
|
|
"someMethod", |
40
|
|
|
['foo', 'bar'] |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @test |
46
|
|
|
*/ |
47
|
|
|
public function shouldRejectNonExistingClass() |
48
|
|
|
{ |
49
|
|
|
$this->expectException(InvalidArgumentException::class); |
50
|
|
|
|
51
|
|
|
new EntityInteractionEvent( |
52
|
|
|
"doesNotExist", |
53
|
|
|
"some-entity-id", |
54
|
|
|
$this->entity, |
55
|
|
|
"someMethod", |
56
|
|
|
['foo', 'bar'] |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @test |
62
|
|
|
*/ |
63
|
|
|
public function shouldRejectNonObjectEntity() |
64
|
|
|
{ |
65
|
|
|
$this->expectException(InvalidArgumentException::class); |
66
|
|
|
|
67
|
|
|
new EntityInteractionEvent( |
68
|
|
|
"stdClass", |
69
|
|
|
"some-entity-id", |
70
|
|
|
"entity", |
|
|
|
|
71
|
|
|
"someMethod", |
72
|
|
|
['foo', 'bar'] |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @test |
78
|
|
|
*/ |
79
|
|
|
public function shouldHaveEntityClass() |
80
|
|
|
{ |
81
|
|
|
$this->assertEquals("stdClass", $this->event->getEntityClass()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @test |
86
|
|
|
*/ |
87
|
|
|
public function shouldHaveEntityId() |
88
|
|
|
{ |
89
|
|
|
$this->assertEquals("some-entity-id", $this->event->getEntityId()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @test |
94
|
|
|
*/ |
95
|
|
|
public function shouldHaveEntity() |
96
|
|
|
{ |
97
|
|
|
$this->assertSame($this->entity, $this->event->getEntity()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @test |
102
|
|
|
*/ |
103
|
|
|
public function shouldHaveMethod() |
104
|
|
|
{ |
105
|
|
|
$this->assertEquals("someMethod", $this->event->getMethod()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @test |
110
|
|
|
*/ |
111
|
|
|
public function shouldHaveArguments() |
112
|
|
|
{ |
113
|
|
|
$this->assertEquals(['foo', 'bar'], $this->event->getArguments()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..