Use ORMException instead of a default exception
This commit is contained in:
parent
2a7d21ad18
commit
be4aafd4f6
@ -101,7 +101,7 @@ class ORMException extends Exception
|
||||
return new self("Unrecognized field: $field");
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $association
|
||||
@ -340,4 +340,16 @@ class ORMException extends Exception
|
||||
{
|
||||
return new self("Can't use IN operator on entities that have composite keys.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a given entityName hasn't the good type
|
||||
*
|
||||
* @param mixed $entityName The given entity (which shouldn't be a string)
|
||||
*
|
||||
* @return ORMException
|
||||
*/
|
||||
public static function invalidEntityName($entityName)
|
||||
{
|
||||
return new self(sprintf('Entity name must be a string, %s given', gettype($entityName)));
|
||||
}
|
||||
}
|
||||
|
@ -2364,7 +2364,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
public function clear($entityName = null)
|
||||
{
|
||||
if ($entityName !== null && !is_string($entityName)) {
|
||||
throw new \InvalidArgumentException(sprintf('Argument 1 passed to %s() must be a string, %s given', __METHOD__, gettype($entityName)));
|
||||
throw ORMException::invalidEntityName($entityName);
|
||||
}
|
||||
|
||||
if ($entityName === null) {
|
||||
|
@ -8,6 +8,7 @@ use Doctrine\Common\PropertyChangedListener;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\ORMInvalidArgumentException;
|
||||
use Doctrine\ORM\UnitOfWork;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Doctrine\Tests\Mocks\ConnectionMock;
|
||||
use Doctrine\Tests\Mocks\DriverMock;
|
||||
use Doctrine\Tests\Mocks\EntityManagerMock;
|
||||
@ -351,7 +352,7 @@ class UnitOfWorkTest extends OrmTestCase
|
||||
|
||||
public function testClearManagerWithObject()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectException(ORMException::class);
|
||||
$this->expectExceptionMessage('must be a string');
|
||||
|
||||
$entity = new Country(456, 'United Kingdom');
|
||||
|
Loading…
x
Reference in New Issue
Block a user