Skip to content

Commit

Permalink
Actions done:
Browse files Browse the repository at this point in the history
- Change exception to MappingException
- Change test to use setExpectedException instead of @ExpectedException
- Update phpdoc of loadMetadata and fix CS
  • Loading branch information
eduardosoliv committed May 8, 2013
1 parent 9ac67af commit b8479cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Expand Up @@ -20,7 +20,8 @@
namespace Doctrine\Common\Persistence\Mapping;

use Doctrine\Common\Cache\Cache,
Doctrine\Common\Util\ClassUtils;
Doctrine\Common\Util\ClassUtils,
Doctrine\Common\Persistence\Mapping\MappingException;

/**
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
Expand Down Expand Up @@ -268,14 +269,14 @@ protected function getParentClasses($name)
*
* @param string $name The name of the class for which the metadata should get loaded.
*
* @throws MappingException
*
* @return array
*/
protected function loadMetadata($name)
{
if ( !class_exists($name) ) {
throw new \RuntimeException(
sprintf('Failed to load metadata for class "%s" because class does not exists.', $name)
);
if ( ! class_exists($name)) {
throw MappingException::nonExistingClass($name);
}

if ( ! $this->initialized) {
Expand Down
9 changes: 9 additions & 0 deletions lib/Doctrine/Common/Persistence/Mapping/MappingException.php
Expand Up @@ -83,4 +83,13 @@ public static function invalidMappingFile($entityName, $fileName)
{
return new self("Invalid mapping file '$fileName' for class '$entityName'.");
}

/**
* @param string $className
* @return MappingException
*/
public static function nonExistingClass($className)
{
return new self("Class '$className' does not exists");
}
}
Expand Up @@ -39,11 +39,9 @@ public function testGetMetadataFor()
$this->assertTrue($this->cmf->hasMetadataFor('stdClass'));
}

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

Expand Down

0 comments on commit b8479cb

Please sign in to comment.