2013-04-17 22:32:28 +01:00
|
|
|
<?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\Bundle\FrameworkBundle\Tests\Templating;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\TimedPhpEngine;
|
|
|
|
use Symfony\Component\DependencyInjection\Container;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
|
|
|
|
|
|
|
class TimedPhpEngineTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testThatRenderLogsTime()
|
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
$templateNameParser = $this->getTemplateNameParser();
|
|
|
|
$globalVariables = $this->getGlobalVariables();
|
|
|
|
$loader = $this->getLoader($this->getStorage());
|
|
|
|
|
|
|
|
$stopwatch = $this->getStopwatch();
|
|
|
|
$stopwatchEvent = $this->getStopwatchEvent();
|
|
|
|
|
|
|
|
$stopwatch->expects($this->once())
|
|
|
|
->method('start')
|
|
|
|
->with('template.php (index.php)', 'template')
|
|
|
|
->will($this->returnValue($stopwatchEvent));
|
|
|
|
|
|
|
|
$stopwatchEvent->expects($this->once())->method('stop');
|
|
|
|
|
|
|
|
$engine = new TimedPhpEngine($templateNameParser, $container, $loader, $stopwatch, $globalVariables);
|
|
|
|
$engine->render('index.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-30 09:03:46 +00:00
|
|
|
* @return Container
|
2013-04-17 22:32:28 +01:00
|
|
|
*/
|
|
|
|
private function getContainer()
|
|
|
|
{
|
2016-12-19 09:02:29 +00:00
|
|
|
return $this->getMockBuilder('Symfony\Component\DependencyInjection\Container')->getMock();
|
2013-04-17 22:32:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Symfony\Component\Templating\TemplateNameParserInterface
|
|
|
|
*/
|
|
|
|
private function getTemplateNameParser()
|
|
|
|
{
|
2016-12-19 09:02:29 +00:00
|
|
|
$templateReference = $this->getMockBuilder('Symfony\Component\Templating\TemplateReferenceInterface')->getMock();
|
|
|
|
$templateNameParser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock();
|
2013-04-17 22:32:28 +01:00
|
|
|
$templateNameParser->expects($this->any())
|
|
|
|
->method('parse')
|
|
|
|
->will($this->returnValue($templateReference));
|
|
|
|
|
|
|
|
return $templateNameParser;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-30 09:03:46 +00:00
|
|
|
* @return GlobalVariables
|
2013-04-17 22:32:28 +01:00
|
|
|
*/
|
|
|
|
private function getGlobalVariables()
|
|
|
|
{
|
|
|
|
return $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Symfony\Component\Templating\Storage\StringStorage
|
|
|
|
*/
|
|
|
|
private function getStorage()
|
|
|
|
{
|
|
|
|
return $this->getMockBuilder('Symfony\Component\Templating\Storage\StringStorage')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMockForAbstractClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \Symfony\Component\Templating\Storage\StringStorage $storage
|
|
|
|
*
|
|
|
|
* @return \Symfony\Component\Templating\Loader\Loader
|
|
|
|
*/
|
|
|
|
private function getLoader($storage)
|
|
|
|
{
|
|
|
|
$loader = $this->getMockForAbstractClass('Symfony\Component\Templating\Loader\Loader');
|
|
|
|
$loader->expects($this->once())
|
|
|
|
->method('load')
|
|
|
|
->will($this->returnValue($storage));
|
|
|
|
|
|
|
|
return $loader;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Symfony\Component\Stopwatch\StopwatchEvent
|
|
|
|
*/
|
|
|
|
private function getStopwatchEvent()
|
|
|
|
{
|
|
|
|
return $this->getMockBuilder('Symfony\Component\Stopwatch\StopwatchEvent')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Symfony\Component\Stopwatch\Stopwatch
|
|
|
|
*/
|
|
|
|
private function getStopwatch()
|
|
|
|
{
|
2016-12-19 09:02:29 +00:00
|
|
|
return $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')->getMock();
|
2013-04-17 22:32:28 +01:00
|
|
|
}
|
|
|
|
}
|