[FrameworkBundle] removed the need to boot a Kernel in a unit test file
This commit is contained in:
parent
4dc5b8ec78
commit
d86aa74e3d
@ -13,14 +13,27 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
|
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
|
||||||
use Symfony\Bundle\FrameworkBundle\Tests\Logger;
|
use Symfony\Component\ClassLoader\UniversalClassLoader;
|
||||||
use Symfony\Bundle\FrameworkBundle\Tests\Kernel;
|
|
||||||
|
|
||||||
require_once __DIR__.'/../Kernel.php';
|
|
||||||
require_once __DIR__.'/../Logger.php';
|
|
||||||
|
|
||||||
class ControllerNameParserTest extends TestCase
|
class ControllerNameParserTest extends TestCase
|
||||||
{
|
{
|
||||||
|
protected $loader;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->loader = new UniversalClassLoader();
|
||||||
|
$this->loader->registerNamespaces(array(
|
||||||
|
'TestBundle' => __DIR__.'/../Fixtures',
|
||||||
|
'TestApplication' => __DIR__.'/../Fixtures',
|
||||||
|
));
|
||||||
|
$this->loader->register();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
spl_autoload_unregister(array($this->loader, 'loadClass'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testParse()
|
public function testParse()
|
||||||
{
|
{
|
||||||
$parser = $this->createParser();
|
$parser = $this->createParser();
|
||||||
@ -63,10 +76,31 @@ class ControllerNameParserTest extends TestCase
|
|||||||
|
|
||||||
private function createParser()
|
private function createParser()
|
||||||
{
|
{
|
||||||
$kernel = new Kernel();
|
$bundles = array(
|
||||||
$kernel->boot();
|
'SensioFooBundle' => array($this->getBundle('TestBundle\Fabpot\FooBundle', 'FabpotFooBundle'), $this->getBundle('TestBundle\Sensio\FooBundle', 'SensioFooBundle')),
|
||||||
$logger = new Logger();
|
'SensioCmsFooBundle' => array($this->getBundle('TestBundle\Sensio\Cms\FooBundle', 'SensioCmsFooBundle')),
|
||||||
|
'FooBundle' => array($this->getBundle('TestBundle\FooBundle', 'FooBundle')),
|
||||||
|
'FabpotFooBundle' => array($this->getBundle('TestBundle\Fabpot\FooBundle', 'FabpotFooBundle'), $this->getBundle('TestBundle\Sensio\FooBundle', 'SensioFooBundle')),
|
||||||
|
);
|
||||||
|
|
||||||
return new ControllerNameParser($kernel, $logger);
|
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
|
||||||
|
$kernel
|
||||||
|
->expects($this->any())
|
||||||
|
->method('getBundle')
|
||||||
|
->will($this->returnCallback(function ($bundle) use ($bundles) {
|
||||||
|
return $bundles[$bundle];
|
||||||
|
}))
|
||||||
|
;
|
||||||
|
|
||||||
|
return new ControllerNameParser($kernel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getBundle($namespace, $name)
|
||||||
|
{
|
||||||
|
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
|
||||||
|
$bundle->expects($this->any())->method('getName')->will($this->returnValue($name));
|
||||||
|
$bundle->expects($this->any())->method('getNamespace')->will($this->returnValue($namespace));
|
||||||
|
|
||||||
|
return $bundle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user