diff --git a/tests/Doctrine/Tests/ORM/Mapping/AllTests.php b/tests/Doctrine/Tests/ORM/Mapping/AllTests.php index 47d506a3a..7a0285bc3 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AllTests.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AllTests.php @@ -20,8 +20,7 @@ class AllTests $suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Orm Mapping'); $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\XmlDriverTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\YamlDriverTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\MappingDriverTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataFactoryTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataLoadEventTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\BasicInheritanceMappingTest'); diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php similarity index 61% rename from tests/Doctrine/Tests/ORM/Mapping/YamlDriverTest.php rename to tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php index 92bb15420..fc0f93794 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php @@ -2,17 +2,31 @@ namespace Doctrine\Tests\ORM\Mapping; -use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Mapping\Driver\YamlDriver; +use Doctrine\ORM\Mapping\ClassMetadata, + Doctrine\ORM\Mapping\Driver\XmlDriver, + Doctrine\ORM\Mapping\Driver\YamlDriver; -require_once __DIR__ . '/yaml/User.php'; require_once __DIR__ . '/../../TestInit.php'; -class YamlDriverTest extends \Doctrine\Tests\OrmTestCase +class MappingDriverTest extends \Doctrine\Tests\OrmTestCase { + public function testXmlMapping() + { + $className = 'Doctrine\Tests\ORM\Mapping\User'; + $xmlDriver = new XmlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'xml', XmlDriver::FILE_PER_CLASS); + + $class = new ClassMetadata($className); + + $this->assertFalse($xmlDriver->isTransient($className)); + + $xmlDriver->loadMetadataForClass($className, $class); + + $this->_testUserClassMapping($class); + } + public function testYamlMapping() { - $className = 'YamlMappingTest\User'; + $className = 'Doctrine\Tests\ORM\Mapping\User'; $yamlDriver = new YamlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'); $class = new ClassMetadata($className); @@ -21,6 +35,43 @@ class YamlDriverTest extends \Doctrine\Tests\OrmTestCase $yamlDriver->loadMetadataForClass($className, $class); + $this->_testUserClassMapping($class); + } + + public function testXmlPreloadMode() + { + $className = 'Doctrine\Tests\ORM\Mapping\User'; + $xmlDriver = new XmlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'xml'); + $class = new ClassMetadata($className); + + $classNames = $xmlDriver->preload(); + + $this->assertEquals($className, $classNames[0]); + $this->assertEquals(1, count($xmlDriver->getPreloadedElements())); + + $xmlDriver->loadMetadataForClass($className, $class); + + $this->assertEquals(0, count($xmlDriver->getPreloadedElements())); + } + + public function testYamlPreloadMode() + { + $className = 'Doctrine\Tests\ORM\Mapping\User'; + $yamlDriver = new YamlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'); + $class = new ClassMetadata($className); + + $classNames = $yamlDriver->preload(); + + $this->assertEquals($className, $classNames[0]); + $this->assertEquals(1, count($yamlDriver->getPreloadedElements())); + + $yamlDriver->loadMetadataForClass($className, $class); + + $this->assertEquals(0, count($yamlDriver->getPreloadedElements())); + } + + private function _testUserClassMapping($class) + { $this->assertEquals('cms_users', $class->getTableName()); $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $class->getInheritanceType()); $this->assertEquals(2, count($class->fieldMappings)); @@ -47,20 +98,14 @@ class YamlDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(isset($class->associationMappings['groups'])); $this->assertTrue($class->associationMappings['groups']->isOwningSide); } +} - public function testPreloadMode() - { - $className = 'YamlMappingTest\User'; - $yamlDriver = new YamlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'); - $class = new ClassMetadata($className); - - $classNames = $yamlDriver->preload(); - - $this->assertEquals($className, $classNames[0]); - $this->assertEquals(1, count($yamlDriver->getPreloadedElements())); - - $yamlDriver->loadMetadataForClass($className, $class); - - $this->assertEquals(0, count($yamlDriver->getPreloadedElements())); - } +class User { + private $id; + private $name; + private $address; + private $phonenumbers; + private $groups; + + // ... rest of code omitted, irrelevant for the mapping tests } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlDriverTest.php deleted file mode 100644 index 63c1d7498..000000000 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlDriverTest.php +++ /dev/null @@ -1,66 +0,0 @@ -assertFalse($xmlDriver->isTransient($className)); - - $xmlDriver->loadMetadataForClass($className, $class); - - $this->assertEquals('cms_users', $class->getTableName()); - $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $class->getInheritanceType()); - $this->assertEquals(2, count($class->fieldMappings)); - $this->assertTrue(isset($class->fieldMappings['id'])); - $this->assertTrue(isset($class->fieldMappings['name'])); - $this->assertEquals('string', $class->fieldMappings['name']['type']); - $this->assertEquals(array('id'), $class->identifier); - $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $class->getIdGeneratorType()); - - $this->assertEquals(3, count($class->associationMappings)); - $this->assertEquals(1, count($class->inverseMappings)); - - $this->assertTrue($class->associationMappings['address'] instanceof \Doctrine\ORM\Mapping\OneToOneMapping); - $this->assertTrue(isset($class->associationMappings['address'])); - $this->assertTrue($class->associationMappings['address']->isOwningSide); - - $this->assertTrue($class->associationMappings['phonenumbers'] instanceof \Doctrine\ORM\Mapping\OneToManyMapping); - $this->assertTrue(isset($class->associationMappings['phonenumbers'])); - $this->assertFalse($class->associationMappings['phonenumbers']->isOwningSide); - $this->assertTrue($class->associationMappings['phonenumbers']->isInverseSide()); - $this->assertTrue($class->associationMappings['phonenumbers']->isCascadePersist); - - $this->assertTrue($class->associationMappings['groups'] instanceof \Doctrine\ORM\Mapping\ManyToManyMapping); - $this->assertTrue(isset($class->associationMappings['groups'])); - $this->assertTrue($class->associationMappings['groups']->isOwningSide); - } - - public function testPreloadMode() - { - $className = 'XmlMappingTest\User'; - $xmlDriver = new XmlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'xml'); - $class = new ClassMetadata($className); - - $classNames = $xmlDriver->preload(); - - $this->assertEquals($className, $classNames[0]); - $this->assertEquals(1, count($xmlDriver->getPreloadedElements())); - - $xmlDriver->loadMetadataForClass($className, $class); - - $this->assertEquals(0, count($xmlDriver->getPreloadedElements())); - } -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/XmlMappingTest.User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml similarity index 95% rename from tests/Doctrine/Tests/ORM/Mapping/xml/XmlMappingTest.User.dcm.xml rename to tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml index ed3ea167b..34d28027e 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/XmlMappingTest.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping /Users/robo/dev/php/Doctrine/doctrine-mapping.xsd"> - + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/User.php b/tests/Doctrine/Tests/ORM/Mapping/xml/User.php deleted file mode 100644 index 190a135ca..000000000 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/User.php +++ /dev/null @@ -1,13 +0,0 @@ -