Permalink
Browse files

Merge pull request #275 from entering/avoid-warning-ref-class-parents

RuntimeReflectionService - throw exception instead of php warning
  • Loading branch information...
2 parents 7eea788 + 660900a commit ce87784a45f93c73a4035748fd98ecbbda3098fb @beberlei beberlei committed May 9, 2013
@@ -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");
+ }
}
@@ -33,6 +33,9 @@
* 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);
@@ -22,6 +22,7 @@
use ReflectionClass;
use ReflectionProperty;
use Doctrine\Common\Reflection\RuntimePublicReflectionProperty;
+use Doctrine\Common\Persistence\Mapping\MappingException;
/**
* PHP Runtime Reflection Service
@@ -35,6 +36,10 @@ class RuntimeReflectionService implements ReflectionService
*/
public function getParentClasses($class)
{
+ if ( ! class_exists($class)) {
+ throw MappingException::nonExistingClass($class);
+ }
+
return class_parents($class);
}
@@ -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');
@@ -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__);

0 comments on commit ce87784

Please sign in to comment.