Skip to content

Commit

Permalink
Add return value to measure() function. (#443)
Browse files Browse the repository at this point in the history
Change-Id: I0e0277a019545bae6b4a9854b915a83bcea6757a

Co-authored-by: vdauchy <vdauchy@summit-tech.ca>
  • Loading branch information
vdauchy and vdauchy committed May 6, 2020
1 parent 936807d commit 1a1605b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/DebugBar/DataCollector/TimeDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public function addMeasure($label, $start, $end, $params = array(), $collector =
* @param string $label
* @param \Closure $closure
* @param string|null $collector
* @return mixed
*/
public function measure($label, \Closure $closure, $collector = null)
{
Expand All @@ -142,6 +143,7 @@ public function measure($label, \Closure $closure, $collector = null)
$result = $closure();
$params = is_array($result) ? $result : array();
$this->stopMeasure($name, $params);
return $result;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/DebugBar/Tests/DataCollector/TimeDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ public function testCollect()
$this->assertTrue($data['duration'] > 0);
$this->assertCount(2, $data['measures']);
}

public function testMeasure()
{
$returned = $this->c->measure('bar', function() {
return 'returnedValue';
});
$m = $this->c->getMeasures();
$this->assertCount(1, $m);
$this->assertEquals('bar', $m[0]['label']);
$this->assertTrue($m[0]['start'] < $m[0]['end']);
$this->assertSame('returnedValue', $returned);
}
}

0 comments on commit 1a1605b

Please sign in to comment.