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
This commit is contained in:
Fabien Potencier 2015-10-27 19:18:52 -07:00
commit bca80ae820
2 changed files with 25 additions and 6 deletions

View File

@ -117,6 +117,9 @@ class DoctrineDataCollector extends DataCollector
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']);
}

View File

@ -79,9 +79,25 @@ class DoctrineDataCollectorTest extends \PHPUnit_Framework_TestCase
$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']);
}
/**
@ -96,9 +112,9 @@ class DoctrineDataCollectorTest extends \PHPUnit_Framework_TestCase
$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()