mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-01-16 21:08:34 +01:00
Add return value to measure() function. (#443)
Change-Id: I0e0277a019545bae6b4a9854b915a83bcea6757a Co-authored-by: vdauchy <vdauchy@summit-tech.ca>
This commit is contained in:
parent
936807d1e3
commit
1a1605b8e9
@ -134,6 +134,7 @@ class TimeDataCollector extends DataCollector implements Renderable
|
||||
* @param string $label
|
||||
* @param \Closure $closure
|
||||
* @param string|null $collector
|
||||
* @return mixed
|
||||
*/
|
||||
public function measure($label, \Closure $closure, $collector = null)
|
||||
{
|
||||
@ -142,6 +143,7 @@ class TimeDataCollector extends DataCollector implements Renderable
|
||||
$result = $closure();
|
||||
$params = is_array($result) ? $result : array();
|
||||
$this->stopMeasure($name, $params);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,4 +45,16 @@ class TimeDataCollectorTest extends DebugBarTestCase
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user