浏览代码

[FrameworkBundle] Fix an issue when adding a scoped service as an event listener

Victor Berchet 14 年之前
父节点
当前提交
3322cdbefc

+ 0 - 34
src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php

@@ -65,40 +65,6 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements
         parent::addListener($eventNames, $listener, $priority);
     }
 
-    /**
-     * {@inheritDoc}
-     *
-     * @throws \RuntimeException if the service does not exist
-     * @throws \RuntimeException if the listener service method is not callable
-     */
-    public function addListenerService($eventNames, $serviceId, $priority = 0)
-    {
-        $error = null;
-
-        if (!$this->container->has($serviceId)) {
-            $error = sprintf('The container has no service "%s".', $serviceId);
-        } else {
-            $listener = $this->container->get($serviceId);
-            if (!$listener instanceof \Closure) {
-                foreach ((array) $eventNames as $method) {
-                    if (!is_callable(array($listener, $method))) {
-                        $error = sprintf('The event method "%s()" is not callable on the service "%s".', $method, $serviceId);
-                        break;
-                    }
-                }
-            }
-        }
-
-        if (null !== $error) {
-            if (null !== $this->logger) {
-                $this->logger->err($error);
-            }
-            throw new \RuntimeException($error);
-        }
-
-        parent::addListenerService($eventNames, $serviceId, $priority);
-    }
-
     /**
      * {@inheritDoc}
      */

+ 0 - 41
src/Symfony/Bundle/FrameworkBundle/Tests/Debug/TraceableEventDispactherTest.php

@@ -26,45 +26,4 @@ class TraceableEventDispactherTest extends TestCase
         $dispatcher = new TraceableEventDispatcher($container);
         $dispatcher->addListener('onFooEvent', new \stdClass());
     }
-
-    /**
-     * @expectedException \RuntimeException
-     */
-    public function testThrowsAnExceptionWhenAListenerServiceIsNotFound()
-    {
-        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
-        $container
-            ->expects($this->once())
-            ->method('has')
-            ->with($this->equalTo('listener.service'))
-            ->will($this->returnValue(false))
-        ;
-
-        $dispatcher = new TraceableEventDispatcher($container);
-
-        $dispatcher->addListenerService('onFooEvent', 'listener.service');
-    }
-
-    /**
-     * @expectedException \RuntimeException
-     */
-    public function testThrowsAnExceptionWhenAListenerServiceMethodIsNotCallable()
-    {
-        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
-        $container
-            ->expects($this->once())
-            ->method('has')
-            ->with($this->equalTo('listener.service'))
-            ->will($this->returnValue(true))
-        ;
-        $container
-            ->expects($this->once())
-            ->method('get')
-            ->with($this->equalTo('listener.service'))
-            ->will($this->returnValue(new \stdClass()))
-        ;
-
-        $dispatcher = new TraceableEventDispatcher($container);
-        $dispatcher->addListenerService('onFooEvent', 'listener.service');
-    }
 }