Skip to content

Commit 0a72a99

Browse files
committed
[FrameworkBundle] Added tests for the DelegatingEngine.
1 parent 6c31ab2 commit 0a72a99

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
13+
14+
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
15+
16+
class DelegatingEngineTest extends \PHPUnit_Framework_TestCase
17+
{
18+
public function testSupportsRetrievesEngineFromTheContainer()
19+
{
20+
$container = $this->getContainerMock(array(
21+
'engine.first' => $this->getEngineMock('template.php', false),
22+
'engine.second' => $this->getEngineMock('template.php', true)
23+
));
24+
25+
$delegatingEngine = new DelegatingEngine($container, array('engine.first', 'engine.second'));
26+
27+
$this->assertTrue($delegatingEngine->supports('template.php'));
28+
}
29+
30+
public function testRenderResponse()
31+
{
32+
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
33+
$engine = $this->getFrameworkEngineMock('template.php', true);
34+
$engine->expects($this->once())
35+
->method('renderResponse')
36+
->with('template.php', array('foo' => 'bar'))
37+
->will($this->returnValue($response));
38+
$container = $this->getContainerMock(array('engine' => $engine));
39+
40+
$delegatingEngine = new DelegatingEngine($container, array('engine'));
41+
42+
$this->assertSame($response, $delegatingEngine->renderResponse('template.php', array('foo' => 'bar')));
43+
}
44+
45+
private function getEngineMock($template, $supports)
46+
{
47+
$engine = $this->getMock('Symfony\Component\Templating\EngineInterface');
48+
49+
$engine->expects($this->once())
50+
->method('supports')
51+
->with($template)
52+
->will($this->returnValue($supports));
53+
54+
return $engine;
55+
}
56+
57+
private function getFrameworkEngineMock($template, $supports)
58+
{
59+
$engine = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
60+
61+
$engine->expects($this->once())
62+
->method('supports')
63+
->with($template)
64+
->will($this->returnValue($supports));
65+
66+
return $engine;
67+
}
68+
69+
private function getContainerMock($services)
70+
{
71+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
72+
73+
$i = 0;
74+
foreach ($services as $id => $service) {
75+
$container->expects($this->at($i++))
76+
->method('get')
77+
->with($id)
78+
->will($this->returnValue($service));
79+
}
80+
81+
return $container;
82+
}
83+
}

0 commit comments

Comments
 (0)