fixed unit tests

This commit is contained in:
Fabien Potencier 2012-12-13 17:59:38 +01:00
parent fc444f1a55
commit 142cffbc4f
2 changed files with 19 additions and 55 deletions

View File

@ -12,72 +12,33 @@
namespace Symfony\Bundle\TwigBundle\Tests\Controller;
use Symfony\Bundle\TwigBundle\Tests\TestCase;
use Symfony\Bundle\TwigBundle\Controller\ExceptionController;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\HttpFoundation\Request;
class ExceptionControllerTest extends TestCase
{
protected $controller;
protected $container;
protected $flatten;
protected $templating;
protected $kernel;
protected function setUp()
public function testOnlyClearOwnOutputBuffers()
{
parent::setUp();
$this->flatten = $this->getMock('Symfony\Component\HttpKernel\Exception\FlattenException');
$this->flatten
$flatten = $this->getMock('Symfony\Component\HttpKernel\Exception\FlattenException');
$flatten
->expects($this->once())
->method('getStatusCode')
->will($this->returnValue(404));
$this->controller = new ExceptionController();
$this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
$this->templating = $this->getMockBuilder('Symfony\\Bundle\\TwigBundle\\TwigEngine')
$twig = $this->getMockBuilder('\Twig_Environment')
->disableOriginalConstructor()
->getMock();
$this->templating
$twig
->expects($this->any())
->method('renderResponse')
->method('render')
->will($this->returnValue($this->getMock('Symfony\Component\HttpFoundation\Response')));
$this->request = Request::create('/');
$this->container = $this->getContainer();
}
$twig
->expects($this->any())
->method('getLoader')
->will($this->returnValue($this->getMock('\Twig_LoaderInterface')));
$request = Request::create('/');
$request->headers->set('X-Php-Ob-Level', 1);
protected function tearDown()
{
parent::tearDown();
$this->controller = null;
$this->container = null;
$this->flatten = null;
$this->templating = null;
$this->kernel = null;
}
public function testOnlyClearOwnOutputBuffers()
{
$this->request->headers->set('X-Php-Ob-Level', 1);
$this->controller->setContainer($this->container);
$this->controller->showAction($this->flatten);
}
private function getContainer()
{
$container = new ContainerBuilder();
$container->addScope(new Scope('request'));
$container->set('request', $this->request);
$container->set('templating', $this->templating);
$container->setParameter('kernel.bundles', array());
$container->setParameter('kernel.cache_dir', __DIR__);
$container->setParameter('kernel.root_dir', __DIR__);
$container->set('kernel', $this->kernel);
return $container;
$controller = new ExceptionController($twig, false);
$controller->showAction($request, $flatten);
}
}

View File

@ -80,7 +80,7 @@ class TemplateManagerTest extends TestCase
->method('hasCollector')
->will($this->returnCallback(array($this, 'profileHasCollectorCallback')));
$this->assertEquals('FooBundle:Collector:foo.html.twig', $this->templateManager->getName($profile, 'foo'));
$this->assertEquals('FooBundle:Collector:foo.html.twig', $this->templateManager->getName($profile, 'foo'));
}
/**
@ -89,7 +89,6 @@ class TemplateManagerTest extends TestCase
*/
public function testGetTemplates()
{
$profile = $this->mockProfile();
$profile->expects($this->any())
->method('hasCollector')
@ -145,6 +144,10 @@ class TemplateManagerTest extends TestCase
->method('loadTemplate')
->will($this->returnValue('loadedTemplate'));
$this->twigEnvironment->expects($this->any())
->method('getLoader')
->will($this->returnValue($this->getMock('\Twig_LoaderInterface')));
return $this->twigEnvironment;
}