@@ -32,22 +32,30 @@ protected function setUp(): void
32
32
33
33
public function testDispatchEventRespectOrder ()
34
34
{
35
- $ this ->evm = new ContainerAwareEventManager ($ this ->container , [' sub1 ' , [['foo ' ], 'list1 ' ], ' sub2 ' ]);
35
+ $ this ->evm = new ContainerAwareEventManager ($ this ->container , [[['foo ' ], 'list1 ' ], [[ ' foo ' ], ' list2 ' ] ]);
36
36
37
37
$ this ->container ->set ('list1 ' , $ listener1 = new MyListener ());
38
+ $ this ->container ->set ('list2 ' , $ listener2 = new MyListener ());
39
+
40
+ $ this ->assertSame ([$ listener1 , $ listener2 ], array_values ($ this ->evm ->getListeners ('foo ' )));
41
+ }
42
+
43
+ /**
44
+ * @group legacy
45
+ */
46
+ public function testDispatchEventRespectOrderWithSubscribers ()
47
+ {
48
+ $ this ->evm = new ContainerAwareEventManager ($ this ->container , ['sub1 ' , 'sub2 ' ]);
49
+
38
50
$ this ->container ->set ('sub1 ' , $ subscriber1 = new MySubscriber (['foo ' ]));
39
51
$ this ->container ->set ('sub2 ' , $ subscriber2 = new MySubscriber (['foo ' ]));
40
52
41
- $ this ->assertSame ([$ subscriber1 , $ listener1 , $ subscriber2 ], array_values ($ this ->evm ->getListeners ('foo ' )));
53
+ $ this ->expectDeprecation ('Since symfony/doctrine-bridge 6.3: Using Doctrine subscribers as services is deprecated, declare listeners instead ' );
54
+ $ this ->assertSame ([$ subscriber1 , $ subscriber2 ], array_values ($ this ->evm ->getListeners ('foo ' )));
42
55
}
43
56
44
57
public function testDispatchEvent ()
45
58
{
46
- $ this ->evm = new ContainerAwareEventManager ($ this ->container , ['lazy4 ' ]);
47
-
48
- $ this ->container ->set ('lazy4 ' , $ subscriber1 = new MySubscriber (['foo ' ]));
49
- $ this ->assertSame (0 , $ subscriber1 ->calledSubscribedEventsCount );
50
-
51
59
$ this ->container ->set ('lazy1 ' , $ listener1 = new MyListener ());
52
60
$ this ->evm ->addEventListener ('foo ' , 'lazy1 ' );
53
61
$ this ->evm ->addEventListener ('foo ' , $ listener2 = new MyListener ());
@@ -57,16 +65,10 @@ public function testDispatchEvent()
57
65
$ this ->container ->set ('lazy3 ' , $ listener5 = new MyListener ());
58
66
$ this ->evm ->addEventListener ('foo ' , $ listener5 = new MyListener ());
59
67
$ this ->evm ->addEventListener ('bar ' , $ listener5 );
60
- $ this ->evm ->addEventSubscriber ($ subscriber2 = new MySubscriber (['bar ' ]));
61
-
62
- $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
63
68
64
69
$ this ->evm ->dispatchEvent ('foo ' );
65
70
$ this ->evm ->dispatchEvent ('bar ' );
66
71
67
- $ this ->assertSame (1 , $ subscriber1 ->calledSubscribedEventsCount );
68
- $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
69
-
70
72
$ this ->assertSame (0 , $ listener1 ->calledByInvokeCount );
71
73
$ this ->assertSame (1 , $ listener1 ->calledByEventNameCount );
72
74
$ this ->assertSame (0 , $ listener2 ->calledByInvokeCount );
@@ -77,40 +79,57 @@ public function testDispatchEvent()
77
79
$ this ->assertSame (0 , $ listener4 ->calledByEventNameCount );
78
80
$ this ->assertSame (1 , $ listener5 ->calledByInvokeCount );
79
81
$ this ->assertSame (1 , $ listener5 ->calledByEventNameCount );
80
- $ this ->assertSame (0 , $ subscriber1 ->calledByInvokeCount );
81
- $ this ->assertSame (1 , $ subscriber1 ->calledByEventNameCount );
82
- $ this ->assertSame (1 , $ subscriber2 ->calledByInvokeCount );
83
- $ this ->assertSame (0 , $ subscriber2 ->calledByEventNameCount );
84
82
}
85
83
86
- public function testAddEventListenerAndSubscriberAfterDispatchEvent ()
84
+ /**
85
+ * @group legacy
86
+ */
87
+ public function testDispatchEventWithSubscribers ()
87
88
{
88
- $ this ->evm = new ContainerAwareEventManager ($ this ->container , ['lazy7 ' ]);
89
+ $ this ->evm = new ContainerAwareEventManager ($ this ->container , ['lazy4 ' ]);
89
90
90
- $ this ->container ->set ('lazy7 ' , $ subscriber1 = new MySubscriber (['foo ' ]));
91
+ $ this ->container ->set ('lazy4 ' , $ subscriber1 = new MySubscriber (['foo ' ]));
91
92
$ this ->assertSame (0 , $ subscriber1 ->calledSubscribedEventsCount );
92
93
93
94
$ this ->container ->set ('lazy1 ' , $ listener1 = new MyListener ());
95
+ $ this ->expectDeprecation ('Since symfony/doctrine-bridge 6.3: Using Doctrine subscribers as services is deprecated, declare listeners instead ' );
94
96
$ this ->evm ->addEventListener ('foo ' , 'lazy1 ' );
97
+ $ this ->evm ->addEventListener ('foo ' , $ listener2 = new MyListener ());
98
+ $ this ->evm ->addEventSubscriber ($ subscriber2 = new MySubscriber (['bar ' ]));
99
+
100
+ $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
101
+
102
+ $ this ->evm ->dispatchEvent ('foo ' );
103
+ $ this ->evm ->dispatchEvent ('bar ' );
104
+
95
105
$ this ->assertSame (1 , $ subscriber1 ->calledSubscribedEventsCount );
106
+ $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
107
+
108
+ $ this ->assertSame (0 , $ listener1 ->calledByInvokeCount );
109
+ $ this ->assertSame (1 , $ listener1 ->calledByEventNameCount );
110
+ $ this ->assertSame (0 , $ listener2 ->calledByInvokeCount );
111
+ $ this ->assertSame (1 , $ listener2 ->calledByEventNameCount );
112
+ $ this ->assertSame (0 , $ subscriber1 ->calledByInvokeCount );
113
+ $ this ->assertSame (1 , $ subscriber1 ->calledByEventNameCount );
114
+ $ this ->assertSame (1 , $ subscriber2 ->calledByInvokeCount );
115
+ $ this ->assertSame (0 , $ subscriber2 ->calledByEventNameCount );
116
+ }
96
117
118
+ public function testAddEventListenerAfterDispatchEvent ()
119
+ {
120
+ $ this ->container ->set ('lazy1 ' , $ listener1 = new MyListener ());
121
+ $ this ->evm ->addEventListener ('foo ' , 'lazy1 ' );
97
122
$ this ->evm ->addEventListener ('foo ' , $ listener2 = new MyListener ());
98
123
$ this ->container ->set ('lazy2 ' , $ listener3 = new MyListener ());
99
124
$ this ->evm ->addEventListener ('bar ' , 'lazy2 ' );
100
125
$ this ->evm ->addEventListener ('bar ' , $ listener4 = new MyListener ());
101
126
$ this ->container ->set ('lazy3 ' , $ listener5 = new MyListener ());
102
127
$ this ->evm ->addEventListener ('foo ' , $ listener5 = new MyListener ());
103
128
$ this ->evm ->addEventListener ('bar ' , $ listener5 );
104
- $ this ->evm ->addEventSubscriber ($ subscriber2 = new MySubscriber (['bar ' ]));
105
-
106
- $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
107
129
108
130
$ this ->evm ->dispatchEvent ('foo ' );
109
131
$ this ->evm ->dispatchEvent ('bar ' );
110
132
111
- $ this ->assertSame (1 , $ subscriber1 ->calledSubscribedEventsCount );
112
- $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
113
-
114
133
$ this ->container ->set ('lazy4 ' , $ listener6 = new MyListener ());
115
134
$ this ->evm ->addEventListener ('foo ' , 'lazy4 ' );
116
135
$ this ->evm ->addEventListener ('foo ' , $ listener7 = new MyListener ());
@@ -120,19 +139,10 @@ public function testAddEventListenerAndSubscriberAfterDispatchEvent()
120
139
$ this ->container ->set ('lazy6 ' , $ listener10 = new MyListener ());
121
140
$ this ->evm ->addEventListener ('foo ' , $ listener10 = new MyListener ());
122
141
$ this ->evm ->addEventListener ('bar ' , $ listener10 );
123
- $ this ->evm ->addEventSubscriber ($ subscriber3 = new MySubscriber (['bar ' ]));
124
-
125
- $ this ->assertSame (1 , $ subscriber1 ->calledSubscribedEventsCount );
126
- $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
127
- $ this ->assertSame (1 , $ subscriber3 ->calledSubscribedEventsCount );
128
142
129
143
$ this ->evm ->dispatchEvent ('foo ' );
130
144
$ this ->evm ->dispatchEvent ('bar ' );
131
145
132
- $ this ->assertSame (1 , $ subscriber1 ->calledSubscribedEventsCount );
133
- $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
134
- $ this ->assertSame (1 , $ subscriber3 ->calledSubscribedEventsCount );
135
-
136
146
$ this ->assertSame (0 , $ listener1 ->calledByInvokeCount );
137
147
$ this ->assertSame (2 , $ listener1 ->calledByEventNameCount );
138
148
$ this ->assertSame (0 , $ listener2 ->calledByInvokeCount );
@@ -143,10 +153,6 @@ public function testAddEventListenerAndSubscriberAfterDispatchEvent()
143
153
$ this ->assertSame (0 , $ listener4 ->calledByEventNameCount );
144
154
$ this ->assertSame (2 , $ listener5 ->calledByInvokeCount );
145
155
$ this ->assertSame (2 , $ listener5 ->calledByEventNameCount );
146
- $ this ->assertSame (0 , $ subscriber1 ->calledByInvokeCount );
147
- $ this ->assertSame (2 , $ subscriber1 ->calledByEventNameCount );
148
- $ this ->assertSame (2 , $ subscriber2 ->calledByInvokeCount );
149
- $ this ->assertSame (0 , $ subscriber2 ->calledByEventNameCount );
150
156
151
157
$ this ->assertSame (0 , $ listener6 ->calledByInvokeCount );
152
158
$ this ->assertSame (1 , $ listener6 ->calledByEventNameCount );
@@ -158,16 +164,81 @@ public function testAddEventListenerAndSubscriberAfterDispatchEvent()
158
164
$ this ->assertSame (0 , $ listener9 ->calledByEventNameCount );
159
165
$ this ->assertSame (1 , $ listener10 ->calledByInvokeCount );
160
166
$ this ->assertSame (1 , $ listener10 ->calledByEventNameCount );
167
+ }
168
+
169
+ /**
170
+ * @group legacy
171
+ */
172
+ public function testAddEventListenerAndSubscriberAfterDispatchEvent ()
173
+ {
174
+ $ this ->evm = new ContainerAwareEventManager ($ this ->container , ['lazy7 ' ]);
175
+
176
+ $ this ->container ->set ('lazy7 ' , $ subscriber1 = new MySubscriber (['foo ' ]));
177
+ $ this ->assertSame (0 , $ subscriber1 ->calledSubscribedEventsCount );
178
+
179
+ $ this ->container ->set ('lazy1 ' , $ listener1 = new MyListener ());
180
+ $ this ->expectDeprecation ('Since symfony/doctrine-bridge 6.3: Using Doctrine subscribers as services is deprecated, declare listeners instead ' );
181
+ $ this ->evm ->addEventListener ('foo ' , 'lazy1 ' );
182
+ $ this ->assertSame (1 , $ subscriber1 ->calledSubscribedEventsCount );
183
+
184
+ $ this ->evm ->addEventSubscriber ($ subscriber2 = new MySubscriber (['bar ' ]));
185
+
186
+ $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
187
+
188
+ $ this ->evm ->dispatchEvent ('foo ' );
189
+ $ this ->evm ->dispatchEvent ('bar ' );
190
+
191
+ $ this ->assertSame (1 , $ subscriber1 ->calledSubscribedEventsCount );
192
+ $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
193
+
194
+ $ this ->container ->set ('lazy6 ' , $ listener2 = new MyListener ());
195
+ $ this ->evm ->addEventListener ('foo ' , $ listener2 = new MyListener ());
196
+ $ this ->evm ->addEventListener ('bar ' , $ listener2 );
197
+ $ this ->evm ->addEventSubscriber ($ subscriber3 = new MySubscriber (['bar ' ]));
198
+
199
+ $ this ->assertSame (1 , $ subscriber1 ->calledSubscribedEventsCount );
200
+ $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
201
+ $ this ->assertSame (1 , $ subscriber3 ->calledSubscribedEventsCount );
202
+
203
+ $ this ->evm ->dispatchEvent ('foo ' );
204
+ $ this ->evm ->dispatchEvent ('bar ' );
205
+
206
+ $ this ->assertSame (1 , $ subscriber1 ->calledSubscribedEventsCount );
207
+ $ this ->assertSame (1 , $ subscriber2 ->calledSubscribedEventsCount );
208
+ $ this ->assertSame (1 , $ subscriber3 ->calledSubscribedEventsCount );
209
+
210
+ $ this ->assertSame (0 , $ listener1 ->calledByInvokeCount );
<
10000
code>211 + $ this ->assertSame (2 , $ listener1 ->calledByEventNameCount );
212
+ $ this ->assertSame (0 , $ subscriber1 ->calledByInvokeCount );
213
+ $ this ->assertSame (2 , $ subscriber1 ->calledByEventNameCount );
214
+ $ this ->assertSame (2 , $ subscriber2 ->calledByInvokeCount );
215
+ $ this ->assertSame (0 , $ subscriber2 ->calledByEventNameCount );
216
+
217
+ $ this ->assertSame (1 , $ listener2 ->calledByInvokeCount );
218
+ $ this ->assertSame (1 , $ listener2 ->calledByEventNameCount );
161
219
$ this ->assertSame (1 , $ subscriber3 ->calledByInvokeCount );
162
220
$ this ->assertSame (0 , $ subscriber3 ->calledByEventNameCount );
163
221
}
164
222
165
223
public function testGetListenersForEvent ()
224
+ {
225
+ $ this ->container ->set ('lazy ' , $ listener1 = new MyListener ());
226
+ $ this ->evm ->addEventListener ('foo ' , 'lazy ' );
227
+ $ this ->evm ->addEventListener ('foo ' , $ listener2 = new MyListener ());
228
+
229
+ $ this ->assertSame ([$ listener1 , $ listener2 ], array_values ($ this ->evm ->getListeners ('foo ' )));
230
+ }
231
+
232
+ /**
233
+ * @group legacy
234
+ */
235
+ public function testGetListenersForEventWhenSubscribersArePresent ()
166
236
{
167
237
$ this ->evm = new ContainerAwareEventManager ($ this ->container , ['lazy2 ' ]);
168
238
169
239
$ this ->container ->set ('lazy ' , $ listener1 = new MyListener ());
170
240
$ this ->container ->set ('lazy2 ' , $ subscriber1 = new MySubscriber (['foo ' ]));
241
+ $ this ->expectDeprecation ('Since symfony/doctrine-bridge 6.3: Using Doctrine subscribers as services is deprecated, declare listeners instead ' );
171
242
$ this ->evm ->addEventListener ('foo ' , 'lazy ' );
172
243
$ this ->evm ->addEventListener ('foo ' , $ listener2 = new MyListener ());
173
244
0 commit comments