From ce6e5ac5aa61d4a109e80041d8490b44b65243fb Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Fri, 19 Feb 2016 17:41:56 +0100 Subject: [PATCH] [2.7] [FrameworkBundle] minor fix tests added by #17569 --- .../Tests/Console/ApplicationTest.php | 62 +++++++------------ 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php index fc003431fa..fc0e7654db 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php @@ -24,7 +24,7 @@ class ApplicationTest extends TestCase { $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface'); - $kernel = $this->getKernel(array($bundle)); + $kernel = $this->getKernel(array($bundle), true); $application = new Application($kernel); $application->doRun(new ArrayInput(array('list')), new NullOutput()); @@ -35,7 +35,7 @@ class ApplicationTest extends TestCase $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); $bundle->expects($this->once())->method('registerCommands'); - $kernel = $this->getKernel(array($bundle)); + $kernel = $this->getKernel(array($bundle), true); $application = new Application($kernel); $application->doRun(new ArrayInput(array('list')), new NullOutput()); @@ -49,12 +49,7 @@ class ApplicationTest extends TestCase $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); $bundle->expects($this->once())->method('registerCommands'); - $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); - $kernel - ->expects($this->any()) - ->method('getBundles') - ->will($this->returnValue(array($bundle))) - ; + $kernel = $this->getKernel(array($bundle)); $application = new Application($kernel); $application->all(); @@ -68,12 +63,7 @@ class ApplicationTest extends TestCase $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); $bundle->expects($this->once())->method('registerCommands'); - $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); - $kernel - ->expects($this->any()) - ->method('getBundles') - ->will($this->returnValue(array($bundle))) - ; + $kernel = $this->getKernel(array($bundle)); $application = new Application($kernel); @@ -88,12 +78,7 @@ class ApplicationTest extends TestCase $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); $bundle->expects($this->once())->method('registerCommands'); - $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); - $kernel - ->expects($this->any()) - ->method('getBundles') - ->will($this->returnValue(array($bundle))) - ; + $kernel = $this->getKernel(array($bundle)); $application = new Application($kernel); @@ -108,12 +93,7 @@ class ApplicationTest extends TestCase $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); $bundle->expects($this->once())->method('registerCommands'); - $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); - $kernel - ->expects($this->any()) - ->method('getBundles') - ->will($this->returnValue(array($bundle))) - ; + $kernel = $this->getKernel(array($bundle)); $application = new Application($kernel); @@ -130,7 +110,7 @@ class ApplicationTest extends TestCase $command->setCode(function () {}); $command->expects($this->exactly(2))->method('setContainer'); - $application = new Application($this->getKernel(array())); + $application = new Application($this->getKernel(array(), true)); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->add($command); @@ -143,21 +123,23 @@ class ApplicationTest extends TestCase $tester->run(array('command' => 'foo')); } - private function getKernel(array $bundles) + private function getKernel(array $bundles, $useDispatcher = false) { - $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); - $dispatcher - ->expects($this->atLeastOnce()) - ->method('dispatch') - ; - $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $container - ->expects($this->atLeastOnce()) - ->method('get') - ->with($this->equalTo('event_dispatcher')) - ->will($this->returnValue($dispatcher)) - ; + + if ($useDispatcher) { + $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $dispatcher + ->expects($this->atLeastOnce()) + ->method('dispatch') + ; + $container + ->expects($this->atLeastOnce()) + ->method('get') + ->with($this->equalTo('event_dispatcher')) + ->will($this->returnValue($dispatcher)); + } + $container ->expects($this->once()) ->method('hasParameter')