From 017a7d889f109d9501808080d1b13961348c87f9 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Thu, 15 Dec 2011 17:12:01 -0200 Subject: [PATCH] Fixed DDC-1468 --- .../ORM/Mapping/Driver/AbstractFileDriver.php | 3 +++ lib/Doctrine/ORM/Mapping/MappingException.php | 5 +++++ .../Tests/ORM/Mapping/XmlMappingDriverTest.php | 11 +++++++++++ .../Tests/ORM/Mapping/YamlMappingDriverTest.php | 11 +++++++++++ ...ts.Models.Generic.SerializationModel.dcm.xml | 17 +++++++++++++++++ ...ts.Models.Generic.SerializationModel.dcm.yml | 13 +++++++++++++ 6 files changed, 60 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php index 457b7cda7..a92432db8 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php @@ -118,6 +118,9 @@ abstract class AbstractFileDriver implements Driver { $result = $this->_loadMappingFile($this->_findMappingFile($className)); + if(!isset($result[$className])){ + throw MappingException::invalidMappingFile($className, str_replace('\\', '.', $className) . $this->_fileExtension); + } return $result[$className]; } diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index 014714bf8..bf8da82e6 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -67,6 +67,11 @@ class MappingException extends \Doctrine\ORM\ORMException { return new self("No mapping file found named '$fileName' for class '$entityName'."); } + + public static function invalidMappingFile($entityName, $fileName) + { + return new self("Invalid mapping file '$fileName' for class '$entityName'."); + } public static function mappingNotFound($className, $fieldName) { diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 9ba8748f4..980a720df 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -51,6 +51,17 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest $this->assertTrue($class->associationMappings['article']['id']); } + /** + * @group DDC-1468 + * + * @expectedException Doctrine\ORM\Mapping\MappingException + * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'. + */ + public function testInvalidMappingFileException() + { + $this->createClassMetadata('Doctrine\Tests\Models\Generic\SerializationModel'); + } + /** * @param string $xmlMappingFile * @dataProvider dataValidSchema diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index 34c3fa810..2757259a4 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -43,4 +43,15 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest $this->assertEquals('Doctrine\Tests\Models\DirectoryTree\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']); } + /** + * @group DDC-1468 + * + * @expectedException Doctrine\ORM\Mapping\MappingException + * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'. + */ + public function testInvalidMappingFileException() + { + $this->createClassMetadata('Doctrine\Tests\Models\Generic\SerializationModel'); + } + } diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml new file mode 100644 index 000000000..36af855f2 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml new file mode 100644 index 000000000..64f74b55f --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml @@ -0,0 +1,13 @@ +\stdClass: + type: entity + id: + id: + type: integer + unsigned: true + generator: + strategy: AUTO + fields: + array: + type: array + object: + type: object \ No newline at end of file