Commit 7152da32 authored by romanb's avatar romanb

[2.0] Unified xml/yaml driver mapping tests so that there is a stronger...

[2.0] Unified xml/yaml driver mapping tests so that there is a stronger enforcement on keeping them synchronized feature-wise.
parent e578bad6
......@@ -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');
......
......@@ -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
<?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
......@@ -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"/>
......
<?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
<?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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment