[DoctrineBridge] catch errors while converting to db values in data collector
This commit is contained in:
parent
e4a7fd8eed
commit
61c4531292
@ -13,6 +13,7 @@ namespace Symfony\Bridge\Doctrine\DataCollector;
|
|||||||
|
|
||||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||||
use Doctrine\DBAL\Logging\DebugStack;
|
use Doctrine\DBAL\Logging\DebugStack;
|
||||||
|
use Doctrine\DBAL\Types\ConversionException;
|
||||||
use Doctrine\DBAL\Types\Type;
|
use Doctrine\DBAL\Types\Type;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
@ -132,7 +133,14 @@ class DoctrineDataCollector extends DataCollector
|
|||||||
}
|
}
|
||||||
if ($type instanceof Type) {
|
if ($type instanceof Type) {
|
||||||
$query['types'][$j] = $type->getBindingType();
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Bridge\Doctrine\Tests\DataCollector;
|
namespace Symfony\Bridge\Doctrine\Tests\DataCollector;
|
||||||
|
|
||||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||||
|
use Doctrine\DBAL\Version;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
|
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@ -120,7 +121,7 @@ class DoctrineDataCollectorTest extends TestCase
|
|||||||
|
|
||||||
public function paramProvider()
|
public function paramProvider()
|
||||||
{
|
{
|
||||||
return array(
|
$tests = array(
|
||||||
array('some value', array(), 'some value', true),
|
array('some value', array(), 'some value', true),
|
||||||
array(1, array(), 1, true),
|
array(1, array(), 1, true),
|
||||||
array(true, array(), true, true),
|
array(true, array(), true, true),
|
||||||
@ -129,6 +130,13 @@ class DoctrineDataCollectorTest extends TestCase
|
|||||||
array(fopen(__FILE__, 'r'), array(), 'Resource(stream)', false),
|
array(fopen(__FILE__, 'r'), array(), 'Resource(stream)', false),
|
||||||
array(new \SplFileInfo(__FILE__), array(), 'Object(SplFileInfo)', 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)
|
private function createCollector($queries)
|
||||||
|
Reference in New Issue
Block a user