mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
N°2651 rollback gitignore for lib tests dirs
Too dangerous ! We'll work properly on this but for 2.8
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?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 Symfony\Component\HttpKernel\Tests\Fragment;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class FragmentHandlerTest extends TestCase
|
||||
{
|
||||
private $requestStack;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->requestStack = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
$this->requestStack
|
||||
->expects($this->any())
|
||||
->method('getCurrentRequest')
|
||||
->willReturn(Request::create('/'))
|
||||
;
|
||||
}
|
||||
|
||||
public function testRenderWhenRendererDoesNotExist()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$handler = new FragmentHandler($this->requestStack);
|
||||
$handler->render('/', 'foo');
|
||||
}
|
||||
|
||||
public function testRenderWithUnknownRenderer()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$handler = $this->getHandler($this->returnValue(new Response('foo')));
|
||||
|
||||
$handler->render('/', 'bar');
|
||||
}
|
||||
|
||||
public function testDeliverWithUnsuccessfulResponse()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$this->expectExceptionMessage('Error when rendering "http://localhost/" (Status code is 404).');
|
||||
$handler = $this->getHandler($this->returnValue(new Response('foo', 404)));
|
||||
|
||||
$handler->render('/', 'foo');
|
||||
}
|
||||
|
||||
public function testRender()
|
||||
{
|
||||
$handler = $this->getHandler($this->returnValue(new Response('foo')), ['/', Request::create('/'), ['foo' => 'foo', 'ignore_errors' => true]]);
|
||||
|
||||
$this->assertEquals('foo', $handler->render('/', 'foo', ['foo' => 'foo']));
|
||||
}
|
||||
|
||||
protected function getHandler($returnValue, $arguments = [])
|
||||
{
|
||||
$renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
|
||||
$renderer
|
||||
->expects($this->any())
|
||||
->method('getName')
|
||||
->willReturn('foo')
|
||||
;
|
||||
$e = $renderer
|
||||
->expects($this->any())
|
||||
->method('render')
|
||||
->will($returnValue)
|
||||
;
|
||||
|
||||
if ($arguments) {
|
||||
\call_user_func_array([$e, 'with'], $arguments);
|
||||
}
|
||||
|
||||
$handler = new FragmentHandler($this->requestStack);
|
||||
$handler->addRenderer($renderer);
|
||||
|
||||
return $handler;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user