diff --git a/lib/Twig/Profiler/Profile.php b/lib/Twig/Profiler/Profile.php index 60b9103c8..3fdc1a8ae 100644 --- a/lib/Twig/Profiler/Profile.php +++ b/lib/Twig/Profiler/Profile.php @@ -145,6 +145,12 @@ class Twig_Profiler_Profile implements IteratorAggregate, Serializable ); } + public function reset() + { + $this->starts = $this->ends = $this->profiles = array(); + $this->enter(); + } + public function getIterator() { return new ArrayIterator($this->profiles); diff --git a/test/Twig/Tests/Profiler/ProfileTest.php b/test/Twig/Tests/Profiler/ProfileTest.php index 0bebdcd45..08db96a90 100644 --- a/test/Twig/Tests/Profiler/ProfileTest.php +++ b/test/Twig/Tests/Profiler/ProfileTest.php @@ -97,4 +97,14 @@ class Twig_Tests_Profiler_ProfileTest extends \PHPUnit\Framework\TestCase $this->assertEquals($profile1->getType(), $profile3->getType()); $this->assertEquals($profile1->getName(), $profile3->getName()); } + + public function testReset() + { + $profile = new Twig_Profiler_Profile(); + usleep(1); + $profile->leave(); + $profile->reset(); + + $this->assertEquals(0, $profile->getDuration()); + } }