@@ 78-112 (lines=35) @@ | ||
75 | $pass->process($container); |
|
76 | } |
|
77 | ||
78 | public function testEventListenerCanBePrivate() |
|
79 | { |
|
80 | $container = $this->getContainer(); |
|
81 | ||
82 | $def = new Definition('Foo'); |
|
83 | $def->setPublic(false); |
|
84 | $def->addTag('jms_serializer.event_listener', ['event' => 'serializer.pre_serialize']); |
|
85 | ||
86 | $container->setDefinition('my_listener', $def); |
|
87 | ||
88 | $pass = new RegisterEventListenersAndSubscribersPass(); |
|
89 | $pass->process($container); |
|
90 | ||
91 | $dispatcher = $container->getDefinition('jms_serializer.event_dispatcher'); |
|
92 | $methodCalls = $dispatcher->getMethodCalls(); |
|
93 | ||
94 | $called = false; |
|
95 | foreach ($methodCalls as $call) { |
|
96 | if ($call[0] === 'setListeners') { |
|
97 | $called = true; |
|
98 | $this->assertEquals([ |
|
99 | 'serializer.pre_serialize' => [ |
|
100 | [ |
|
101 | ['my_listener', 'onserializerpreserialize'], |
|
102 | null, |
|
103 | null |
|
104 | ] |
|
105 | ]], $call[1][0]); |
|
106 | } |
|
107 | } |
|
108 | ||
109 | if (!$called) { |
|
110 | $this->fail("The method setListeners was not invoked on the jms_serializer.event_dispatcher"); |
|
111 | } |
|
112 | } |
|
113 | ||
114 | public function testEventListener() |
|
115 | { |
|
@@ 244-278 (lines=35) @@ | ||
241 | $pass->process($container); |
|
242 | } |
|
243 | ||
244 | public function testEventSubscriberCanBePrivate() |
|
245 | { |
|
246 | $container = $this->getContainer(); |
|
247 | ||
248 | $def = new Definition(SimpleHandler::class); |
|
249 | $def->setPublic(false); |
|
250 | $def->addTag('jms_serializer.event_subscriber'); |
|
251 | ||
252 | $container->setDefinition('my_subscriber', $def); |
|
253 | ||
254 | $pass = new RegisterEventListenersAndSubscribersPass(); |
|
255 | $pass->process($container); |
|
256 | ||
257 | $dispatcher = $container->getDefinition('jms_serializer.event_dispatcher'); |
|
258 | $methodCalls = $dispatcher->getMethodCalls(); |
|
259 | ||
260 | $called = false; |
|
261 | foreach ($methodCalls as $call) { |
|
262 | if ($call[0] === 'setListeners') { |
|
263 | $called = true; |
|
264 | $this->assertEquals([ |
|
265 | 'the-event-name' => [ |
|
266 | [ |
|
267 | ['my_subscriber', 'onEventName'], |
|
268 | 'some-class', |
|
269 | 'json' |
|
270 | ] |
|
271 | ]], $call[1][0]); |
|
272 | } |
|
273 | } |
|
274 | ||
275 | if (!$called) { |
|
276 | $this->fail('The method setListeners was not invoked on the jms_serializer.event_dispatcher'); |
|
277 | } |
|
278 | } |
|
279 | } |
|
280 | ||
281 |