Skip to content

Commit

Permalink
Merge pull request #236 from FabioBatSilva/DDC-1065
Browse files Browse the repository at this point in the history
[DDC-1065] Error messages
  • Loading branch information
guilhermeblanco committed Dec 22, 2011
2 parents 06de4e6 + c2cee0d commit ec58285
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public function close()
public function persist($entity)
{
if ( ! is_object($entity)) {
throw new \InvalidArgumentException(gettype($entity));
throw ORMInvalidArgumentException::invalidObject('EntityManager#persist()' , $entity);
}

$this->errorIfClosed();
Expand All @@ -507,7 +507,7 @@ public function persist($entity)
public function remove($entity)
{
if ( ! is_object($entity)) {
throw new \InvalidArgumentException(gettype($entity));
throw ORMInvalidArgumentException::invalidObject('EntityManager#remove()' , $entity);
}

$this->errorIfClosed();
Expand All @@ -524,7 +524,7 @@ public function remove($entity)
public function refresh($entity)
{
if ( ! is_object($entity)) {
throw new \InvalidArgumentException(gettype($entity));
throw ORMInvalidArgumentException::invalidObject('EntityManager#refresh()' , $entity);
}

$this->errorIfClosed();
Expand All @@ -544,7 +544,7 @@ public function refresh($entity)
public function detach($entity)
{
if ( ! is_object($entity)) {
throw new \InvalidArgumentException(gettype($entity));
throw ORMInvalidArgumentException::invalidObject('EntityManager#detach()' , $entity);
}

$this->unitOfWork->detach($entity);
Expand All @@ -561,7 +561,7 @@ public function detach($entity)
public function merge($entity)
{
if ( ! is_object($entity)) {
throw new \InvalidArgumentException(gettype($entity));
throw ORMInvalidArgumentException::invalidObject('EntityManager#merge()' , $entity);
}

$this->errorIfClosed();
Expand Down
6 changes: 6 additions & 0 deletions lib/Doctrine/ORM/ORMInvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ static public function detachedEntityCannot($entity, $operation)
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.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/ORM/EntityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ static public function dataMethodsAffectedByNoObjectArguments()

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

Expand Down

0 comments on commit ec58285

Please sign in to comment.