merged branch Olden/issue_7639 (PR #7691)
This PR was squashed before being merged into the master branch (closes #7691).
Discussion
----------
[Stopwatch] Fix checking started events
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #7639, #7653
| License | MIT
Stopwatch component return true from isStarted method, when StopwatchEvent was added but not started.
Commits
-------
b626542
[Stopwatch] Fix checking started events
This commit is contained in:
commit
b42e4b0284
|
@ -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