merged branch Tobion/console-dispatcher (PR #8158)

This PR was merged into the 2.3 branch.

Discussion
----------

[FrameworkBundle] set the dispatcher in the console application

BC break: no
test pass: yes

Otherwise events are not dispatched in symfony frameworkbundle.
The first commit fixes a related typehint in the console.

Commits
-------

e93fc7a [FrameworkBundle] set the dispatcher in the console application
176a3d4 [Console] fix typehint for Application::setDispatcher
This commit is contained in:
Fabien Potencier 2013-05-30 07:11:26 +02:00
commit b5c9bb8e03
3 changed files with 26 additions and 5 deletions

View File

@ -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')));

View File

@ -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;
}

View File

@ -33,7 +33,7 @@ use Symfony\Component\Console\Helper\TableHelper;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
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;
}