From 7152da322fc7ee741ab31a62b125badf304b9386 Mon Sep 17 00:00:00 2001 From: romanb <romanb@625475ce-881a-0410-a577-b389adb331d8> Date: Thu, 13 Aug 2009 11:03:26 +0000 Subject: [PATCH] [2.0] Unified xml/yaml driver mapping tests so that there is a stronger enforcement on keeping them synchronized feature-wise. --- tests/Doctrine/Tests/ORM/Mapping/AllTests.php | 3 +- ...mlDriverTest.php => MappingDriverTest.php} | 85 ++++++++++++++----- .../Tests/ORM/Mapping/XmlDriverTest.php | 66 -------------- ...> Doctrine.Tests.ORM.Mapping.User.dcm.xml} | 2 +- tests/Doctrine/Tests/ORM/Mapping/xml/User.php | 13 --- ...> Doctrine.Tests.ORM.Mapping.User.dcm.yml} | 2 +- .../Doctrine/Tests/ORM/Mapping/yaml/User.php | 13 --- 7 files changed, 68 insertions(+), 116 deletions(-) rename tests/Doctrine/Tests/ORM/Mapping/{YamlDriverTest.php => MappingDriverTest.php} (61%) delete mode 100644 tests/Doctrine/Tests/ORM/Mapping/XmlDriverTest.php rename tests/Doctrine/Tests/ORM/Mapping/xml/{XmlMappingTest.User.dcm.xml => Doctrine.Tests.ORM.Mapping.User.dcm.xml} (95%) delete mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/User.php rename tests/Doctrine/Tests/ORM/Mapping/yaml/{YamlMappingTest.User.dcm.yml => Doctrine.Tests.ORM.Mapping.User.dcm.yml} (95%) delete mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/User.php 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 @@ -<?php - -namespace Doctrine\Tests\ORM\Mapping; - -use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Mapping\Driver\XmlDriver; - -require_once __DIR__ . '/xml/User.php'; -require_once __DIR__ . '/../../TestInit.php'; - -class XmlDriverTest extends \Doctrine\Tests\OrmTestCase -{ - public function testFilePerClassMapping() - { - $className = 'XmlMappingTest\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->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"> - <entity name="XmlMappingTest\User" table="cms_users"> + <entity name="Doctrine\Tests\ORM\Mapping\User" table="cms_users"> <id name="id" type="integer" column="id"> <generator strategy="AUTO"/> 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 @@ -<?php - -namespace XmlMappingTest; - -class User { - private $id; - private $name; - private $address; - private $phonenumbers; - private $groups; - - // ... rest of code omitted, irrelevant for the mapping test -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/YamlMappingTest.User.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml similarity index 95% rename from tests/Doctrine/Tests/ORM/Mapping/yaml/YamlMappingTest.User.dcm.yml rename to tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml index 738a5e016..75f1add5c 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/YamlMappingTest.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml @@ -1,4 +1,4 @@ -YamlMappingTest\User: +Doctrine\Tests\ORM\Mapping\User: type: entity table: cms_users id: diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/User.php b/tests/Doctrine/Tests/ORM/Mapping/yaml/User.php deleted file mode 100644 index 13652659b..000000000 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/User.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php - -namespace YamlMappingTest; - -class User { - private $id; - private $name; - private $address; - private $phonenumbers; - private $groups; - - // ... rest of code omitted, irrelevant for the mapping test -} \ No newline at end of file