Skip to content

Commit

Permalink
Merge branch '4.3' into 4.4
Browse files Browse the repository at this point in the history
* 4.3: (26 commits)
  [Console] Fix #33915, Detect dimensions using mode CON if vt100 is supported
  [HttpKernel][DataCollectorInterface] Ease compatibility
  Add tests to ensure defaultLocale is properly passed to the URL generator
  [DependencyInjection] Fix broken references in tests
  [HttpClient] Retry safe requests when then fail before the body arrives
  Avoid using of kernel after shutdown
  Simplify PHP CS Fixer configuration
  [PropertyInfo] Fixed type extraction for nullable collections of non-nullable elements
  [FrameworkBundle] [HttpKernel] fixed correct EOL and EOM month
  [Serializer] Fix property name usage for denormalization
  Name test accordingly to the tested class
  Fix MockFileSessionStorageTest::sessionDir being used after it's unset
  bumped Symfony version to 4.3.7
  updated VERSION for 4.3.6
  updated CHANGELOG for 4.3.6
  bumped Symfony version to 3.4.34
  updated VERSION for 3.4.33
  update CONTRIBUTORS for 3.4.33
  updated CHANGELOG for 3.4.33
  [HttpClient] Fix perf issue when doing thousands of requests with curl
  ...
  • Loading branch information
nicolas-grekas committed Nov 5, 2019
2 parents 1c0f661 + e96c259 commit 5745b51
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
18 changes: 12 additions & 6 deletions StopwatchEvent.php
Expand Up @@ -154,7 +154,15 @@ public function getPeriods()
*/
public function getStartTime()
{
return isset($this->periods[0]) ? $this->periods[0]->getStartTime() : 0;
if (isset($this->periods[0])) {
return $this->periods[0]->getStartTime();
}

if ($this->started) {
return $this->started[0];
}

return 0;
}

/**
Expand All @@ -177,12 +185,10 @@ public function getEndTime()
public function getDuration()
{
$periods = $this->periods;
$stopped = \count($periods);
$left = \count($this->started) - $stopped;
$left = \count($this->started);

for ($i = 0; $i < $left; ++$i) {
$index = $stopped + $i;
$periods[] = new StopwatchPeriod($this->started[$index], $this->getNow(), $this->morePrecision);
for ($i = $left - 1; $i >= 0; --$i) {
$periods[] = new StopwatchPeriod($this->started[$i], $this->getNow(), $this->morePrecision);
}

$total = 0;
Expand Down
40 changes: 39 additions & 1 deletion Tests/StopwatchEventTest.php
Expand Up @@ -99,8 +99,25 @@ public function testDurationBeforeStop()
$event->stop();
usleep(50000);
$event->start();
usleep(100000);
$this->assertEqualsWithDelta(100, $event->getDuration(), self::DELTA);
usleep(100000);
$this->assertEqualsWithDelta(200, $event->getDuration(), self::DELTA);
}

public function testDurationWithMultipleStarts()
{
$event = new StopwatchEvent(microtime(true) * 1000);
$event->start();
usleep(100000);
$event->start();
usleep(100000);
$this->assertEqualsWithDelta(300, $event->getDuration(), self::DELTA);
$event->stop();
$this->assertEqualsWithDelta(300, $event->getDuration(), self::DELTA);
usleep(100000);
$this->assertEqualsWithDelta(400, $event->getDuration(), self::DELTA);
$event->stop();
$this->assertEqualsWithDelta(400, $event->getDuration(), self::DELTA);
}

public function testStopWithoutStart()
Expand Down Expand Up @@ -152,6 +169,27 @@ public function testStartTime()
$this->assertEqualsWithDelta(0, $event->getStartTime(), self::DELTA);
}

public function testStartTimeWhenStartedLater()
{
$event = new StopwatchEvent(microtime(true) * 1000);
usleep(100000);
$this->assertLessThanOrEqual(0.5, $event->getStartTime());

$event = new StopwatchEvent(microtime(true) * 1000);
usleep(100000);
$event->start();
$event->stop();
$this->assertLessThanOrEqual(101, $event->getStartTime());

$event = new StopwatchEvent(microtime(true) * 1000);
usleep(100000);
$event->start();
usleep(100000);
$this->assertEqualsWithDelta(100, $event->getStartTime(), self::DELTA);
$event->stop();
$this->assertEqualsWithDelta(100, $event->getStartTime(), self::DELTA);
}

public function testHumanRepresentation()
{
$event = new StopwatchEvent(microtime(true) * 1000);
Expand Down

0 comments on commit 5745b51

Please sign in to comment.