mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 10:26:32 +00:00
removed mock usage in profile tests
This commit is contained in:
@@ -15,14 +15,7 @@ abstract class Twig_Tests_Profiler_Dumper_AbstractTest extends \PHPUnit\Framewor
|
||||
{
|
||||
protected function getProfile()
|
||||
{
|
||||
$profile = $this->getMockBuilder('\Twig\Profiler\Profile')->disableOriginalConstructor()->getMock();
|
||||
|
||||
$profile->expects($this->any())->method('isRoot')->will($this->returnValue(true));
|
||||
$profile->expects($this->any())->method('getName')->will($this->returnValue('main'));
|
||||
$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));
|
||||
|
||||
$profile = new Profile('main');
|
||||
$subProfiles = [
|
||||
$this->getIndexProfile(
|
||||
[
|
||||
@@ -42,35 +35,36 @@ abstract class Twig_Tests_Profiler_Dumper_AbstractTest extends \PHPUnit\Framewor
|
||||
),
|
||||
];
|
||||
|
||||
$profile->expects($this->any())->method('getProfiles')->will($this->returnValue($subProfiles));
|
||||
$profile->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator($subProfiles)));
|
||||
$p = new \ReflectionProperty($profile, 'profiles');
|
||||
$p->setAccessible(true);
|
||||
$p->setValue($profile, $subProfiles);
|
||||
|
||||
return $profile;
|
||||
}
|
||||
|
||||
private function getIndexProfile(array $subProfiles = [])
|
||||
{
|
||||
return $this->generateProfile('main', 1, true, 'template', 'index.twig', $subProfiles);
|
||||
return $this->generateProfile('main', 1, 'template', 'index.twig', $subProfiles);
|
||||
}
|
||||
|
||||
private function getEmbeddedBlockProfile(array $subProfiles = [])
|
||||
{
|
||||
return $this->generateProfile('body', 0.0001, false, 'block', 'embedded.twig', $subProfiles);
|
||||
return $this->generateProfile('body', 0.0001, 'block', 'embedded.twig', $subProfiles);
|
||||
}
|
||||
|
||||
private function getEmbeddedTemplateProfile(array $subProfiles = [])
|
||||
{
|
||||
return $this->generateProfile('main', 0.0001, true, 'template', 'embedded.twig', $subProfiles);
|
||||
return $this->generateProfile('main', 0.0001, 'template', 'embedded.twig', $subProfiles);
|
||||
}
|
||||
|
||||
private function getIncludedTemplateProfile(array $subProfiles = [])
|
||||
{
|
||||
return $this->generateProfile('main', 0.0001, true, 'template', 'included.twig', $subProfiles);
|
||||
return $this->generateProfile('main', 0.0001, 'template', 'included.twig', $subProfiles);
|
||||
}
|
||||
|
||||
private function getMacroProfile(array $subProfiles = [])
|
||||
{
|
||||
return $this->generateProfile('foo', 0.0001, false, 'macro', 'index.twig', $subProfiles);
|
||||
return $this->generateProfile('foo', 0.0001, 'macro', 'index.twig', $subProfiles);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,20 +77,28 @@ abstract class Twig_Tests_Profiler_Dumper_AbstractTest extends \PHPUnit\Framewor
|
||||
*
|
||||
* @return Profile
|
||||
*/
|
||||
private function generateProfile($name, $duration, $isTemplate, $type, $templateName, array $subProfiles = [])
|
||||
private function generateProfile($name, $duration, $type, $templateName, array $subProfiles = [])
|
||||
{
|
||||
$profile = $this->getMockBuilder('\Twig\Profiler\Profile')->disableOriginalConstructor()->getMock();
|
||||
$profile = new Profile($templateName, $type, $name);
|
||||
|
||||
$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)));
|
||||
$p = new \ReflectionProperty($profile, 'profiles');
|
||||
$p->setAccessible(true);
|
||||
$p->setValue($profile, $subProfiles);
|
||||
|
||||
$starts = new \ReflectionProperty($profile, 'starts');
|
||||
$starts->setAccessible(true);
|
||||
$starts->setValue($profile, [
|
||||
'wt' => 0,
|
||||
'mu' => 0,
|
||||
'pmu' => 0,
|
||||
]);
|
||||
$ends = new \ReflectionProperty($profile, 'ends');
|
||||
$ends->setAccessible(true);
|
||||
$ends->setValue($profile, [
|
||||
'wt' => $duration,
|
||||
'mu' => 0,
|
||||
'pmu' => 0,
|
||||
]);
|
||||
|
||||
return $profile;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user