2009-01-05 23:18:56 +03:00
|
|
|
<?php
|
2009-01-06 20:22:23 +03:00
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\Tests\ORM\Mapping;
|
2009-01-06 20:22:23 +03:00
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
2009-07-16 00:18:40 +04:00
|
|
|
use Doctrine\ORM\Events;
|
2009-01-22 22:38:10 +03:00
|
|
|
|
2009-01-24 19:56:44 +03:00
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
2009-01-05 23:18:56 +03:00
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
|
2009-01-06 20:22:23 +03:00
|
|
|
{
|
2009-02-18 10:59:11 +03:00
|
|
|
public function testClassMetadataInstanceSerialization()
|
|
|
|
{
|
2009-01-22 22:38:10 +03:00
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
|
2009-01-05 23:18:56 +03:00
|
|
|
|
|
|
|
// Test initial state
|
2009-01-12 16:34:41 +03:00
|
|
|
$this->assertTrue(count($cm->getReflectionProperties()) == 0);
|
2009-05-14 14:03:09 +04:00
|
|
|
$this->assertTrue($cm->reflClass instanceof \ReflectionClass);
|
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name);
|
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->rootEntityName);
|
|
|
|
$this->assertEquals(array(), $cm->subClasses);
|
|
|
|
$this->assertEquals(array(), $cm->parentClasses);
|
2009-01-05 23:18:56 +03:00
|
|
|
|
|
|
|
// Customize state
|
|
|
|
$cm->setSubclasses(array("One", "Two", "Three"));
|
|
|
|
$cm->setParentClasses(array("UserParent"));
|
|
|
|
$cm->setCustomRepositoryClass("UserRepository");
|
|
|
|
$cm->setDiscriminatorColumn(array('name' => 'disc', 'type' => 'integer'));
|
2009-01-12 16:34:41 +03:00
|
|
|
$cm->mapOneToOne(array('fieldName' => 'phonenumbers', 'targetEntity' => 'Bar', 'mappedBy' => 'foo'));
|
2009-01-22 22:38:10 +03:00
|
|
|
$this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof \Doctrine\ORM\Mapping\OneToOneMapping);
|
2009-05-14 14:03:09 +04:00
|
|
|
$this->assertEquals(1, count($cm->associationMappings));
|
2009-01-05 23:18:56 +03:00
|
|
|
|
|
|
|
$serialized = serialize($cm);
|
|
|
|
$cm = unserialize($serialized);
|
|
|
|
|
|
|
|
// Check state
|
|
|
|
$this->assertTrue(count($cm->getReflectionProperties()) > 0);
|
2009-05-14 14:03:09 +04:00
|
|
|
$this->assertTrue($cm->reflClass instanceof \ReflectionClass);
|
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name);
|
|
|
|
$this->assertEquals('UserParent', $cm->rootEntityName);
|
2009-08-17 21:58:16 +04:00
|
|
|
$this->assertEquals(array('Doctrine\Tests\Models\CMS\One', 'Doctrine\Tests\Models\CMS\Two', 'Doctrine\Tests\Models\CMS\Three'), $cm->subClasses);
|
2009-05-14 14:03:09 +04:00
|
|
|
$this->assertEquals(array('UserParent'), $cm->parentClasses);
|
2009-01-05 23:18:56 +03:00
|
|
|
$this->assertEquals('UserRepository', $cm->getCustomRepositoryClass());
|
2009-07-20 19:30:54 +04:00
|
|
|
$this->assertEquals(array('name' => 'disc', 'type' => 'integer', 'fieldName' => 'disc'), $cm->discriminatorColumn);
|
2009-01-22 22:38:10 +03:00
|
|
|
$this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof \Doctrine\ORM\Mapping\OneToOneMapping);
|
2009-05-14 14:03:09 +04:00
|
|
|
$this->assertEquals(1, count($cm->associationMappings));
|
2009-01-12 16:34:41 +03:00
|
|
|
$oneOneMapping = $cm->getAssociationMapping('phonenumbers');
|
|
|
|
$this->assertEquals('phonenumbers', $oneOneMapping->getSourceFieldName());
|
2009-02-04 19:35:36 +03:00
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\Bar', $oneOneMapping->getTargetEntityName());
|
2009-01-05 23:18:56 +03:00
|
|
|
}
|
|
|
|
}
|