error messages
This commit is contained in:
parent
06de4e62a5
commit
c2cee0d6eb
@ -488,7 +488,7 @@ class EntityManager implements ObjectManager
|
||||
public function persist($entity)
|
||||
{
|
||||
if ( ! is_object($entity)) {
|
||||
throw new \InvalidArgumentException(gettype($entity));
|
||||
throw ORMInvalidArgumentException::invalidObject('EntityManager#persist()' , $entity);
|
||||
}
|
||||
|
||||
$this->errorIfClosed();
|
||||
@ -507,7 +507,7 @@ class EntityManager implements ObjectManager
|
||||
public function remove($entity)
|
||||
{
|
||||
if ( ! is_object($entity)) {
|
||||
throw new \InvalidArgumentException(gettype($entity));
|
||||
throw ORMInvalidArgumentException::invalidObject('EntityManager#remove()' , $entity);
|
||||
}
|
||||
|
||||
$this->errorIfClosed();
|
||||
@ -524,7 +524,7 @@ class EntityManager implements ObjectManager
|
||||
public function refresh($entity)
|
||||
{
|
||||
if ( ! is_object($entity)) {
|
||||
throw new \InvalidArgumentException(gettype($entity));
|
||||
throw ORMInvalidArgumentException::invalidObject('EntityManager#refresh()' , $entity);
|
||||
}
|
||||
|
||||
$this->errorIfClosed();
|
||||
@ -544,7 +544,7 @@ class EntityManager implements ObjectManager
|
||||
public function detach($entity)
|
||||
{
|
||||
if ( ! is_object($entity)) {
|
||||
throw new \InvalidArgumentException(gettype($entity));
|
||||
throw ORMInvalidArgumentException::invalidObject('EntityManager#detach()' , $entity);
|
||||
}
|
||||
|
||||
$this->unitOfWork->detach($entity);
|
||||
@ -561,7 +561,7 @@ class EntityManager implements ObjectManager
|
||||
public function merge($entity)
|
||||
{
|
||||
if ( ! is_object($entity)) {
|
||||
throw new \InvalidArgumentException(gettype($entity));
|
||||
throw ORMInvalidArgumentException::invalidObject('EntityManager#merge()' , $entity);
|
||||
}
|
||||
|
||||
$this->errorIfClosed();
|
||||
|
@ -94,6 +94,12 @@ class ORMInvalidArgumentException extends \InvalidArgumentException
|
||||
throw new self("A detached entity was found during " . $operation . " " . self::objToStr($entity));
|
||||
}
|
||||
|
||||
public static function invalidObject($context, $given, $parameterIndex = 1)
|
||||
{
|
||||
return new self($context .' expects parameter ' . $parameterIndex .
|
||||
' to be an entity object, '. gettype($given) . ' given.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to show an object as string.
|
||||
*
|
||||
|
@ -114,10 +114,10 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
/**
|
||||
* @dataProvider dataMethodsAffectedByNoObjectArguments
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @param string $methodName
|
||||
*/
|
||||
public function testThrowsExceptionOnNonObjectValues($methodName) {
|
||||
$this->setExpectedException('Doctrine\ORM\ORMInvalidArgumentException',
|
||||
'EntityManager#'.$methodName.'() expects parameter 1 to be an entity object, NULL given.');
|
||||
$this->_em->$methodName(null);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user