da97f478aac4cb27899c69ca1c9d51374d64b2ee
[yaffs-website] / vendor / twig / twig / test / Twig / Tests / Profiler / Dumper / AbstractTest.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
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 abstract class Twig_Tests_Profiler_Dumper_AbstractTest extends PHPUnit_Framework_TestCase
13 {
14     protected function getProfile()
15     {
16         $profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock();
17
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));
23
24         $subProfiles = array(
25             $this->getIndexProfile(
26                 array(
27                     $this->getEmbeddedBlockProfile(),
28                     $this->getEmbeddedTemplateProfile(
29                         array(
30                             $this->getIncludedTemplateProfile(),
31                         )
32                     ),
33                     $this->getMacroProfile(),
34                     $this->getEmbeddedTemplateProfile(
35                         array(
36                             $this->getIncludedTemplateProfile(),
37                         )
38                     ),
39                 )
40             ),
41         );
42
43         $profile->expects($this->any())->method('getProfiles')->will($this->returnValue($subProfiles));
44         $profile->expects($this->any())->method('getIterator')->will($this->returnValue(new ArrayIterator($subProfiles)));
45
46         return $profile;
47     }
48
49     private function getIndexProfile(array $subProfiles = array())
50     {
51         return $this->generateProfile('main', 1, true, 'template', 'index.twig', $subProfiles);
52     }
53
54     private function getEmbeddedBlockProfile(array $subProfiles = array())
55     {
56         return $this->generateProfile('body', 0.0001, false, 'block', 'embedded.twig', $subProfiles);
57     }
58
59     private function getEmbeddedTemplateProfile(array $subProfiles = array())
60     {
61         return $this->generateProfile('main', 0.0001, true, 'template', 'embedded.twig', $subProfiles);
62     }
63
64     private function getIncludedTemplateProfile(array $subProfiles = array())
65     {
66         return $this->generateProfile('main', 0.0001, true, 'template', 'included.twig', $subProfiles);
67     }
68
69     private function getMacroProfile(array $subProfiles = array())
70     {
71         return $this->generateProfile('foo', 0.0001, false, 'macro', 'index.twig', $subProfiles);
72     }
73
74     /**
75      * @param string $name
76      * @param float  $duration
77      * @param bool   $isTemplate
78      * @param string $type
79      * @param string $templateName
80      * @param array  $subProfiles
81      *
82      * @return Twig_Profiler_Profile
83      */
84     private function generateProfile($name, $duration, $isTemplate, $type, $templateName, array $subProfiles = array())
85     {
86         $profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock();
87
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)));
98
99         return $profile;
100     }
101 }