diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php index 38c5af4734..65df5c5ea6 100644 --- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php +++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php @@ -13,6 +13,7 @@ namespace Symfony\Bridge\Doctrine\DataCollector; use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\DBAL\Logging\DebugStack; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -132,7 +133,14 @@ class DoctrineDataCollector extends DataCollector } if ($type instanceof Type) { $query['types'][$j] = $type->getBindingType(); - $param = $type->convertToDatabaseValue($param, $this->registry->getConnection($connectionName)->getDatabasePlatform()); + try { + $param = $type->convertToDatabaseValue($param, $this->registry->getConnection($connectionName)->getDatabasePlatform()); + } catch (\TypeError $e) { + // Error thrown while processing params, query is not explainable. + $query['explainable'] = false; + } catch (ConversionException $e) { + $query['explainable'] = false; + } } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php index 7557390bc6..f968bbd257 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\Doctrine\Tests\DataCollector; use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Version; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector; use Symfony\Component\HttpFoundation\Request; @@ -120,7 +121,7 @@ class DoctrineDataCollectorTest extends TestCase public function paramProvider() { - return array( + $tests = array( array('some value', array(), 'some value', true), array(1, array(), 1, true), array(true, array(), true, true), @@ -129,6 +130,13 @@ class DoctrineDataCollectorTest extends TestCase array(fopen(__FILE__, 'r'), array(), 'Resource(stream)', false), array(new \SplFileInfo(__FILE__), array(), 'Object(SplFileInfo)', false), ); + + if (version_compare(Version::VERSION, '2.6', '>=')) { + $tests[] = array('this is not a date', array('date'), 'this is not a date', false); + $tests[] = array(new \stdClass(), array('date'), 'Object(stdClass)', false); + } + + return $tests; } private function createCollector($queries)