Skip to content

Commit

Permalink
[FrameworkBundle] removed the need to boot a Kernel in a unit test file
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Apr 21, 2011
1 parent 4dc5b8e commit d86aa74
Showing 1 changed file with 43 additions and 9 deletions.
Expand Up @@ -13,14 +13,27 @@

use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Bundle\FrameworkBundle\Tests\Logger;
use Symfony\Bundle\FrameworkBundle\Tests\Kernel;

require_once __DIR__.'/../Kernel.php';
require_once __DIR__.'/../Logger.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;

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()
{
$parser = $this->createParser();
Expand Down Expand Up @@ -63,10 +76,31 @@ public function getMissingControllersTest()

private function createParser()
{
$kernel = new Kernel();
$kernel->boot();
$logger = new Logger();
$bundles = array(
'SensioFooBundle' => array($this->getBundle('TestBundle\Fabpot\FooBundle', 'FabpotFooBundle'), $this->getBundle('TestBundle\Sensio\FooBundle', 'SensioFooBundle')),
'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')),
);

$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 new ControllerNameParser($kernel, $logger);
return $bundle;
}
}

0 comments on commit d86aa74

Please sign in to comment.