| @@ 87-121 (lines=35) @@ | ||
| 84 | $pass->process($container); |
|
| 85 | } |
|
| 86 | ||
| 87 | public function testEventListenerCanBePrivate() |
|
| 88 | { |
|
| 89 | $container = $this->getContainer(); |
|
| 90 | ||
| 91 | $def = new Definition('Foo'); |
|
| 92 | $def->setPublic(false); |
|
| 93 | $def->addTag('jms_serializer.event_listener', ['event' => 'serializer.pre_serialize']); |
|
| 94 | ||
| 95 | $container->setDefinition('my_listener', $def); |
|
| 96 | ||
| 97 | $pass = new RegisterEventListenersAndSubscribersPass(); |
|
| 98 | $pass->process($container); |
|
| 99 | ||
| 100 | $dispatcher = $container->getDefinition('jms_serializer.event_dispatcher'); |
|
| 101 | $methodCalls = $dispatcher->getMethodCalls(); |
|
| 102 | ||
| 103 | $called = false; |
|
| 104 | foreach ($methodCalls as $call) { |
|
| 105 | if ($call[0] === 'setListeners') { |
|
| 106 | $called = true; |
|
| 107 | $this->assertEquals([ |
|
| 108 | 'serializer.pre_serialize' => [ |
|
| 109 | [ |
|
| 110 | ['my_listener', 'onserializerpreserialize'], |
|
| 111 | null, |
|
| 112 | null |
|
| 113 | ] |
|
| 114 | ]], $call[1][0]); |
|
| 115 | } |
|
| 116 | } |
|
| 117 | ||
| 118 | if (!$called) { |
|
| 119 | $this->fail("The method setListeners was not invoked on the jms_serializer.event_dispatcher"); |
|
| 120 | } |
|
| 121 | } |
|
| 122 | ||
| 123 | public function testEventListener() |
|
| 124 | { |
|
| @@ 253-287 (lines=35) @@ | ||
| 250 | $pass->process($container); |
|
| 251 | } |
|
| 252 | ||
| 253 | public function testEventSubscriberCanBePrivate() |
|
| 254 | { |
|
| 255 | $container = $this->getContainer(); |
|
| 256 | ||
| 257 | $def = new Definition(SimpleHandler::class); |
|
| 258 | $def->setPublic(false); |
|
| 259 | $def->addTag('jms_serializer.event_subscriber'); |
|
| 260 | ||
| 261 | $container->setDefinition('my_subscriber', $def); |
|
| 262 | ||
| 263 | $pass = new RegisterEventListenersAndSubscribersPass(); |
|
| 264 | $pass->process($container); |
|
| 265 | ||
| 266 | $dispatcher = $container->getDefinition('jms_serializer.event_dispatcher'); |
|
| 267 | $methodCalls = $dispatcher->getMethodCalls(); |
|
| 268 | ||
| 269 | $called = false; |
|
| 270 | foreach ($methodCalls as $call) { |
|
| 271 | if ($call[0] === 'setListeners') { |
|
| 272 | $called = true; |
|
| 273 | $this->assertEquals([ |
|
| 274 | 'the-event-name' => [ |
|
| 275 | [ |
|
| 276 | ['my_subscriber', 'onEventName'], |
|
| 277 | 'some-class', |
|
| 278 | 'json' |
|
| 279 | ] |
|
| 280 | ]], $call[1][0]); |
|
| 281 | } |
|
| 282 | } |
|
| 283 | ||
| 284 | if (!$called) { |
|
| 285 | $this->fail('The method setListeners was not invoked on the jms_serializer.event_dispatcher'); |
|
| 286 | } |
|
| 287 | } |
|
| 288 | } |
|
| 289 | ||
| 290 | ||