From 176a3d435e38f9dc0fce83a81603c3dfd20cf6f3 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Tue, 28 May 2013 21:36:15 +0200 Subject: [PATCH 1/2] [Console] fix typehint for Application::setDispatcher --- src/Symfony/Component/Console/Application.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 5c232698e2..7b231ef01a 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -33,7 +33,7 @@ use Symfony\Component\Console\Helper\TableHelper; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\Console\Event\ConsoleForExceptionEvent; use Symfony\Component\Console\Event\ConsoleTerminateEvent; -use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * An Application is the container for a collection of commands. @@ -88,7 +88,7 @@ class Application } } - public function setDispatcher(EventDispatcher $dispatcher) + public function setDispatcher(EventDispatcherInterface $dispatcher) { $this->dispatcher = $dispatcher; } From e93fc7a2c0b00744f02928642df890226416d0f1 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Tue, 28 May 2013 21:38:03 +0200 Subject: [PATCH 2/2] [FrameworkBundle] set the dispatcher in the console application So events are really dispatched using the FrameworkBundle console application --- .../FrameworkBundle/Console/Application.php | 2 ++ .../Tests/Console/ApplicationTest.php | 25 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index e478c51723..06a8698cf1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -67,6 +67,8 @@ class Application extends BaseApplication { $this->registerCommands(); + $this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher')); + if (true === $input->hasParameterOption(array('--shell', '-s'))) { $shell = new Shell($this); $shell->setProcessIsolation($input->hasParameterOption(array('--process-isolation'))); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php index 1427453b10..6ded6dc5da 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php @@ -20,7 +20,7 @@ class ApplicationTest extends TestCase { public function testBundleInterfaceImplementation() { - $bundle = $this->getMock("Symfony\Component\HttpKernel\Bundle\BundleInterface"); + $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface'); $kernel = $this->getKernel(array($bundle)); @@ -30,7 +30,7 @@ class ApplicationTest extends TestCase public function testBundleCommandsAreRegistered() { - $bundle = $this->getMock("Symfony\Component\HttpKernel\Bundle\Bundle"); + $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); $bundle->expects($this->once())->method('registerCommands'); $kernel = $this->getKernel(array($bundle)); @@ -41,12 +41,31 @@ class ApplicationTest extends TestCase private function getKernel(array $bundles) { - $kernel = $this->getMock("Symfony\Component\HttpKernel\KernelInterface"); + $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $dispatcher + ->expects($this->atLeastOnce()) + ->method('dispatch') + ; + + $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $container + ->expects($this->once()) + ->method('get') + ->with($this->equalTo('event_dispatcher')) + ->will($this->returnValue($dispatcher)) + ; + + $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); $kernel ->expects($this->any()) ->method('getBundles') ->will($this->returnValue($bundles)) ; + $kernel + ->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($container)) + ; return $kernel; }