Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/Doctrine/Common/Persistence/Mapping/MappingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,14 @@ public static function invalidMappingFile($entityName, $fileName)
{
return new self("Invalid mapping file '$fileName' for class '$entityName'.");
}

/**
* @param string $className
*
* @return \Doctrine\Common\Persistence\Mapping\MappingException
*/
public static function nonExistingClass($className)
{
return new self("Class '$className' does not exists");
}
}
3 changes: 3 additions & 0 deletions lib/Doctrine/Common/Persistence/Mapping/ReflectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ interface ReflectionService
* Return an array of the parent classes (not interfaces) for the given class.
*
* @param string $class
*
* @throws \Doctrine\Common\Persistence\Mapping\MappingException
*
* @return array
*/
function getParentClasses($class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use ReflectionClass;
use ReflectionProperty;
use Doctrine\Common\Reflection\RuntimePublicReflectionProperty;
use Doctrine\Common\Persistence\Mapping\MappingException;

/**
* PHP Runtime Reflection Service
Expand All @@ -35,6 +36,10 @@ class RuntimeReflectionService implements ReflectionService
*/
public function getParentClasses($class)
{
if ( ! class_exists($class)) {
throw MappingException::nonExistingClass($class);
}

return class_parents($class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public function testGetMetadataFor()
$this->assertTrue($this->cmf->hasMetadataFor('stdClass'));
}

public function testGetMetadataForAbsentClass()
{
$this->setExpectedException('Doctrine\Common\Persistence\Mapping\MappingException');
$this->cmf->getMetadataFor(__NAMESPACE__ . '\AbsentClass');
}

public function testGetParentMetadata()
{
$metadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public function testGetParentClasses()
$this->assertTrue(count($classes) >= 1, "The test class ".__CLASS__." should have at least one parent.");
}

public function testGetParentClassesForAbsentClass()
{
$this->setExpectedException('Doctrine\Common\Persistence\Mapping\MappingException');
$this->reflectionService->getParentClasses(__NAMESPACE__ . '\AbsentClass');
}

public function testGetReflectionClass()
{
$class = $this->reflectionService->getClass(__CLASS__);
Expand Down