4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\Fragment;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Request;
16 use Symfony\Component\HttpFoundation\Response;
17 use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
20 * @group time-sensitive
22 class FragmentHandlerTest extends TestCase
24 private $requestStack;
26 protected function setUp()
28 $this->requestStack = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
29 ->disableOriginalConstructor()
33 ->expects($this->any())
34 ->method('getCurrentRequest')
35 ->will($this->returnValue(Request::create('/')))
40 * @expectedException \InvalidArgumentException
42 public function testRenderWhenRendererDoesNotExist()
44 $handler = new FragmentHandler($this->requestStack);
45 $handler->render('/', 'foo');
49 * @expectedException \InvalidArgumentException
51 public function testRenderWithUnknownRenderer()
53 $handler = $this->getHandler($this->returnValue(new Response('foo')));
55 $handler->render('/', 'bar');
59 * @expectedException \RuntimeException
60 * @expectedExceptionMessage Error when rendering "http://localhost/" (Status code is 404).
62 public function testDeliverWithUnsuccessfulResponse()
64 $handler = $this->getHandler($this->returnValue(new Response('foo', 404)));
66 $handler->render('/', 'foo');
69 public function testRender()
71 $handler = $this->getHandler($this->returnValue(new Response('foo')), array('/', Request::create('/'), array('foo' => 'foo', 'ignore_errors' => true)));
73 $this->assertEquals('foo', $handler->render('/', 'foo', array('foo' => 'foo')));
76 protected function getHandler($returnValue, $arguments = array())
78 $renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
80 ->expects($this->any())
82 ->will($this->returnValue('foo'))
85 ->expects($this->any())
91 \call_user_func_array(array($e, 'with'), $arguments);
94 $handler = new FragmentHandler($this->requestStack);
95 $handler->addRenderer($renderer);