Skip to content

Commit 445fa33

Browse files
committed
[FrameworkBundle] Added a missing test for TimedPhpEngine.
1 parent d2677a0 commit 445fa33

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\TimedPhpEngine;
15+
use Symfony\Component\DependencyInjection\Container;
16+
use Symfony\Component\HttpFoundation\Request;
17+
use Symfony\Component\HttpFoundation\Session\Session;
18+
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
19+
use Symfony\Component\Templating\TemplateNameParser;
20+
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
21+
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
22+
23+
class TimedPhpEngineTest extends TestCase
24+
{
25+
public function testThatRenderLogsTime()
26+
{
27+
$container = $this->getContainer();
28+
$templateNameParser = $this->getTemplateNameParser();
29+
$globalVariables = $this->getGlobalVariables();
30+
$loader = $this->getLoader($this->getStorage());
31+
32+
$stopwatch = $this->getStopwatch();
33+
$stopwatchEvent = $this->getStopwatchEvent();
34+
35+
$stopwatch->expects($this->once())
36+
->method('start')
37+
->with('template.php (index.php)', 'template')
38+
->will($this->returnValue($stopwatchEvent));
39+
40+
$stopwatchEvent->expects($this->once())->method('stop');
41+
42+
$engine = new TimedPhpEngine($templateNameParser, $container, $loader, $stopwatch, $globalVariables);
43+
$engine->render('index.php');
44+
}
45+
46+
/**
47+
* @return \Symfony\Component\DependencyInjection\Container
48+
*/
49+
private function getContainer()
50+
{
51+
return $this->getMock('Symfony\Component\DependencyInjection\Container');
52+
}
53+
54+
/**
55+
* @return \Symfony\Component\Templating\TemplateNameParserInterface
56+
*/
57+
private function getTemplateNameParser()
58+
{
59+
$templateReference = $this->getMock('Symfony\Component\Templating\TemplateReferenceInterface');
60+
$templateNameParser = $this->getMock('Symfony\Component\Templating\TemplateNameParserInterface');
61+
$templateNameParser->expects($this->any())
62+
->method('parse')
63+
->will($this->returnValue($templateReference));
64+
65+
return $templateNameParser;
66+
}
67+
68+
/**
69+
* @return \Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables
70+
*/
71+
private function getGlobalVariables()
72+
{
73+
return $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables')
74+
->disableOriginalConstructor()
75+
->getMock();
76+
}
77+
78+
/**
79+
* @return \Symfony\Component\Templating\Storage\StringStorage
80+
*/
81+
private function getStorage()
82+
{
83+
return $this->getMockBuilder('Symfony\Component\Templating\Storage\StringStorage')
84+
->disableOriginalConstructor()
85+
->getMockForAbstractClass();
86+
}
87+
88+
/**
89+
* @param \Symfony\Component\Templating\Storage\StringStorage $storage
90+
*
91+
* @return \Symfony\Component\Templating\Loader\Loader
92+
*/
93+
private function getLoader($storage)
94+
{
95+
$loader = $this->getMockForAbstractClass('Symfony\Component\Templating\Loader\Loader');
96+
$loader->expects($this->once())
97+
->method('load')
98+
->will($this->returnValue($storage));
99+
100+
return $loader;
101+
}
102+
103+
/**
104+
* @return \Symfony\Component\Stopwatch\StopwatchEvent
105+
*/
106+
private function getStopwatchEvent()
107+
{
108+
return $this->getMockBuilder('Symfony\Component\Stopwatch\StopwatchEvent')
109+
->disableOriginalConstructor()
110+
->getMock();
111+
}
112+
113+
/**
114+
* @return \Symfony\Component\Stopwatch\Stopwatch
115+
*/
116+
private function getStopwatch()
117+
{
118+
return $this->getMock('Symfony\Component\Stopwatch\Stopwatch');
119+
}
120+
}

0 commit comments

Comments
 (0)