4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 abstract class Twig_Tests_Profiler_Dumper_AbstractTest extends PHPUnit_Framework_TestCase
14 protected function getProfile()
16 $profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock();
18 $profile->expects($this->any())->method('isRoot')->will($this->returnValue(true));
19 $profile->expects($this->any())->method('getName')->will($this->returnValue('main'));
20 $profile->expects($this->any())->method('getDuration')->will($this->returnValue(1));
21 $profile->expects($this->any())->method('getMemoryUsage')->will($this->returnValue(0));
22 $profile->expects($this->any())->method('getPeakMemoryUsage')->will($this->returnValue(0));
25 $this->getIndexProfile(
27 $this->getEmbeddedBlockProfile(),
28 $this->getEmbeddedTemplateProfile(
30 $this->getIncludedTemplateProfile(),
33 $this->getMacroProfile(),
34 $this->getEmbeddedTemplateProfile(
36 $this->getIncludedTemplateProfile(),
43 $profile->expects($this->any())->method('getProfiles')->will($this->returnValue($subProfiles));
44 $profile->expects($this->any())->method('getIterator')->will($this->returnValue(new ArrayIterator($subProfiles)));
49 private function getIndexProfile(array $subProfiles = array())
51 return $this->generateProfile('main', 1, true, 'template', 'index.twig', $subProfiles);
54 private function getEmbeddedBlockProfile(array $subProfiles = array())
56 return $this->generateProfile('body', 0.0001, false, 'block', 'embedded.twig', $subProfiles);
59 private function getEmbeddedTemplateProfile(array $subProfiles = array())
61 return $this->generateProfile('main', 0.0001, true, 'template', 'embedded.twig', $subProfiles);
64 private function getIncludedTemplateProfile(array $subProfiles = array())
66 return $this->generateProfile('main', 0.0001, true, 'template', 'included.twig', $subProfiles);
69 private function getMacroProfile(array $subProfiles = array())
71 return $this->generateProfile('foo', 0.0001, false, 'macro', 'index.twig', $subProfiles);
76 * @param float $duration
77 * @param bool $isTemplate
79 * @param string $templateName
80 * @param array $subProfiles
82 * @return Twig_Profiler_Profile
84 private function generateProfile($name, $duration, $isTemplate, $type, $templateName, array $subProfiles = array())
86 $profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock();
88 $profile->expects($this->any())->method('isRoot')->will($this->returnValue(false));
89 $profile->expects($this->any())->method('getName')->will($this->returnValue($name));
90 $profile->expects($this->any())->method('getDuration')->will($this->returnValue($duration));
91 $profile->expects($this->any())->method('getMemoryUsage')->will($this->returnValue(0));
92 $profile->expects($this->any())->method('getPeakMemoryUsage')->will($this->returnValue(0));
93 $profile->expects($this->any())->method('isTemplate')->will($this->returnValue($isTemplate));
94 $profile->expects($this->any())->method('getType')->will($this->returnValue($type));
95 $profile->expects($this->any())->method('getTemplate')->will($this->returnValue($templateName));
96 $profile->expects($this->any())->method('getProfiles')->will($this->returnValue($subProfiles));
97 $profile->expects($this->any())->method('getIterator')->will($this->returnValue(new ArrayIterator($subProfiles)));