minor #17859 [2.7] [FrameworkBundle] minor fix tests added by #17569 (HeahDude)

This PR was merged into the 2.7 branch.

Discussion
----------

[2.7] [FrameworkBundle] minor fix tests added by #17569

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | -

Commits
-------

ce6e5ac [2.7] [FrameworkBundle] minor fix tests added by #17569
This commit is contained in:
Fabien Potencier 2016-02-22 15:50:41 +01:00
commit 98a946a481

View File

@ -24,7 +24,7 @@ class ApplicationTest extends TestCase
{ {
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface'); $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
$kernel = $this->getKernel(array($bundle)); $kernel = $this->getKernel(array($bundle), true);
$application = new Application($kernel); $application = new Application($kernel);
$application->doRun(new ArrayInput(array('list')), new NullOutput()); $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 = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->once())->method('registerCommands'); $bundle->expects($this->once())->method('registerCommands');
$kernel = $this->getKernel(array($bundle)); $kernel = $this->getKernel(array($bundle), true);
$application = new Application($kernel); $application = new Application($kernel);
$application->doRun(new ArrayInput(array('list')), new NullOutput()); $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 = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->once())->method('registerCommands'); $bundle->expects($this->once())->method('registerCommands');
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); $kernel = $this->getKernel(array($bundle));
$kernel
->expects($this->any())
->method('getBundles')
->will($this->returnValue(array($bundle)))
;
$application = new Application($kernel); $application = new Application($kernel);
$application->all(); $application->all();
@ -68,12 +63,7 @@ class ApplicationTest extends TestCase
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->once())->method('registerCommands'); $bundle->expects($this->once())->method('registerCommands');
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); $kernel = $this->getKernel(array($bundle));
$kernel
->expects($this->any())
->method('getBundles')
->will($this->returnValue(array($bundle)))
;
$application = new Application($kernel); $application = new Application($kernel);
@ -88,12 +78,7 @@ class ApplicationTest extends TestCase
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->once())->method('registerCommands'); $bundle->expects($this->once())->method('registerCommands');
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); $kernel = $this->getKernel(array($bundle));
$kernel
->expects($this->any())
->method('getBundles')
->will($this->returnValue(array($bundle)))
;
$application = new Application($kernel); $application = new Application($kernel);
@ -108,12 +93,7 @@ class ApplicationTest extends TestCase
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->once())->method('registerCommands'); $bundle->expects($this->once())->method('registerCommands');
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); $kernel = $this->getKernel(array($bundle));
$kernel
->expects($this->any())
->method('getBundles')
->will($this->returnValue(array($bundle)))
;
$application = new Application($kernel); $application = new Application($kernel);
@ -130,7 +110,7 @@ class ApplicationTest extends TestCase
$command->setCode(function () {}); $command->setCode(function () {});
$command->expects($this->exactly(2))->method('setContainer'); $command->expects($this->exactly(2))->method('setContainer');
$application = new Application($this->getKernel(array())); $application = new Application($this->getKernel(array(), true));
$application->setAutoExit(false); $application->setAutoExit(false);
$application->setCatchExceptions(false); $application->setCatchExceptions(false);
$application->add($command); $application->add($command);
@ -143,21 +123,23 @@ class ApplicationTest extends TestCase
$tester->run(array('command' => 'foo')); $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 = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container
->expects($this->atLeastOnce()) if ($useDispatcher) {
->method('get') $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
->with($this->equalTo('event_dispatcher')) $dispatcher
->will($this->returnValue($dispatcher)) ->expects($this->atLeastOnce())
; ->method('dispatch')
;
$container
->expects($this->atLeastOnce())
->method('get')
->with($this->equalTo('event_dispatcher'))
->will($this->returnValue($dispatcher));
}
$container $container
->expects($this->once()) ->expects($this->once())
->method('hasParameter') ->method('hasParameter')