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 class Twig_Tests_Profiler_ProfileTest extends PHPUnit_Framework_TestCase
14 public function testConstructor()
16 $profile = new Twig_Profiler_Profile('template', 'type', 'name');
18 $this->assertEquals('template', $profile->getTemplate());
19 $this->assertEquals('type', $profile->getType());
20 $this->assertEquals('name', $profile->getName());
23 public function testIsRoot()
25 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
26 $this->assertTrue($profile->isRoot());
28 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::TEMPLATE);
29 $this->assertFalse($profile->isRoot());
32 public function testIsTemplate()
34 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::TEMPLATE);
35 $this->assertTrue($profile->isTemplate());
37 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
38 $this->assertFalse($profile->isTemplate());
41 public function testIsBlock()
43 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::BLOCK);
44 $this->assertTrue($profile->isBlock());
46 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
47 $this->assertFalse($profile->isBlock());
50 public function testIsMacro()
52 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::MACRO);
53 $this->assertTrue($profile->isMacro());
55 $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT);
56 $this->assertFalse($profile->isMacro());
59 public function testGetAddProfile()
61 $profile = new Twig_Profiler_Profile();
62 $profile->addProfile($a = new Twig_Profiler_Profile());
63 $profile->addProfile($b = new Twig_Profiler_Profile());
65 $this->assertSame(array($a, $b), $profile->getProfiles());
66 $this->assertSame(array($a, $b), iterator_to_array($profile));
69 public function testGetDuration()
71 $profile = new Twig_Profiler_Profile();
75 $this->assertTrue($profile->getDuration() > 0, sprintf('Expected duration > 0, got: %f', $profile->getDuration()));
78 public function testSerialize()
80 $profile = new Twig_Profiler_Profile('template', 'type', 'name');
81 $profile1 = new Twig_Profiler_Profile('template1', 'type1', 'name1');
82 $profile->addProfile($profile1);
86 $profile2 = unserialize(serialize($profile));
87 $profiles = $profile->getProfiles();
88 $this->assertCount(1, $profiles);
89 $profile3 = $profiles[0];
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());
96 $this->assertEquals($profile1->getTemplate(), $profile3->getTemplate());
97 $this->assertEquals($profile1->getType(), $profile3->getType());
98 $this->assertEquals($profile1->getName(), $profile3->getName());