2009-06-06 01:40:47 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Mapping;
|
|
|
|
|
2009-08-13 15:03:26 +04:00
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata,
|
|
|
|
Doctrine\ORM\Mapping\Driver\XmlDriver,
|
|
|
|
Doctrine\ORM\Mapping\Driver\YamlDriver;
|
2009-06-06 01:40:47 +04:00
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
|
|
|
|
2009-08-13 15:03:26 +04:00
|
|
|
class MappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
2009-06-06 01:40:47 +04:00
|
|
|
{
|
2009-08-13 15:03:26 +04:00
|
|
|
public function testXmlMapping()
|
|
|
|
{
|
|
|
|
$className = 'Doctrine\Tests\ORM\Mapping\User';
|
2009-12-16 00:06:32 +03:00
|
|
|
$xmlDriver = new XmlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'xml');
|
2009-08-13 15:03:26 +04:00
|
|
|
|
|
|
|
$class = new ClassMetadata($className);
|
|
|
|
|
|
|
|
$this->assertFalse($xmlDriver->isTransient($className));
|
|
|
|
|
|
|
|
$xmlDriver->loadMetadataForClass($className, $class);
|
|
|
|
|
|
|
|
$this->_testUserClassMapping($class);
|
|
|
|
}
|
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
public function testYamlMapping()
|
|
|
|
{
|
2009-08-13 15:03:26 +04:00
|
|
|
$className = 'Doctrine\Tests\ORM\Mapping\User';
|
2009-06-06 01:40:47 +04:00
|
|
|
$yamlDriver = new YamlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'yaml');
|
|
|
|
|
|
|
|
$class = new ClassMetadata($className);
|
|
|
|
|
|
|
|
$this->assertFalse($yamlDriver->isTransient($className));
|
|
|
|
|
|
|
|
$yamlDriver->loadMetadataForClass($className, $class);
|
|
|
|
|
2009-08-13 15:03:26 +04:00
|
|
|
$this->_testUserClassMapping($class);
|
|
|
|
}
|
|
|
|
|
2009-12-16 00:06:32 +03:00
|
|
|
public function testXmlGetAllClassNames()
|
2009-08-13 15:03:26 +04:00
|
|
|
{
|
|
|
|
$className = 'Doctrine\Tests\ORM\Mapping\User';
|
2009-12-16 00:06:32 +03:00
|
|
|
$xmlDriver = new XmlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'xml');
|
2009-08-13 15:03:26 +04:00
|
|
|
$class = new ClassMetadata($className);
|
|
|
|
|
2009-12-16 00:06:32 +03:00
|
|
|
$classNames = $xmlDriver->getAllClassNames();
|
2009-08-13 15:03:26 +04:00
|
|
|
|
|
|
|
$this->assertEquals($className, $classNames[0]);
|
2009-12-16 00:06:32 +03:00
|
|
|
$this->assertEquals(1, count($classNames));
|
2009-08-13 15:03:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private function _testUserClassMapping($class)
|
|
|
|
{
|
2009-06-06 01:40:47 +04:00
|
|
|
$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());
|
2009-07-25 20:33:29 +04:00
|
|
|
$this->assertTrue($class->associationMappings['phonenumbers']->isCascadePersist);
|
2009-06-06 01:40:47 +04:00
|
|
|
|
|
|
|
$this->assertTrue($class->associationMappings['groups'] instanceof \Doctrine\ORM\Mapping\ManyToManyMapping);
|
|
|
|
$this->assertTrue(isset($class->associationMappings['groups']));
|
|
|
|
$this->assertTrue($class->associationMappings['groups']->isOwningSide);
|
2009-08-25 01:05:55 +04:00
|
|
|
$this->assertEquals(count($class->lifecycleCallbacks), 2);
|
|
|
|
$this->assertEquals($class->lifecycleCallbacks['prePersist'][0], 'doStuffOnPrePersist');
|
|
|
|
$this->assertEquals($class->lifecycleCallbacks['postPersist'][0], 'doStuffOnPostPersist');
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2009-08-13 15:03:26 +04:00
|
|
|
}
|
2009-06-06 01:40:47 +04:00
|
|
|
|
2009-08-13 15:03:26 +04:00
|
|
|
class User {
|
|
|
|
private $id;
|
|
|
|
private $name;
|
|
|
|
private $address;
|
|
|
|
private $phonenumbers;
|
|
|
|
private $groups;
|
|
|
|
|
|
|
|
// ... rest of code omitted, irrelevant for the mapping tests
|
2009-08-25 01:05:55 +04:00
|
|
|
|
|
|
|
public function doStuffOnPrePersist()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function doStuffOnPostPersist()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|