1
0
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:
VictorDauchy 2020-05-06 03:06:27 -04:00 committed by GitHub
parent 936807d1e3
commit 1a1605b8e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -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;
}
/**

View File

@ -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);
}
}