Вход Регистрация
Файл: symfony-2.7/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php
Строк: 201
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyBundleFrameworkBundleTestsConsole;

use 
SymfonyBundleFrameworkBundleTestsTestCase;
use 
SymfonyBundleFrameworkBundleConsoleApplication;
use 
SymfonyComponentConsoleInputArrayInput;
use 
SymfonyComponentConsoleOutputNullOutput;
use 
SymfonyComponentConsoleTesterApplicationTester;

class 
ApplicationTest extends TestCase
{
    public function 
testBundleInterfaceImplementation()
    {
        
$bundle $this->getMock('SymfonyComponentHttpKernelBundleBundleInterface');

        
$kernel $this->getKernel(array($bundle));

        
$application = new Application($kernel);
        
$application->doRun(new ArrayInput(array('list')), new NullOutput());
    }

    public function 
testBundleCommandsAreRegistered()
    {
        
$bundle $this->getMock('SymfonyComponentHttpKernelBundleBundle');
        
$bundle->expects($this->once())->method('registerCommands');

        
$kernel $this->getKernel(array($bundle));

        
$application = new Application($kernel);
        
$application->doRun(new ArrayInput(array('list')), new NullOutput());
    }

    public function 
testBundleCommandsHaveRightContainer()
    {
        
$command $this->getMockForAbstractClass('SymfonyBundleFrameworkBundleCommandContainerAwareCommand', array('foo'), ''truetruetrue, array('setContainer'));
        
$command->setCode(function () {});
        
$command->expects($this->exactly(2))->method('setContainer');

        
$application = new Application($this->getKernel(array()));
        
$application->setAutoExit(false);
        
$application->setCatchExceptions(false);
        
$application->add($command);
        
$tester = new ApplicationTester($application);

        
// set container is called here
        
$tester->run(array('command' => 'foo'));

        
// as the container might have change between two runs, setContainer must called again
        
$tester->run(array('command' => 'foo'));
    }

    private function 
getKernel(array $bundles)
    {
        
$dispatcher $this->getMock('SymfonyComponentEventDispatcherEventDispatcherInterface');
        
$dispatcher
            
->expects($this->atLeastOnce())
            ->
method('dispatch')
        ;

        
$container $this->getMock('SymfonyComponentDependencyInjectionContainerInterface');
        
$container
            
->expects($this->atLeastOnce())
            ->
method('get')
            ->
with($this->equalTo('event_dispatcher'))
            ->
will($this->returnValue($dispatcher))
        ;
        
$container
            
->expects($this->once())
            ->
method('hasParameter')
            ->
with($this->equalTo('console.command.ids'))
            ->
will($this->returnValue(true))
        ;
        
$container
            
->expects($this->once())
            ->
method('getParameter')
            ->
with($this->equalTo('console.command.ids'))
            ->
will($this->returnValue(array()))
        ;

        
$kernel $this->getMock('SymfonyComponentHttpKernelKernelInterface');
        
$kernel
            
->expects($this->any())
            ->
method('getBundles')
            ->
will($this->returnValue($bundles))
        ;
        
$kernel
            
->expects($this->any())
            ->
method('getContainer')
            ->
will($this->returnValue($container))
        ;

        return 
$kernel;
    }
}
Онлайн: 0
Реклама