Skip to content

Commit 1a1605b

Browse files
vdauchyvdauchy
andauthored
Add return value to measure() function. (php-debugbar#443)
Change-Id: I0e0277a019545bae6b4a9854b915a83bcea6757a Co-authored-by: vdauchy <[email protected]>
1 parent 936807d commit 1a1605b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/DebugBar/DataCollector/TimeDataCollector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public function addMeasure($label, $start, $end, $params = array(), $collector =
134134
* @param string $label
135135
* @param \Closure $closure
136136
* @param string|null $collector
137+
* @return mixed
137138
*/
138139
public function measure($label, \Closure $closure, $collector = null)
139140
{
@@ -142,6 +143,7 @@ public function measure($label, \Closure $closure, $collector = null)
142143
$result = $closure();
143144
$params = is_array($result) ? $result : array();
144145
$this->stopMeasure($name, $params);
146+
return $result;
145147
}
146148

147149
/**

tests/DebugBar/Tests/DataCollector/TimeDataCollectorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,16 @@ public function testCollect()
4545
$this->assertTrue($data['duration'] > 0);
4646
$this->assertCount(2, $data['measures']);
4747
}
48+
49+
public function testMeasure()
50+
{
51+
$returned = $this->c->measure('bar', function() {
52+
return 'returnedValue';
53+
});
54+
$m = $this->c->getMeasures();
55+
$this->assertCount(1, $m);
56+
$this->assertEquals('bar', $m[0]['label']);
57+
$this->assertTrue($m[0]['start'] < $m[0]['end']);
58+
$this->assertSame('returnedValue', $returned);
59+
}
4860
}

0 commit comments

Comments
 (0)