ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ProfileTest.php
Go to the documentation of this file.
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
12class Twig_Tests_Profiler_ProfileTest extends \PHPUnit\Framework\TestCase
13{
14 public function testConstructor()
15 {
16 $profile = new Twig_Profiler_Profile('template', 'type', 'name');
17
18 $this->assertEquals('template', $profile->getTemplate());
19 $this->assertEquals('type', $profile->getType());
20 $this->assertEquals('name', $profile->getName());
21 }
22
23 public function testIsRoot()
24 {
25 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
26 $this->assertTrue($profile->isRoot());
27
29 $this->assertFalse($profile->isRoot());
30 }
31
32 public function testIsTemplate()
33 {
35 $this->assertTrue($profile->isTemplate());
36
37 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
38 $this->assertFalse($profile->isTemplate());
39 }
40
41 public function testIsBlock()
42 {
43 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::BLOCK);
44 $this->assertTrue($profile->isBlock());
45
46 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
47 $this->assertFalse($profile->isBlock());
48 }
49
50 public function testIsMacro()
51 {
52 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::MACRO);
53 $this->assertTrue($profile->isMacro());
54
55 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
56 $this->assertFalse($profile->isMacro());
57 }
58
59 public function testGetAddProfile()
60 {
61 $profile = new Twig_Profiler_Profile();
62 $profile->addProfile($a = new Twig_Profiler_Profile());
63 $profile->addProfile($b = new Twig_Profiler_Profile());
64
65 $this->assertSame(array($a, $b), $profile->getProfiles());
66 $this->assertSame(array($a, $b), iterator_to_array($profile));
67 }
68
69 public function testGetDuration()
70 {
71 $profile = new Twig_Profiler_Profile();
72 usleep(1);
73 $profile->leave();
74
75 $this->assertTrue($profile->getDuration() > 0, sprintf('Expected duration > 0, got: %f', $profile->getDuration()));
76 }
77
78 public function testSerialize()
79 {
80 $profile = new Twig_Profiler_Profile('template', 'type', 'name');
81 $profile1 = new Twig_Profiler_Profile('template1', 'type1', 'name1');
82 $profile->addProfile($profile1);
83 $profile->leave();
84 $profile1->leave();
85
86 $profile2 = unserialize(serialize($profile));
87 $profiles = $profile->getProfiles();
88 $this->assertCount(1, $profiles);
89 $profile3 = $profiles[0];
90
91 $this->assertEquals($profile->getTemplate(), $profile2->getTemplate());
92 $this->assertEquals($profile->getType(), $profile2->getType());
93 $this->assertEquals($profile->getName(), $profile2->getName());
94 $this->assertEquals($profile->getDuration(), $profile2->getDuration());
95
96 $this->assertEquals($profile1->getTemplate(), $profile3->getTemplate());
97 $this->assertEquals($profile1->getType(), $profile3->getType());
98 $this->assertEquals($profile1->getName(), $profile3->getName());
99 }
100
101 public function testReset()
102 {
103 $profile = new Twig_Profiler_Profile();
104 usleep(1);
105 $profile->leave();
106 $profile->reset();
107
108 $this->assertEquals(0, $profile->getDuration());
109 }
110}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.