From e93fc7a2c0b00744f02928642df890226416d0f1 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Tue, 28 May 2013 21:38:03 +0200 Subject: [PATCH] [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 e478c5172318..06a8698cf162 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -67,6 +67,8 @@ public function doRun(InputInterface $input, OutputInterface $output) { $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 1427453b1065..6ded6dc5daf8 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 @@ public function testBundleInterfaceImplementation() 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 @@ public function testBundleCommandsAreRegistered() 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; }