diff --git a/src/Symfony/Component/Stopwatch/Stopwatch.php b/src/Symfony/Component/Stopwatch/Stopwatch.php index 8ad93165bfd74..562f220f673b1 100644 --- a/src/Symfony/Component/Stopwatch/Stopwatch.php +++ b/src/Symfony/Component/Stopwatch/Stopwatch.php @@ -30,7 +30,7 @@ class Stopwatch public function __construct() { - $this->sections = $this->activeSections = array('__root__' => new Section('__root__')); + $this->reset(); } /** @@ -156,4 +156,12 @@ public function getSectionEvents($id) { return isset($this->sections[$id]) ? $this->sections[$id]->getEvents() : array(); } + + /** + * Resets the stopwatch to its original state. + */ + public function reset() + { + $this->sections = $this->activeSections = array('__root__' => new Section('__root__')); + } } diff --git a/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php b/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php index f7d9171d8bc04..519803d9908d2 100644 --- a/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php +++ b/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php @@ -153,4 +153,16 @@ public function testReopenANewSectionShouldThrowAnException() $stopwatch = new Stopwatch(); $stopwatch->openSection('section'); } + + public function testReset() + { + $stopwatch = new Stopwatch(); + + $stopwatch->openSection(); + $stopwatch->start('foo', 'cat'); + + $stopwatch->reset(); + + $this->assertEquals(new Stopwatch(), $stopwatch); + } }