Skip to content

Commit ed21c02

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [DoctrineBridge] Fix global query time calculation in profiler
2 parents e979087 + 1aa274a commit ed21c02

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

DataCollector/DoctrineDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function getQueries(): array
8585
return $this->data['queries'];
8686
}
8787

88-
public function getTime(): int
88+
public function getTime(): float
8989
{
9090
$time = 0;
9191
foreach ($this->data['queries'] as $queries) {

Tests/DataCollector/DoctrineDataCollectorTest.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,36 @@ public function testCollectTime()
9090
$this->assertEquals(3, $c->getTime());
9191
}
9292

93+
public function testCollectTimeWithFloatExecutionMS()
94+
{
95+
$queries = [
96+
['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 0.23],
97+
];
98+
$c = $this->createCollector($queries);
99+
$c->collect(new Request(), new Response());
100+
$c = unserialize(serialize($c));
101+
$this->assertEqualsWithDelta(0.23, $c->getTime(), .01);
102+
103+
$queries = [
104+
['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 1.02],
105+
['sql' => 'SELECT * FROM table2', 'params' => [], 'types' => [], 'executionMS' => 0.75],
106+
];
107+
$c = $this->createCollector($queries);
108+
$c->collect(new Request(), new Response());
109+
$c = unserialize(serialize($c));
110+
$this->assertEqualsWithDelta(1.77, $c->getTime(), .01);
111+
112+
$queries = [
113+
['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 0.15],
114+
['sql' => 'SELECT * FROM table2', 'params' => [], 'types' => [], 'executionMS' => 0.32],
115+
['sql' => 'SELECT * FROM table3', 'params' => [], 'types' => [], 'executionMS' => 0.07],
116+
];
117+
$c = $this->createCollector($queries);
118+
$c->collect(new Request(), new Response());
119+
$c = unserialize(serialize($c));
120+
$this->assertEqualsWithDelta(0.54, $c->getTime(), .01);
121+
}
122+
93123
public function testCollectQueryWithNoTypes()
94124
{
95125
$queries = [
@@ -248,7 +278,7 @@ private function createCollector(array $queries): DoctrineDataCollector
248278
$debugDataHolder->addQuery('default', $query);
249279

250280
if (isset($queryData['executionMS'])) {
251-
sleep($queryData['executionMS']);
281+
usleep($queryData['executionMS'] * 1000000);
252282
}
253283
$query->stop();
254284
}

0 commit comments

Comments
 (0)