@@ -28,34 +28,80 @@ 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 ());
37
+ $ this ->container ->set ('lazy3 ' , $ listener5 = new MyListener ());
38
+ $ this ->evm ->addEventListener ('foo ' , $ listener5 = new MyListener ());
39
+ $ this ->evm ->addEventListener ('bar ' , $ listener5 );
34
40
35
41
$ this ->evm ->dispatchEvent ('foo ' );
36
-
37
- $ this ->assertTrue ($ listener1 ->called );
38
- $ this ->assertTrue ($ listener2 ->called );
42
+ $ this ->evm ->dispatchEvent ('bar ' );
43
+
44
+ $ this ->assertSame (0 , $ listener1 ->calledByInvokeCount );
45
+ $ this ->assertSame (1 , $ listener1 ->calledByEventNameCount );
46
+ $ this ->assertSame (0 , $ listener2 ->calledByInvokeCount );
47
+ $ this ->assertSame (1 , $ listener2 ->calledByEventNameCount );
48
+ $ this ->assertSame (1 , $ listener3 ->calledByInvokeCount );
49
+ $ this ->assertSame (0 , $ listener3 ->calledByEventNameCount );
50
+ $ this ->assertSame (1 , $ listener4 ->calledByInvokeCount );
51
+ $ this ->assertSame (0 , $ listener4 ->calledByEventNameCount );
52
+ $ this ->assertSame (1 , $ listener5 ->calledByInvokeCount );
53
+ $ this ->assertSame (1 , $ listener5 ->calledByEventNameCount );
39
54
}
40
55
41
56
public function testAddEventListenerAfterDispatchEvent ()
42
57
{
43
58
$ this ->container ->set ('lazy1 ' , $ listener1 = new MyListener ());
44
59
$ this ->evm ->addEventListener ('foo ' , 'lazy1 ' );
45
60
$ this ->evm ->addEventListener ('foo ' , $ listener2 = new MyListener ());
46
-
47
- $ this ->evm ->dispatchEvent ('foo ' );
48
-
49
61
$ this ->container ->set ('lazy2 ' , $ listener3 = new MyListener ());
50
- $ this ->evm ->addEventListener ('foo ' , 'lazy2 ' );
51
- $ this ->evm ->addEventListener ('foo ' , $ listener4 = new MyListener ());
62
+ $ this ->evm ->addEventListener ('bar ' , 'lazy2 ' );
63
+ $ this ->evm ->addEventListener ('bar ' , $ listener4 = new MyListener ());
64
+ $ this ->container ->set ('lazy3 ' , $ listener5 = new MyListener ());
65
+ $ this ->evm ->addEventListener ('foo ' , $ listener5 = new MyListener ());
66
+ $ this ->evm ->addEventListener ('bar ' , $ listener5 );
52
67
53
68
$ this ->evm ->dispatchEvent ('foo ' );
69
+ $ this ->evm ->dispatchEvent ('bar ' );
70
+
71
+ $ this ->container ->set ('lazy4 ' , $ listener6 = new MyListener ());
72
+ $ this ->evm ->addEventListener ('foo ' , 'lazy4 ' );
73
+ $ this ->evm ->addEventListener ('foo ' , $ listener7 = new MyListener ());
74
+ $ this ->container ->set ('lazy5 ' , $ listener8 = new MyListener ());
75
+ $ this ->evm ->addEventListener ('bar ' , 'lazy5 ' );
76
+ $ this ->evm ->addEventListener ('bar ' , $ listener9 = new MyListener ());
77
+ $ this ->container ->set ('lazy6 ' , $ listener10 = new MyListener ());
78
+ $ this ->evm ->addEventListener ('foo ' , $ listener10 = new MyListener ());
79
+ $ this ->evm ->addEventListener ('bar ' , $ listener10 );
54
80
55
- $ this ->assertTrue ($ listener1 ->called );
56
- $ this ->assertTrue ($ listener2 ->called );
57
- $ this ->assertTrue ($ listener3 ->called );
58
- $ this ->assertTrue ($ listener4 ->called );
81
+ $ this ->evm ->dispatchEvent ('foo ' );
82
+ $ this ->evm ->dispatchEvent ('bar ' );
83
+
84
+ $ this ->assertSame (0 , $ listener1 ->calledByInvokeCount );
85
+ $ this ->assertSame (2 , $ listener1 ->calledByEventNameCount );
86
+ $ this ->assertSame (0 , $ listener2 ->calledByInvokeCount );
87
+ $ this ->assertSame (2 , $ listener2 ->calledByEventNameCount );
88
+ $ this ->assertSame (2 , $ listener3 ->calledByInvokeCount );
89
+ $ this ->assertSame (0 , $ listener3 ->calledByEventNameCount );
90
+ $ this ->assertSame (2 , $ listener4 ->calledByInvokeCount );
91
+ $ this ->assertSame (0 , $ listener4 ->calledByEventNameCount );
92
+ $ this ->assertSame (2 , $ listener5 ->calledByInvokeCount );
93
+ $ this ->assertSame (2 , $ listener5 ->calledByEventNameCount );
94
+
95
+ $ this ->assertSame (0 , $ listener6 ->calledByInvokeCount );
96
+ $ this ->assertSame (1 , $ listener6 ->calledByEventNameCount );
97
+ $ this ->assertSame (0 , $ listener7 ->calledByInvokeCount );
98
+ $ this ->assertSame (1 , $ listener7 ->calledByEventNameCount );
99
+ $ this ->assertSame (1 , $ listener8 ->calledByInvokeCount );
100
+ $ this ->assertSame (0 , $ listener8 ->calledByEventNameCount );
101
+ $ this ->assertSame (1 , $ listener9 ->calledByInvokeCount );
102
+ $ this ->assertSame (0 , $ listener9 ->calledByEventNameCount );
103
+ $ this ->assertSame (1 , $ listener10 ->calledByInvokeCount );
104
+ $ this ->assertSame (1 , $ listener10 ->calledByEventNameCount );
59
105
}
60
106
61
107
public function testGetListenersForEvent ()
@@ -107,10 +153,16 @@ public function testRemoveEventListenerAfterDispatchEvent()
107
153
108
154
class MyListener
109
155
{
110
- public $ called = false ;
156
+ public $ calledByInvokeCount = 0 ;
157
+ public $ calledByEventNameCount = 0 ;
158
+
159
+ public function __invoke (): void
160
+ {
161
+ $ this ->calledByInvokeCount ++;
162
+ }
111
163
112
164
public function foo ()
113
165
{
114
- $ this ->called = true ;
166
+ $ this ->calledByEventNameCount ++ ;
115
167
}
116
168
}
0 commit comments