Merge branch 'feature/#6136-better-exception-message-on-invalid-connection-object'
Close #6136
This commit is contained in:
commit
e7856f90d8
@ -860,7 +860,13 @@ use Doctrine\Common\Util\ClassUtils;
|
||||
}
|
||||
|
||||
if ( ! $connection instanceof Connection) {
|
||||
throw new \InvalidArgumentException("Invalid argument: " . $connection);
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf(
|
||||
'Invalid $connection argument of type %s given%s.',
|
||||
is_object($connection) ? get_class($connection) : gettype($connection),
|
||||
is_object($connection) ? '' : ': "' . $connection . '"'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($eventManager !== null && $connection->getEventManager() !== $eventManager) {
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
namespace Doctrine\Tests\ORM;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\ORM\Configuration;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Doctrine\ORM\ORMInvalidArgumentException;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
@ -72,9 +75,9 @@ class EntityManagerTest extends OrmTestCase
|
||||
{
|
||||
$rsm = new ResultSetMapping();
|
||||
$this->_em->getConfiguration()->addNamedNativeQuery('foo', 'SELECT foo', $rsm);
|
||||
|
||||
|
||||
$query = $this->_em->createNamedNativeQuery('foo');
|
||||
|
||||
|
||||
$this->assertInstanceOf('Doctrine\ORM\NativeQuery', $query);
|
||||
}
|
||||
|
||||
@ -116,14 +119,14 @@ class EntityManagerTest extends OrmTestCase
|
||||
$this->assertInstanceOf('Doctrine\ORM\Query', $q);
|
||||
$this->assertEquals('SELECT 1', $q->getDql());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers Doctrine\ORM\EntityManager::createNamedQuery
|
||||
*/
|
||||
public function testCreateNamedQuery()
|
||||
{
|
||||
$this->_em->getConfiguration()->addNamedQuery('foo', 'SELECT 1');
|
||||
|
||||
|
||||
$query = $this->_em->createNamedQuery('foo');
|
||||
$this->assertInstanceOf('Doctrine\ORM\Query', $query);
|
||||
$this->assertEquals('SELECT 1', $query->getDql());
|
||||
@ -204,4 +207,14 @@ class EntityManagerTest extends OrmTestCase
|
||||
$this->assertSame($this->_em, $em);
|
||||
return 'callback';
|
||||
}
|
||||
|
||||
public function testCreateInvalidConnection()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Invalid $connection argument of type integer given: "1".');
|
||||
|
||||
$config = new Configuration();
|
||||
$config->setMetadataDriverImpl($this->createMock(MappingDriver::class));
|
||||
EntityManager::create(1, $config);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user