Skip to content

Commit

Permalink
feature #2560 Added pssibility to reset the profiler (derrabus)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.x branch.

Discussion
----------

Added pssibility to reset the profiler

In order to implement symfony/symfony#18244 properly, I needed the ability to reset a Twig profile.

Commits
-------

ea922bb Added pssibility to reset the profiler.
  • Loading branch information
fabpot committed Sep 27, 2017
2 parents cd06d3c + ea922bb commit 70e735e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Twig/Profiler/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ public function leave()
);
}

public function reset()
{
$this->starts = $this->ends = $this->profiles = array();
$this->enter();
}

public function getIterator()
{
return new ArrayIterator($this->profiles);
Expand Down
10 changes: 10 additions & 0 deletions test/Twig/Tests/Profiler/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,14 @@ public function testSerialize()
$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());
}
}

0 comments on commit 70e735e

Please sign in to comment.