1
1
<?php
2
2
/**
3
- * ControllerTestCaseTest file
4
- *
5
- * Test Case for ControllerTestCase class
6
- *
7
3
* PHP 5
8
4
*
9
5
* CakePHP : Rapid Development Framework (http://cakephp.org)
13
9
* For full copyright and license information, please see the LICENSE.txt
14
10
* Redistributions of files must retain the above copyright notice.
15
11
*
16
- * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
17
- * @link http://cakephp.org CakePHP Project
18
- * @package Cake.Test.Case.Event
19
- * @since CakePHP v 2.1
20
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
12
+ * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
+ * @link http://cakephp.org CakePHP Project
14
+ * @package Cake.Test.Case.Event
15
+ * @since CakePHP v 2.1
16
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
21
17
*/
22
18
namespace Cake \Test \TestCase \Event ;
23
19
@@ -75,7 +71,7 @@ class CustomTestEventListerner extends EventTestListener implements EventListene
75
71
public function implementedEvents () {
76
72
return array (
77
73
'fake.event ' => 'listenerFunction ' ,
78
- 'another.event ' => array ('callable ' => 'secondListenerFunction ' , ' passParams ' => true ),
74
+ 'another.event ' => array ('callable ' => 'secondListenerFunction ' ),
79
75
'multiple.handlers ' => array (
80
76
array ('callable ' => 'listenerFunction ' ),
81
77
array ('callable ' => 'thirdListenerFunction ' )
@@ -109,12 +105,12 @@ public function testAttachListeners() {
109
105
$ manager = new EventManager ;
110
106
$ manager ->attach ('fakeFunction ' , 'fake.event ' );
111
107
$ expected = array (
112
- array ('callable ' => 'fakeFunction ' , ' passParams ' => false )
108
+ array ('callable ' => 'fakeFunction ' )
113
109
);
114
110
$ this ->assertEquals ($ expected , $ manager ->listeners ('fake.event ' ));
115
111
116
112
$ manager ->attach ('fakeFunction2 ' , 'fake.event ' );
117
- $ expected [] = array ('callable ' => 'fakeFunction2 ' , ' passParams ' => false );
113
+ $ expected [] = array ('callable ' => 'fakeFunction2 ' );
118
114
$ this ->assertEquals ($ expected , $ manager ->listeners ('fake.event ' ));
119
115
120
116
$ manager ->attach ('inQ5 ' , 'fake.event ' , array ('priority ' => 5 ));
@@ -123,9 +119,9 @@ public function testAttachListeners() {
123
119
124
120
$ expected = array_merge (
125
121
array (
126
- array ('callable ' => 'inQ1 ' , ' passParams ' => false ),
127
- array ('callable ' => 'inQ5 ' , ' passParams ' => false ),
128
- array ('callable ' => 'otherInQ5 ' , ' passParams ' => false )
122
+ array ('callable ' => 'inQ1 ' ),
123
+ array ('callable ' => 'inQ5 ' ),
124
+ array ('callable ' => 'otherInQ5 ' )
129
125
),
130
126
$ expected
131
127
);
@@ -141,15 +137,15 @@ public function testAttachMultipleEventKeys() {
141
137
$ manager = new EventManager ;
142
138
$ manager ->attach ('fakeFunction ' , 'fake.event ' );
143
139
$ manager ->attach ('fakeFunction2 ' , 'another.event ' );
144
- $ manager ->attach ('fakeFunction3 ' , 'another.event ' , array ('priority ' => 1 , ' passParams ' => true ));
140
+ $ manager ->attach ('fakeFunction3 ' , 'another.event ' , array ('priority ' => 1 ));
145
141
$ expected = array (
146
- array ('callable ' => 'fakeFunction ' , ' passParams ' => false )
142
+ array ('callable ' => 'fakeFunction ' )
147
143
);
148
144
$ this ->assertEquals ($ expected , $ manager ->listeners ('fake.event ' ));
149
145
150
146
$ expected = array (
151
- array ('callable ' => 'fakeFunction3 ' , ' passParams ' => true ),
152
- array ('callable ' => 'fakeFunction2 ' , ' passParams ' => false )
147
+ array ('callable ' => 'fakeFunction3 ' ),
148
+ array ('callable ' => 'fakeFunction2 ' )
153
149
);
154
150
$ this ->assertEquals ($ expected , $ manager ->listeners ('another.event ' ));
155
151
}
@@ -170,7 +166,7 @@ public function testDetach() {
170
166
171
167
$ manager ->detach (array ('AClass ' , 'anotherMethod ' ), 'another.event ' );
172
168
$ expected = array (
173
- array ('callable ' => 'fakeFunction ' , ' passParams ' => false )
169
+ array ('callable ' => 'fakeFunction ' )
174
170
);
175
171
$ this ->assertEquals ($ expected , $ manager ->listeners ('another.event ' ));
176
172
@@ -191,7 +187,7 @@ public function testDetachFromAll() {
191
187
192
188
$ manager ->detach (array ('AClass ' , 'aMethod ' ));
193
189
$ expected = array (
194
- array ('callable ' => 'fakeFunction ' , ' passParams ' => false )
190
+ array ('callable ' => 'fakeFunction ' )
195
191
);
196
192
$ this ->assertEquals ($ expected , $ manager ->listeners ('another.event ' ));
197
193
$ this ->assertEquals (array (), $ manager ->listeners ('fake.event ' ));
@@ -302,50 +298,45 @@ public function testDispatchPrioritized() {
302
298
$ this ->assertEquals ($ expected , $ listener ->callStack );
303
299
}
304
300
305
- /**
306
- * Tests event dispatching with passed params
307
- *
308
- * @return void
309
- */
310
- public function testDispatchPassingParams () {
311
- $ manager = new EventManager ;
312
- $ listener = $ this ->getMock (__NAMESPACE__ . '\EventTestListener ' );
313
- $ anotherListener = $ this ->getMock (__NAMESPACE__ . '\EventTestListener ' );
314
- $ manager ->attach (array ($ listener , 'listenerFunction ' ), 'fake.event ' );
315
- $ manager ->attach (array ($ anotherListener , 'secondListenerFunction ' ), 'fake.event ' , array ('passParams ' => true ));
316
- $ event = new Event ('fake.event ' , $ this , array ('some ' => 'data ' ));
317
-
318
- $ listener ->expects ($ this ->once ())->method ('listenerFunction ' )->with ($ event );
319
- $ anotherListener ->expects ($ this ->once ())->method ('secondListenerFunction ' )->with ('data ' );
320
- $ manager ->dispatch ($ event );
321
- }
322
-
323
301
/**
324
302
* Tests subscribing a listener object and firing the events it subscribed to
325
303
*
326
304
* @return void
327
305
*/
328
306
public function testAttachSubscriber () {
329
- $ manager = new EventManager ;
307
+ $ manager = new EventManager () ;
330
308
$ listener = $ this ->getMock (__NAMESPACE__ . '\CustomTestEventListerner ' , array ('secondListenerFunction ' ));
331
309
$ manager ->attach ($ listener );
332
- $ event = new Event ('fake.event ' );
333
310
311
+ $ event = new Event ('fake.event ' );
334
312
$ manager ->dispatch ($ event );
335
313
336
314
$ expected = array ('listenerFunction ' );
337
315
$ this ->assertEquals ($ expected , $ listener ->callStack );
338
316
339
- $ listener ->expects ($ this ->at (0 ))->method ('secondListenerFunction ' )->with ('data ' );
340
317
$ event = new Event ('another.event ' , $ this , array ('some ' => 'data ' ));
318
+ $ listener ->expects ($ this ->at (0 ))
319
+ ->method ('secondListenerFunction ' )
320
+ ->with ($ event , 'data ' );
341
321
$ manager ->dispatch ($ event );
322
+ }
342
323
324
+ /**
325
+ * Test implementedEvents binding multiple callbacks to the same event name.
326
+ *
327
+ * @return void
328
+ */
329
+ public function testAttachSubscriberMultiple () {
343
330
$ manager = new EventManager ;
344
331
$ listener = $ this ->getMock (__NAMESPACE__ . '\CustomTestEventListerner ' , array ('listenerFunction ' , 'thirdListenerFunction ' ));
345
332
$ manager ->attach ($ listener );
346
333
$ event = new Event ('multiple.handlers ' );
347
- $ listener ->expects ($ this ->once ())->method ('listenerFunction ' )->with ($ event );
348
- $ listener ->expects ($ this ->once ())->method ('thirdListenerFunction ' )->with ($ event );
334
+ $ listener ->expects ($ this ->once ())
335
+ ->method ('listenerFunction ' )
336
+ ->with ($ event );
337
+ $ listener ->expects ($ this ->once ())
338
+ ->method ('thirdListenerFunction ' )
339
+ ->with ($ event );
349
340
$ manager ->dispatch ($ event );
350
341
}
351
342
@@ -359,11 +350,11 @@ public function testDetachSubscriber() {
359
350
$ listener = $ this ->getMock (__NAMESPACE__ . '\CustomTestEventListerner ' , array ('secondListenerFunction ' ));
360
351
$ manager ->attach ($ listener );
361
352
$ expected = array (
362
- array ('callable ' => array ($ listener , 'secondListenerFunction ' ), ' passParams ' => true )
353
+ array ('callable ' => array ($ listener , 'secondListenerFunction ' ))
363
354
);
364
355
$ this ->assertEquals ($ expected , $ manager ->listeners ('another.event ' ));
365
356
$ expected = array (
366
- array ('callable ' => array ($ listener , 'listenerFunction ' ), ' passParams ' => false )
357
+ array ('callable ' => array ($ listener , 'listenerFunction ' ))
367
358
);
368
359
$ this ->assertEquals ($ expected , $ manager ->listeners ('fake.event ' ));
369
360
$ manager ->detach ($ listener );
0 commit comments