[Stopwatch] Fix checking started events
This commit is contained in:
parent
d060c40503
commit
b6265427c6
@ -258,7 +258,7 @@ class Section
|
||||
*/
|
||||
public function isEventStarted($name)
|
||||
{
|
||||
return isset($this->events[$name]);
|
||||
return isset($this->events[$name]) && $this->events[$name]->isStarted();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,6 +106,16 @@ class StopwatchEvent
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the event was started
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isStarted()
|
||||
{
|
||||
return !empty($this->started);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the current period and then starts a new one.
|
||||
*
|
||||
|
@ -91,6 +91,19 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase
|
||||
$event->stop();
|
||||
}
|
||||
|
||||
public function testIsStarted()
|
||||
{
|
||||
$event = new StopwatchEvent(microtime(true) * 1000);
|
||||
$event->start();
|
||||
$this->assertTrue($event->isStarted());
|
||||
}
|
||||
|
||||
public function testIsNotStarted()
|
||||
{
|
||||
$event = new StopwatchEvent(microtime(true) * 1000);
|
||||
$this->assertFalse($event->isStarted());
|
||||
}
|
||||
|
||||
public function testEnsureStopped()
|
||||
{
|
||||
// this also test overlap between two periods
|
||||
|
@ -44,6 +44,28 @@ class StopwatchTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($stopwatch->isStarted('foo'));
|
||||
}
|
||||
|
||||
public function testIsNotStartedEvent()
|
||||
{
|
||||
$stopwatch = new Stopwatch();
|
||||
|
||||
$sections = new \ReflectionProperty('Symfony\Component\Stopwatch\Stopwatch', 'sections');
|
||||
$sections->setAccessible(true);
|
||||
$section = $sections->getValue($stopwatch);
|
||||
|
||||
$events = new \ReflectionProperty('Symfony\Component\Stopwatch\Section', 'events');
|
||||
$events->setAccessible(true);
|
||||
$events->setValue(
|
||||
end($section),
|
||||
array(
|
||||
'foo' =>
|
||||
$this->getMockBuilder('Symfony\Component\Stopwatch\StopwatchEvent')
|
||||
->setConstructorArgs([microtime(true) * 1000])
|
||||
->getMock())
|
||||
);
|
||||
|
||||
$this->assertFalse($stopwatch->isStarted('foo'));
|
||||
}
|
||||
|
||||
public function testStop()
|
||||
{
|
||||
$stopwatch = new Stopwatch();
|
||||
|
Reference in New Issue
Block a user