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-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-01-22 22:38:10 +03:00
|
|
|
$this->assertTrue($cm->getReflectionClass() instanceof \ReflectionClass);
|
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->getClassName());
|
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->getRootClassName());
|
2009-01-05 23:18:56 +03:00
|
|
|
$this->assertEquals(array(), $cm->getSubclasses());
|
|
|
|
$this->assertEquals(array(), $cm->getParentClasses());
|
|
|
|
|
|
|
|
// 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-01-05 23:18:56 +03:00
|
|
|
$this->assertEquals(1, count($cm->getAssociationMappings()));
|
|
|
|
|
|
|
|
$serialized = serialize($cm);
|
|
|
|
$cm = unserialize($serialized);
|
|
|
|
|
|
|
|
// Check state
|
|
|
|
$this->assertTrue(count($cm->getReflectionProperties()) > 0);
|
2009-01-22 22:38:10 +03:00
|
|
|
$this->assertTrue($cm->getReflectionClass() instanceof \ReflectionClass);
|
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->getClassName());
|
2009-01-05 23:18:56 +03:00
|
|
|
$this->assertEquals('UserParent', $cm->getRootClassName());
|
|
|
|
$this->assertEquals(array('One', 'Two', 'Three'), $cm->getSubclasses());
|
|
|
|
$this->assertEquals(array('UserParent'), $cm->getParentClasses());
|
|
|
|
$this->assertEquals('UserRepository', $cm->getCustomRepositoryClass());
|
|
|
|
$this->assertEquals(array('name' => 'disc', 'type' => 'integer'), $cm->getDiscriminatorColumn());
|
2009-01-22 22:38:10 +03:00
|
|
|
$this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof \Doctrine\ORM\Mapping\OneToOneMapping);
|
2009-01-05 23:18:56 +03:00
|
|
|
$this->assertEquals(1, count($cm->getAssociationMappings()));
|
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
|
|
|
}
|
|
|
|
}
|