@@ -56,6 +56,23 @@ public function testHasListeners()
56
56
$ this ->assertTrue ($ tdispatcher ->hasListeners ('foo ' ));
57
57
}
58
58
59
+ public function testGetListenerPriority ()
60
+ {
61
+ $ dispatcher = new EventDispatcher ();
62
+ $ tdispatcher = new TraceableEventDispatcher ($ dispatcher , new Stopwatch ());
63
+
64
+ $ tdispatcher ->addListener ('foo ' , function () {}, 123 );
65
+
66
+ $ listeners = $ dispatcher ->getListeners ('foo ' );
67
+ $ this ->assertSame (123 , $ tdispatcher ->getListenerPriority ('foo ' , $ listeners [0 ]));
68
+
69
+ // Verify that priority is preserved when listener is removed and re-added
70
+ // in preProcess() and postProcess().
71
+ $ tdispatcher ->dispatch ('foo ' , new Event ());
72
+ $ listeners = $ dispatcher ->getListeners ('foo ' );
73
+ $ this ->assertSame (123 , $ tdispatcher ->getListenerPriority ('foo ' , $ listeners [0 ]));
74
+ }
75
+
59
76
public function testAddRemoveSubscriber ()
60
77
{
61
78
$ dispatcher = new EventDispatcher ();
@@ -138,12 +155,12 @@ public function testDispatchCallListeners()
138
155
139
156
$ dispatcher = new EventDispatcher ();
140
157
$ tdispatcher = new TraceableEventDispatcher ($ dispatcher , new Stopwatch ());
141
- $ tdispatcher ->addListener ('foo ' , $ listener1 = function () use (&$ called ) { $ called [] = 'foo1 ' ; });
142
- $ tdispatcher ->addListener ('foo ' , $ listener2 = function () use (&$ called ) { $ called [] = 'foo2 ' ; });
158
+ $ tdispatcher ->addListener ('foo ' , $ listener1 = function () use (&$ called ) { $ called [] = 'foo1 ' ; }, 10 );
159
+ $ tdispatcher ->addListener ('foo ' , $ listener2 = function () use (&$ called ) { $ called [] = 'foo2 ' ; }, 20 );
143
160
144
161
$ tdispatcher ->dispatch ('foo ' );
145
162
146
- $ this ->assertEquals (array ('foo1 ' , 'foo2 ' ), $ called );
163
+ $ this ->assertSame (array ('foo2 ' , 'foo1 ' ), $ called );
147
164
}
148
165
149
166
public function testDispatchNested ()
0 commit comments