@@ -31,6 +31,9 @@ public function testEventSubscriberWithoutInterface()
31
31
);
32
32
33
33
$ definition = $ this ->getMock ('Symfony\Component\DependencyInjection\Definition ' );
34
+ $ definition ->expects ($ this ->atLeastOnce ())
35
+ ->method ('isPublic ' )
36
+ ->will ($ this ->returnValue (true ));
34
37
$ definition ->expects ($ this ->atLeastOnce ())
35
38
->method ('getClass ' )
36
39
->will ($ this ->returnValue ('stdClass ' ));
@@ -60,6 +63,9 @@ public function testValidEventSubscriber()
60
63
);
61
64
62
65
$ definition = $ this ->getMock ('Symfony\Component\DependencyInjection\Definition ' );
66
+ $ definition ->expects ($ this ->atLeastOnce ())
67
+ ->method ('isPublic ' )
68
+ ->will ($ this ->returnValue (true ));
63
69
$ definition ->expects ($ this ->atLeastOnce ())
64
70
->method ('getClass ' )
65
71
->will ($ this ->returnValue ('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\SubscriberService ' ));
@@ -81,6 +87,34 @@ public function testValidEventSubscriber()
81
87
$ registerListenersPass = new RegisterKernelListenersPass ();
82
88
$ registerListenersPass ->process ($ builder );
83
89
}
90
+
91
+ /**
92
+ * @expectedException \InvalidArgumentException
93
+ * @expectedExceptionMessage The service "foo" must be public as event listeners are lazy-loaded.
94
+ */
95
+ public function testPrivateEventListener ()
96
+ {
97
+ $ container = new ContainerBuilder ();
98
+ $ container ->register ('foo ' , 'stdClass ' )->setPublic (false )->addTag ('kernel.event_listener ' , array ());
99
+ $ container ->register ('event_dispatcher ' , 'stdClass ' );
100
+
101
+ $ registerListenersPass = new RegisterKernelListenersPass ();
102
+ $ registerListenersPass ->process ($ container );
103
+ }
104
+
105
+ /**
106
+ * @expectedException \InvalidArgumentException
107
+ * @expectedExceptionMessage The service "foo" must be public as event subscribers are lazy-loaded.
108
+ */
109
+ public function testPrivateEventSubscriber ()
110
+ {
111
+ $ container = new ContainerBuilder ();
112
+ $ container ->register ('foo ' , 'stdClass ' )->setPublic (false )->addTag ('kernel.event_subscriber ' , array ());
113
+ $ container ->register ('event_dispatcher ' , 'stdClass ' );
114
+
115
+ $ registerListenersPass = new RegisterKernelListenersPass ();
116
+ $ registerListenersPass ->process ($ container );
117
+ }
84
118
}
85
119
86
120
class SubscriberService implements \Symfony \Component \EventDispatcher \EventSubscriberInterface
0 commit comments