mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
Use stubs for profiles. Fixes #1660
This commit is contained in:
@@ -13,32 +13,88 @@ abstract class Twig_Tests_Profiler_Dumper_AbstractTest extends PHPUnit_Framework
|
|||||||
{
|
{
|
||||||
protected function getProfile()
|
protected function getProfile()
|
||||||
{
|
{
|
||||||
$profile = new Twig_Profiler_Profile();
|
$profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock();
|
||||||
$index = new Twig_Profiler_Profile('index.twig', Twig_Profiler_Profile::TEMPLATE);
|
|
||||||
$profile->addProfile($index);
|
|
||||||
$body = new Twig_Profiler_Profile('embedded.twig', Twig_Profiler_Profile::BLOCK, 'body');
|
|
||||||
$body->leave();
|
|
||||||
$index->addProfile($body);
|
|
||||||
$embedded = new Twig_Profiler_Profile('embedded.twig', Twig_Profiler_Profile::TEMPLATE);
|
|
||||||
$included = new Twig_Profiler_Profile('included.twig', Twig_Profiler_Profile::TEMPLATE);
|
|
||||||
$embedded->addProfile($included);
|
|
||||||
$index->addProfile($embedded);
|
|
||||||
$included->leave();
|
|
||||||
$embedded->leave();
|
|
||||||
|
|
||||||
$macro = new Twig_Profiler_Profile('index.twig', Twig_Profiler_Profile::MACRO, 'foo');
|
$profile->expects($this->any())->method('isRoot')->will($this->returnValue(true));
|
||||||
$macro->leave();
|
$profile->expects($this->any())->method('getName')->will($this->returnValue('main'));
|
||||||
$index->addProfile($macro);
|
$profile->expects($this->any())->method('getDuration')->will($this->returnValue(1));
|
||||||
|
$profile->expects($this->any())->method('getMemoryUsage')->will($this->returnValue(0));
|
||||||
|
$profile->expects($this->any())->method('getPeakMemoryUsage')->will($this->returnValue(0));
|
||||||
|
|
||||||
$embedded = clone $embedded;
|
$subProfiles = array(
|
||||||
$index->addProfile($embedded);
|
$this->getIndexProfile(
|
||||||
usleep(500);
|
array(
|
||||||
$embedded->leave();
|
$this->getEmbeddedBlockProfile(),
|
||||||
|
$this->getEmbeddedTemplateProfile(
|
||||||
|
array(
|
||||||
|
$this->getIncludedTemplateProfile(),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
$this->getMacroProfile(),
|
||||||
|
$this->getEmbeddedTemplateProfile(
|
||||||
|
array(
|
||||||
|
$this->getIncludedTemplateProfile(),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
usleep(4500);
|
$profile->expects($this->any())->method('getProfiles')->will($this->returnValue($subProfiles));
|
||||||
$index->leave();
|
$profile->expects($this->any())->method('getIterator')->will($this->returnValue(new ArrayIterator($subProfiles)));
|
||||||
|
|
||||||
$profile->leave();
|
return $profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getIndexProfile(array $subProfiles = array())
|
||||||
|
{
|
||||||
|
return $this->generateProfile('main', 1, true, 'template', 'index.twig', $subProfiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getEmbeddedBlockProfile(array $subProfiles = array())
|
||||||
|
{
|
||||||
|
return $this->generateProfile('body', 0.0001, false, 'block', 'embedded.twig', $subProfiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getEmbeddedTemplateProfile(array $subProfiles = array())
|
||||||
|
{
|
||||||
|
return $this->generateProfile('main', 0.0001, true, 'template', 'embedded.twig', $subProfiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getIncludedTemplateProfile(array $subProfiles = array())
|
||||||
|
{
|
||||||
|
return $this->generateProfile('main', 0.0001, true, 'template', 'included.twig', $subProfiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getMacroProfile(array $subProfiles = array())
|
||||||
|
{
|
||||||
|
return $this->generateProfile('foo', 0.0001, false, 'macro', 'index.twig', $subProfiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param float $duration
|
||||||
|
* @param bool $isTemplate
|
||||||
|
* @param string $type
|
||||||
|
* @param string $templateName
|
||||||
|
* @param array $subProfiles
|
||||||
|
*
|
||||||
|
* @return Twig_Profiler_Profile
|
||||||
|
*/
|
||||||
|
private function generateProfile($name, $duration, $isTemplate, $type, $templateName, array $subProfiles = array())
|
||||||
|
{
|
||||||
|
$profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock();
|
||||||
|
|
||||||
|
$profile->expects($this->any())->method('isRoot')->will($this->returnValue(false));
|
||||||
|
$profile->expects($this->any())->method('getName')->will($this->returnValue($name));
|
||||||
|
$profile->expects($this->any())->method('getDuration')->will($this->returnValue($duration));
|
||||||
|
$profile->expects($this->any())->method('getMemoryUsage')->will($this->returnValue(0));
|
||||||
|
$profile->expects($this->any())->method('getPeakMemoryUsage')->will($this->returnValue(0));
|
||||||
|
$profile->expects($this->any())->method('isTemplate')->will($this->returnValue($isTemplate));
|
||||||
|
$profile->expects($this->any())->method('getType')->will($this->returnValue($type));
|
||||||
|
$profile->expects($this->any())->method('getTemplate')->will($this->returnValue($templateName));
|
||||||
|
$profile->expects($this->any())->method('getProfiles')->will($this->returnValue($subProfiles));
|
||||||
|
$profile->expects($this->any())->method('getIterator')->will($this->returnValue(new ArrayIterator($subProfiles)));
|
||||||
|
|
||||||
return $profile;
|
return $profile;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user