Skip to content

Commit

Permalink
bug #16306 [DoctrineBridge] Fix issue which prevent the profiler to e…
Browse files Browse the repository at this point in the history
…xplain 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
  • Loading branch information
fabpot committed Oct 28, 2015
2 parents c7e772c + 3490e98 commit bca80ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Expand Up @@ -117,6 +117,9 @@ private function sanitizeQueries($connectionName, $queries)
private function sanitizeQuery($connectionName, $query)
{
$query['explainable'] = true;
if (null === $query['params']) {
$query['params'] = array();
}
if (!is_array($query['params'])) {
$query['params'] = array($query['params']);
}
Expand Down
Expand Up @@ -79,9 +79,25 @@ public function testCollectQueries($param, $types, $expected, $explainable)
$c = $this->createCollector($queries);
$c->collect(new Request(), new Response());

$collected_queries = $c->getQueries();
$this->assertEquals($expected, $collected_queries['default'][0]['params'][0]);
$this->assertEquals($explainable, $collected_queries['default'][0]['explainable']);
$collectedQueries = $c->getQueries();
$this->assertEquals($expected, $collectedQueries['default'][0]['params'][0]);
$this->assertEquals($explainable, $collectedQueries['default'][0]['explainable']);
}

public function testCollectQueryWithNoParams()
{
$queries = array(
array('sql' => 'SELECT * FROM table1', 'params' => array(), 'types' => array(), 'executionMS' => 1),
array('sql' => 'SELECT * FROM table1', 'params' => null, 'types' => null, 'executionMS' => 1),
);
$c = $this->createCollector($queries);
$c->collect(new Request(), new Response());

$collectedQueries = $c->getQueries();
$this->assertEquals(array(), $collectedQueries['default'][0]['params']);
$this->assertTrue($collectedQueries['default'][0]['explainable']);
$this->assertEquals(array(), $collectedQueries['default'][1]['params']);
$this->assertTrue($collectedQueries['default'][1]['explainable']);
}

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

$collected_queries = $c->getQueries();
$this->assertEquals($expected, $collected_queries['default'][0]['params'][0]);
$this->assertEquals($explainable, $collected_queries['default'][0]['explainable']);
$collectedQueries = $c->getQueries();
$this->assertEquals($expected, $collectedQueries['default'][0]['params'][0]);
$this->assertEquals($explainable, $collectedQueries['default'][0]['explainable']);
}

public function paramProvider()
Expand Down

0 comments on commit bca80ae

Please sign in to comment.