[Stopwatch] Add a reset method

This commit is contained in:
Jose Gonzalez 2017-06-24 11:52:11 +01:00
parent 411d9fa7a1
commit 7cda099663
2 changed files with 21 additions and 1 deletions

View File

@ -30,7 +30,7 @@ class Stopwatch
public function __construct()
{
$this->sections = $this->activeSections = array('__root__' => new Section('__root__'));
$this->reset();
}
/**
@ -156,4 +156,12 @@ class Stopwatch
{
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__'));
}
}

View File

@ -153,4 +153,16 @@ class StopwatchTest extends TestCase
$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);
}
}