From 1a1605b8e9bacb34cc0c6278206d699772e1d372 Mon Sep 17 00:00:00 2001 From: VictorDauchy Date: Wed, 6 May 2020 03:06:27 -0400 Subject: [PATCH] Add return value to measure() function. (#443) Change-Id: I0e0277a019545bae6b4a9854b915a83bcea6757a Co-authored-by: vdauchy --- src/DebugBar/DataCollector/TimeDataCollector.php | 2 ++ .../Tests/DataCollector/TimeDataCollectorTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/DebugBar/DataCollector/TimeDataCollector.php b/src/DebugBar/DataCollector/TimeDataCollector.php index 27a2e1a2..5794ccd7 100644 --- a/src/DebugBar/DataCollector/TimeDataCollector.php +++ b/src/DebugBar/DataCollector/TimeDataCollector.php @@ -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) { @@ -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; } /** diff --git a/tests/DebugBar/Tests/DataCollector/TimeDataCollectorTest.php b/tests/DebugBar/Tests/DataCollector/TimeDataCollectorTest.php index 1824bb10..4ee76c42 100644 --- a/tests/DebugBar/Tests/DataCollector/TimeDataCollectorTest.php +++ b/tests/DebugBar/Tests/DataCollector/TimeDataCollectorTest.php @@ -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); + } }