1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Use ORMException instead of a default exception

This commit is contained in:
Jeremy Benoist 2016-11-26 23:12:09 +01:00 committed by Marco Pivetta
parent 2a7d21ad18
commit be4aafd4f6
3 changed files with 16 additions and 3 deletions

View File

@ -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)));
}
}

View File

@ -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) {

View File

@ -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');