Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bca80ae

Browse filesBrowse files
committed
bug #16306 [DoctrineBridge] Fix issue which prevent the profiler to explain a query (Baachi)
This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #16306). Discussion ---------- [DoctrineBridge] Fix issue which prevent the profiler to explain a query | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT We currently develop a application which only use the doctrine/dbal and not the orm. And we run into a issue that the profiler can't explained any query. This is because the `SQLLogger` will pass `null` instead of an empty array. And the `sanitizeQuery` method will currently transform this to `array(null)` which leads to an error. I created an fork, so everyone can reproduce this. https://github.com/Baachi/symfony-standard Commits ------- 3490e98 [DoctrineBridge] Fix issue which prevent the profiler to explain a query
2 parents c7e772c + 3490e98 commit bca80ae
Copy full SHA for bca80ae

File tree

2 files changed

+25
-6
lines changed
Filter options

2 files changed

+25
-6
lines changed

‎src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ private function sanitizeQueries($connectionName, $queries)
117117
private function sanitizeQuery($connectionName, $query)
118118
{
119119
$query['explainable'] = true;
120+
if (null === $query['params']) {
121+
$query['params'] = array();
122+
}
120123
if (!is_array($query['params'])) {
121124
$query['params'] = array($query['params']);
122125
}

‎src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php
+22-6Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,25 @@ public function testCollectQueries($param, $types, $expected, $explainable)
7979
$c = $this->createCollector($queries);
8080
$c->collect(new Request(), new Response());
8181

82-
$collected_queries = $c->getQueries();
83-
$this->assertEquals($expected, $collected_queries['default'][0]['params'][0]);
84-
$this->assertEquals($explainable, $collected_queries['default'][0]['explainable']);
82+
$collectedQueries = $c->getQueries();
83+
$this->assertEquals($expected, $collectedQueries['default'][0]['params'][0]);
84+
$this->assertEquals($explainable, $collectedQueries['default'][0]['explainable']);
85+
}
86+
87+
public function testCollectQueryWithNoParams()
88+
{
89+
$queries = array(
90+
array('sql' => 'SELECT * FROM table1', 'params' => array(), 'types' => array(), 'executionMS' => 1),
91+
array('sql' => 'SELECT * FROM table1', 'params' => null, 'types' => null, 'executionMS' => 1),
92+
);
93+
$c = $this->createCollector($queries);
94+
$c->collect(new Request(), new Response());
95+
96+
$collectedQueries = $c->getQueries();
97+
$this->assertEquals(array(), $collectedQueries['default'][0]['params']);
98+
$this->assertTrue($collectedQueries['default'][0]['explainable']);
99+
$this->assertEquals(array(), $collectedQueries['default'][1]['params']);
100+
$this->assertTrue($collectedQueries['default'][1]['explainable']);
85101
}
86102

87103
/**
@@ -96,9 +112,9 @@ public function testSerialization($param, $types, $expected, $explainable)
96112
$c->collect(new Request(), new Response());
97113
$c = unserialize(serialize($c));
98114

99-
$collected_queries = $c->getQueries();
100-
$this->assertEquals($expected, $collected_queries['default'][0]['params'][0]);
101-
$this->assertEquals($explainable, $collected_queries['default'][0]['explainable']);
115+
$collectedQueries = $c->getQueries();
116+
$this->assertEquals($expected, $collectedQueries['default'][0]['params'][0]);
117+
$this->assertEquals($explainable, $collectedQueries['default'][0]['explainable']);
102118
}
103119

104120
public function paramProvider()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.