[Stopwatch] Add a reset method
This commit is contained in:
parent
411d9fa7a1
commit
7cda099663
@ -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__'));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user