@@ -28,34 +28,52 @@ protected function setUp()
28
28
29
29
public function testDispatchEvent ()
30
30
{
31
- $ this ->container ->set ('lazy ' , $ listener1 = new MyListener ());
32
- $ this ->evm ->addEventListener ('foo ' , 'lazy ' );
31
+ $ this ->container ->set ('lazy1 ' , $ listener1 = new MyListener ());
32
+ $ this ->evm ->addEventListener ('foo ' , 'lazy1 ' );
33
33
$ this ->evm ->addEventListener ('foo ' , $ listener2 = new MyListener ());
34
+ $ this ->container ->set ('lazy2 ' , $ listener3 = new MyListener ());
35
+ $ this ->evm ->addEventListener ('bar ' , 'lazy2 ' );
36
+ $ this ->evm ->addEventListener ('bar ' , $ listener4 = new MyListener ());
34
37
35
38
$ this ->evm ->dispatchEvent ('foo ' );
39
+ $ this ->evm ->dispatchEvent ('bar ' );
36
40
37
- $ this ->assertTrue ($ listener1 ->called );
38
- $ this ->assertTrue ($ listener2 ->called );
41
+ $ this ->assertTrue ($ listener1 ->calledByEventName );
42
+ $ this ->assertTrue ($ listener2 ->calledByEventName );
43
+ $ this ->assertTrue ($ listener3 ->calledByInvoke );
44
+ $ this ->assertTrue ($ listener4 ->calledByInvoke );
39
45
}
40
46
41
47
public function testAddEventListenerAfterDispatchEvent ()
42
48
{
43
49
$ this ->container ->set ('lazy1 ' , $ listener1 = new MyListener ());
44
50
$ this ->evm ->addEventListener ('foo ' , 'lazy1 ' );
45
51
$ this ->evm ->addEventListener ('foo ' , $ listener2 = new MyListener ());
52
+ $ this ->container ->set ('lazy2 ' , $ listener3 = new MyListener ());
53
+ $ this ->evm ->addEventListener ('bar ' , 'lazy2 ' );
54
+ $ this ->evm ->addEventListener ('bar ' , $ listener4 = new MyListener ());
46
55
47
56
$ this ->evm ->dispatchEvent ('foo ' );
57
+ $ this ->evm ->dispatchEvent ('bar ' );
48
58
49
- $ this ->container ->set ('lazy2 ' , $ listener3 = new MyListener ());
50
- $ this ->evm ->addEventListener ('foo ' , 'lazy2 ' );
51
- $ this ->evm ->addEventListener ('foo ' , $ listener4 = new MyListener ());
59
+ $ this ->container ->set ('lazy3 ' , $ listener5 = new MyListener ());
60
+ $ this ->evm ->addEventListener ('foo ' , 'lazy3 ' );
61
+ $ this ->evm ->addEventListener ('foo ' , $ listener6 = new MyListener ());
62
+ $ this ->container ->set ('lazy4 ' , $ listener7 = new MyListener ());
63
+ $ this ->evm ->addEventListener ('bar ' , 'lazy4 ' );
64
+ $ this ->evm ->addEventListener ('bar ' , $ listener8 = new MyListener ());
52
65
53
66
$ this ->evm ->dispatchEvent ('foo ' );
54
-
55
- $ this ->assertTrue ($ listener1 ->called );
56
- $ this ->assertTrue ($ listener2 ->called );
57
- $ this ->assertTrue ($ listener3 ->called );
58
- $ this ->assertTrue ($ listener4 ->called );
67
+ $ this ->evm ->dispatchEvent ('bar ' );
68
+
69
+ $ this ->assertTrue ($ listener1 ->calledByEventName );
70
+ $ this ->assertTrue ($ listener2 ->calledByEventName );
71
+ $ this ->assertTrue ($ listener3 ->calledByInvoke );
72
+ $ this ->assertTrue ($ listener4 ->calledByInvoke );
73
+ $ this ->assertTrue ($ listener5 ->calledByEventName );
74
+ $ this ->assertTrue ($ listener6 ->calledByEventName );
75
+ $ this ->assertTrue ($ listener7 ->calledByInvoke );
76
+ $ this ->assertTrue ($ listener8 ->calledByInvoke );
59
77
}
60
78
61
79
public function testGetListenersForEvent ()
@@ -107,10 +125,17 @@ public function testRemoveEventListenerAfterDispatchEvent()
107
125
108
126
class MyListener
109
127
{
110
- public $ called = false ;
128
+ public $ calledByInvoke = false ;
129
+
130
+ public $ calledByEventName = false ;
131
+
132
+ public function __invoke (): void
133
+ {
134
+ $ this ->calledByInvoke = true ;
135
+ }
111
136
112
137
public function foo ()
113
138
{
114
- $ this ->called = true ;
139
+ $ this ->calledByEventName = true ;
115
140
}
116
141
}
0 commit comments