@@ 123-159 (lines=37) @@ | ||
120 | } |
|
121 | } |
|
122 | ||
123 | public function testEventListener() |
|
124 | { |
|
125 | $container = $this->getContainer(); |
|
126 | ||
127 | $def = new Definition('Foo'); |
|
128 | $def->addTag('jms_serializer.event_listener', [ |
|
129 | 'event' => 'serializer.pre_serialize', |
|
130 | 'class' => 'Bar', |
|
131 | ]); |
|
132 | ||
133 | $container->setDefinition('my_listener', $def); |
|
134 | ||
135 | $pass = new RegisterEventListenersAndSubscribersPass(); |
|
136 | $pass->process($container); |
|
137 | ||
138 | $dispatcher = $container->getDefinition('jms_serializer.event_dispatcher'); |
|
139 | $methodCalls = $dispatcher->getMethodCalls(); |
|
140 | ||
141 | $called = false; |
|
142 | foreach ($methodCalls as $call) { |
|
143 | if ($call[0] === 'setListeners') { |
|
144 | $called = true; |
|
145 | $this->assertEquals([ |
|
146 | 'serializer.pre_serialize' => [ |
|
147 | [ |
|
148 | ['my_listener', 'onserializerpreserialize'], |
|
149 | 'bar', |
|
150 | null |
|
151 | ] |
|
152 | ]], $call[1][0]); |
|
153 | } |
|
154 | } |
|
155 | ||
156 | if (!$called) { |
|
157 | $this->fail("The method setListeners was not invoked on the jms_serializer.event_dispatcher"); |
|
158 | } |
|
159 | } |
|
160 | ||
161 | public function testEventListenerWithParams() |
|
162 | { |
|
@@ 161-199 (lines=39) @@ | ||
158 | } |
|
159 | } |
|
160 | ||
161 | public function testEventListenerWithParams() |
|
162 | { |
|
163 | $container = $this->getContainer(); |
|
164 | ||
165 | $container->setParameter('bar', 'Bar'); |
|
166 | ||
167 | $def = new Definition('Foo'); |
|
168 | $def->addTag('jms_serializer.event_listener', [ |
|
169 | 'event' => 'serializer.pre_serialize', |
|
170 | 'class' => '%bar%', |
|
171 | ]); |
|
172 | ||
173 | $container->setDefinition('my_listener', $def); |
|
174 | ||
175 | $pass = new RegisterEventListenersAndSubscribersPass(); |
|
176 | $pass->process($container); |
|
177 | ||
178 | $dispatcher = $container->getDefinition('jms_serializer.event_dispatcher'); |
|
179 | $methodCalls = $dispatcher->getMethodCalls(); |
|
180 | ||
181 | $called = false; |
|
182 | foreach ($methodCalls as $call) { |
|
183 | if ($call[0] === 'setListeners') { |
|
184 | $called = true; |
|
185 | $this->assertEquals([ |
|
186 | 'serializer.pre_serialize' => [ |
|
187 | [ |
|
188 | ['my_listener', 'onserializerpreserialize'], |
|
189 | 'bar', |
|
190 | null |
|
191 | ] |
|
192 | ]], $call[1][0]); |
|
193 | } |
|
194 | } |
|
195 | ||
196 | if (!$called) { |
|
197 | $this->fail("The method setListeners was not invoked on the jms_serializer.event_dispatcher"); |
|
198 | } |
|
199 | } |
|
200 | ||
201 | public function testEventSubscriber() |
|
202 | { |