Commit c2ab01bf authored by romanb's avatar romanb

Added first ClassMetadataFactory tests.

parent 957a6b2c
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#namespace Doctrine\ORM; #namespace Doctrine\ORM;
#use Doctrine\DBAL\Configuration; #use Doctrine\DBAL\Configuration;
#use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
/** /**
* Configuration container for all configuration options of Doctrine. * Configuration container for all configuration options of Doctrine.
...@@ -43,10 +44,21 @@ class Doctrine_ORM_Configuration extends Doctrine_DBAL_Configuration ...@@ -43,10 +44,21 @@ class Doctrine_ORM_Configuration extends Doctrine_DBAL_Configuration
$this->_attributes = array_merge($this->_attributes, array( $this->_attributes = array_merge($this->_attributes, array(
'resultCacheImpl' => null, 'resultCacheImpl' => null,
'queryCacheImpl' => null, 'queryCacheImpl' => null,
'metadataCacheImpl' => null 'metadataCacheImpl' => null,
'metadataDriverImpl' => new Doctrine_ORM_Mapping_Driver_AnnotationDriver()
)); ));
} }
public function setMetadataDriverImpl($driverImpl)
{
$this->_attributes['metadataDriverImpl'] = $driverImpl;
}
public function getMetadataDriverImpl()
{
return $this->_attributes['metadataDriverImpl'];
}
public function getResultCacheImpl() public function getResultCacheImpl()
{ {
return $this->_attributes['resultCacheImpl']; return $this->_attributes['resultCacheImpl'];
......
...@@ -135,7 +135,7 @@ class Doctrine_ORM_EntityManager ...@@ -135,7 +135,7 @@ class Doctrine_ORM_EntityManager
/** /**
* The maintained (cached) Id generators. * The maintained (cached) Id generators.
* *
* @var <type> * @var array
*/ */
private $_idGenerators = array(); private $_idGenerators = array();
...@@ -148,6 +148,8 @@ class Doctrine_ORM_EntityManager ...@@ -148,6 +148,8 @@ class Doctrine_ORM_EntityManager
* *
* @param Doctrine\DBAL\Connection $conn * @param Doctrine\DBAL\Connection $conn
* @param string $name * @param string $name
* @param Doctrine\ORM\Configuration $config
* @param Doctrine\Common\EventManager $eventManager
*/ */
protected function __construct( protected function __construct(
Doctrine_DBAL_Connection $conn, Doctrine_DBAL_Connection $conn,
...@@ -160,16 +162,16 @@ class Doctrine_ORM_EntityManager ...@@ -160,16 +162,16 @@ class Doctrine_ORM_EntityManager
$this->_config = $config; $this->_config = $config;
$this->_eventManager = $eventManager; $this->_eventManager = $eventManager;
$this->_metadataFactory = new Doctrine_ORM_Mapping_ClassMetadataFactory( $this->_metadataFactory = new Doctrine_ORM_Mapping_ClassMetadataFactory(
new Doctrine_ORM_Mapping_Driver_AnnotationDriver(), $this->_config->getMetadataDriverImpl(),
$this->_conn->getDatabasePlatform()); $this->_conn->getDatabasePlatform());
$this->_metadataFactory->setCacheDriver($this->_config->getMetadataCacheImpl());
$this->_unitOfWork = new Doctrine_ORM_UnitOfWork($this); $this->_unitOfWork = new Doctrine_ORM_UnitOfWork($this);
$this->_nullObject = Doctrine_ORM_Internal_Null::$INSTANCE;
} }
/** /**
* Gets the database connection object used by the EntityManager. * Gets the database connection object used by the EntityManager.
* *
* @return Doctrine_Connection * @return Doctrine\DBAL\Connection
*/ */
public function getConnection() public function getConnection()
{ {
...@@ -178,6 +180,8 @@ class Doctrine_ORM_EntityManager ...@@ -178,6 +180,8 @@ class Doctrine_ORM_EntityManager
/** /**
* Gets the metadata factory used to gather the metadata of classes. * Gets the metadata factory used to gather the metadata of classes.
*
* @return Doctrine\ORM\Mapping\ClassMetadataFactory
*/ */
public function getMetadataFactory() public function getMetadataFactory()
{ {
...@@ -609,7 +613,6 @@ class Doctrine_ORM_EntityManager ...@@ -609,7 +613,6 @@ class Doctrine_ORM_EntityManager
} }
$em = new Doctrine_ORM_EntityManager($conn, $name, $config, $eventManager); $em = new Doctrine_ORM_EntityManager($conn, $name, $config, $eventManager);
$em->activate();
return $em; return $em;
} }
......
...@@ -52,9 +52,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping ...@@ -52,9 +52,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
protected $_isCascadeSave; protected $_isCascadeSave;
protected $_isCascadeRefresh; protected $_isCascadeRefresh;
protected $_customAccessor;
protected $_customMutator;
/** /**
* The fetch mode used for the association. * The fetch mode used for the association.
* *
...@@ -110,14 +107,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping ...@@ -110,14 +107,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
*/ */
protected $_mappedByFieldName; protected $_mappedByFieldName;
/**
* Identifies the field on the inverse side of a bidirectional association.
* This is only set on the owning side of an association.
*
* @var string
*/
//protected $_inverseSideFieldName;
/** /**
* The name of the join table, if any. * The name of the join table, if any.
* *
...@@ -125,11 +114,8 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping ...@@ -125,11 +114,8 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
*/ */
protected $_joinTable; protected $_joinTable;
//protected $_mapping = array();
/** /**
* Constructor. * Initializes a new instance of a class derived from AssociationMapping.
* Creates a new AssociationMapping.
* *
* @param array $mapping The mapping definition. * @param array $mapping The mapping definition.
*/ */
...@@ -151,8 +137,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping ...@@ -151,8 +137,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
'mappedBy' => null, 'mappedBy' => null,
'joinColumns' => null, 'joinColumns' => null,
'joinTable' => null, 'joinTable' => null,
'accessor' => null,
'mutator' => null,
'optional' => true, 'optional' => true,
'cascades' => array() 'cascades' => array()
); );
...@@ -193,12 +177,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping ...@@ -193,12 +177,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
} }
// Optional attributes for both sides // Optional attributes for both sides
if (isset($mapping['accessor'])) {
$this->_customAccessor = $mapping['accessor'];
}
if (isset($mapping['mutator'])) {
$this->_customMutator = $mapping['mutator'];
}
$this->_isOptional = isset($mapping['optional']) ? $this->_isOptional = isset($mapping['optional']) ?
(bool)$mapping['optional'] : true; (bool)$mapping['optional'] : true;
$this->_cascades = isset($mapping['cascade']) ? $this->_cascades = isset($mapping['cascade']) ?
...@@ -387,48 +365,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping ...@@ -387,48 +365,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
return $this->_mappedByFieldName || $this->_inverseSideFieldName; return $this->_mappedByFieldName || $this->_inverseSideFieldName;
}*/ }*/
/**
* Whether the source field of the association has a custom accessor.
*
* @return boolean TRUE if the source field of the association has a custom accessor,
* FALSE otherwise.
*/
public function hasCustomAccessor()
{
return isset($this->_customAccessor);
}
/**
* Gets the name of the custom accessor method of the source field.
*
* @return string The name of the accessor method or NULL.
*/
public function getCustomAccessor()
{
return $this->_customAccessor;
}
/**
* Whether the source field of the association has a custom mutator.
*
* @return boolean TRUE if the source field of the association has a custom mutator,
* FALSE otherwise.
*/
public function hasCustomMutator()
{
return isset($this->_customMutator);
}
/**
* Gets the name of the custom mutator method of the source field.
*
* @return string The name of the mutator method or NULL.
*/
public function getCustomMutator()
{
return $this->_customMutator;
}
public function isOneToOne() public function isOneToOne()
{ {
return false; return false;
...@@ -444,6 +380,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping ...@@ -444,6 +380,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
return false; return false;
} }
abstract public function lazyLoadFor($entity); abstract public function lazyLoadFor($entity, $entityManager);
} }
...@@ -1186,6 +1186,11 @@ class Doctrine_ORM_Mapping_ClassMetadata ...@@ -1186,6 +1186,11 @@ class Doctrine_ORM_Mapping_ClassMetadata
$this->_fieldMappings[$mapping['fieldName']] = $mapping; $this->_fieldMappings[$mapping['fieldName']] = $mapping;
} }
public function addAssociationMapping(Doctrine_ORM_Mapping_AssociationMapping $mapping)
{
$this->_storeAssociationMapping($mapping);
}
/** /**
* Adds a one-to-one mapping. * Adds a one-to-one mapping.
* *
...@@ -1256,7 +1261,7 @@ class Doctrine_ORM_Mapping_ClassMetadata ...@@ -1256,7 +1261,7 @@ class Doctrine_ORM_Mapping_ClassMetadata
{ {
$sourceFieldName = $assocMapping->getSourceFieldName(); $sourceFieldName = $assocMapping->getSourceFieldName();
if (isset($this->_associationMappings[$sourceFieldName])) { if (isset($this->_associationMappings[$sourceFieldName])) {
throw Doctrine_MappingException::duplicateFieldMapping(); throw Doctrine_ORM_Exceptions_MappingException::duplicateFieldMapping();
} }
$this->_associationMappings[$sourceFieldName] = $assocMapping; $this->_associationMappings[$sourceFieldName] = $assocMapping;
$this->_registerMappingIfInverse($assocMapping); $this->_registerMappingIfInverse($assocMapping);
...@@ -1412,6 +1417,16 @@ class Doctrine_ORM_Mapping_ClassMetadata ...@@ -1412,6 +1417,16 @@ class Doctrine_ORM_Mapping_ClassMetadata
$this->_discriminatorColumn = $columnDef; $this->_discriminatorColumn = $columnDef;
} }
/**
*
* @param <type> $fieldName
* @param <type> $mapping
*/
/*public function addFieldMapping($fieldName, array $mapping)
{
$this->_fieldMappings[$fieldName] = $mapping;
}*/
/** /**
* Gets the discriminator column definition. * Gets the discriminator column definition.
* *
......
...@@ -40,6 +40,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory ...@@ -40,6 +40,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
/** The targeted database platform. */ /** The targeted database platform. */
private $_targetPlatform; private $_targetPlatform;
private $_driver; private $_driver;
private $_cacheDriver;
/** /**
* Constructor. * Constructor.
...@@ -53,16 +54,35 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory ...@@ -53,16 +54,35 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
$this->_targetPlatform = $targetPlatform; $this->_targetPlatform = $targetPlatform;
} }
public function setCacheDriver($cacheDriver)
{
$this->_cacheDriver = $cacheDriver;
}
public function getCacheDriver()
{
return $this->_cacheDriver;
}
/** /**
* Returns the metadata object for a class. * Returns the metadata object for a class.
* *
* @param string $className The name of the class. * @param string $className The name of the class.
* @return Doctrine_Metadata * @return Doctrine\ORM\Mapping\ClassMetadata
*/ */
public function getMetadataFor($className) public function getMetadataFor($className)
{ {
if ( ! isset($this->_loadedMetadata[$className])) { if ( ! isset($this->_loadedMetadata[$className])) {
if ($this->_cacheDriver) {
if ($this->_cacheDriver->contains("$className\$CLASSMETADATA")) {
$this->_loadedMetadata[$className] = $this->_cacheDriver->get("$className\$CLASSMETADATA");
} else {
$this->_loadMetadata($className); $this->_loadMetadata($className);
$this->_cacheDriver->put("$className\$CLASSMETADATA", $this->_loadedMetadata[$className]);
}
} else {
$this->_loadMetadata($className);
}
} }
return $this->_loadedMetadata[$className]; return $this->_loadedMetadata[$className];
} }
...@@ -93,7 +113,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory ...@@ -93,7 +113,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
$class = $this->_loadedMetadata[$loadedParentClass]; $class = $this->_loadedMetadata[$loadedParentClass];
} else { } else {
$rootClassOfHierarchy = count($parentClasses) > 0 ? array_shift($parentClasses) : $name; $rootClassOfHierarchy = count($parentClasses) > 0 ? array_shift($parentClasses) : $name;
$class = new Doctrine_ORM_Mapping_ClassMetadata($rootClassOfHierarchy); $class = $this->_newClassMetadataInstance($rootClassOfHierarchy);
$this->_loadClassMetadata($class, $rootClassOfHierarchy); $this->_loadClassMetadata($class, $rootClassOfHierarchy);
$this->_loadedMetadata[$rootClassOfHierarchy] = $class; $this->_loadedMetadata[$rootClassOfHierarchy] = $class;
} }
...@@ -108,7 +128,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory ...@@ -108,7 +128,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
// Move down the hierarchy of parent classes, starting from the topmost class // Move down the hierarchy of parent classes, starting from the topmost class
$parent = $class; $parent = $class;
foreach ($parentClasses as $subclassName) { foreach ($parentClasses as $subclassName) {
$subClass = new Doctrine_ORM_Mapping_ClassMetadata($subclassName); $subClass = $this->_newClassMetadataInstance($subclassName);
$subClass->setInheritanceType($parent->getInheritanceType()); $subClass->setInheritanceType($parent->getInheritanceType());
$subClass->setDiscriminatorMap($parent->getDiscriminatorMap()); $subClass->setDiscriminatorMap($parent->getDiscriminatorMap());
$subClass->setDiscriminatorColumn($parent->getDiscriminatorColumn()); $subClass->setDiscriminatorColumn($parent->getDiscriminatorColumn());
...@@ -123,11 +143,16 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory ...@@ -123,11 +143,16 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
} }
} }
protected function _newClassMetadataInstance($className)
{
return new Doctrine_ORM_Mapping_ClassMetadata($className);
}
/** /**
* Adds inherited fields to the subclass mapping. * Adds inherited fields to the subclass mapping.
* *
* @param Doctrine::ORM::Mapping::ClassMetadata $subClass * @param Doctrine\ORM\Mapping\ClassMetadata $subClass
* @param Doctrine::ORM::Mapping::ClassMetadata $parentClass * @param Doctrine\ORM\Mapping\ClassMetadata $parentClass
*/ */
private function _addInheritedFields($subClass, $parentClass) private function _addInheritedFields($subClass, $parentClass)
{ {
...@@ -135,20 +160,20 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory ...@@ -135,20 +160,20 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
if ( ! isset($mapping['inherited'])) { if ( ! isset($mapping['inherited'])) {
$mapping['inherited'] = $parentClass->getClassName(); $mapping['inherited'] = $parentClass->getClassName();
} }
$subClass->addFieldMapping($fieldName, $mapping); $subClass->mapField($mapping);
} }
} }
/** /**
* Adds inherited associations to the subclass mapping. * Adds inherited associations to the subclass mapping.
* *
* @param unknown_type $subClass * @param Doctrine\ORM\Mapping\ClassMetadata $subClass
* @param unknown_type $parentClass * @param Doctrine\ORM\Mapping\ClassMetadata $parentClass
*/ */
private function _addInheritedRelations($subClass, $parentClass) private function _addInheritedRelations($subClass, $parentClass)
{ {
foreach ($parentClass->getAssociationMappings() as $fieldName => $mapping) { foreach ($parentClass->getAssociationMappings() as $mapping) {
$subClass->addAssociationMapping($name, $mapping); $subClass->addAssociationMapping($mapping);
} }
} }
......
...@@ -85,4 +85,3 @@ class Doctrine_ORM_Mapping_ManyToManyMapping extends Doctrine_ORM_Mapping_Associ ...@@ -85,4 +85,3 @@ class Doctrine_ORM_Mapping_ManyToManyMapping extends Doctrine_ORM_Mapping_Associ
} }
} }
?>
\ No newline at end of file
...@@ -111,7 +111,7 @@ class Doctrine_ORM_Mapping_OneToManyMapping extends Doctrine_ORM_Mapping_Associa ...@@ -111,7 +111,7 @@ class Doctrine_ORM_Mapping_OneToManyMapping extends Doctrine_ORM_Mapping_Associa
* @param <type> $entity * @param <type> $entity
* @override * @override
*/ */
public function lazyLoadFor($entity) public function lazyLoadFor($entity, $entityManager)
{ {
} }
......
...@@ -19,9 +19,7 @@ ...@@ -19,9 +19,7 @@
* <http://www.phpdoctrine.org>. * <http://www.phpdoctrine.org>.
*/ */
#namespace Doctrine::ORM::Mappings; #namespace Doctrine\ORM\Mappings;
#use Doctrine::ORM::Entity;
/** /**
* A one-to-one mapping describes a uni-directional mapping from one entity * A one-to-one mapping describes a uni-directional mapping from one entity
...@@ -29,7 +27,6 @@ ...@@ -29,7 +27,6 @@
* *
* @since 2.0 * @since 2.0
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @todo Rename to OneToOneMapping
*/ */
class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_AssociationMapping class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_AssociationMapping
{ {
...@@ -65,6 +62,11 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat ...@@ -65,6 +62,11 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat
parent::__construct($mapping); parent::__construct($mapping);
} }
/**
* {@inheritdoc}
*
* @override
*/
protected function _initMappingArray() protected function _initMappingArray()
{ {
parent::_initMappingArray(); parent::_initMappingArray();
...@@ -72,7 +74,7 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat ...@@ -72,7 +74,7 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat
} }
/** /**
* Validates & completes the mapping. Mapping defaults are applied here. * {@inheritdoc}
* *
* @param array $mapping The mapping to validate & complete. * @param array $mapping The mapping to validate & complete.
* @return array The validated & completed mapping. * @return array The validated & completed mapping.
...@@ -99,7 +101,7 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat ...@@ -99,7 +101,7 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat
/** /**
* Gets the source-to-target key column mapping. * Gets the source-to-target key column mapping.
* *
* @return unknown * @return array
*/ */
public function getSourceToTargetKeyColumns() public function getSourceToTargetKeyColumns()
{ {
...@@ -109,7 +111,7 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat ...@@ -109,7 +111,7 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat
/** /**
* Gets the target-to-source key column mapping. * Gets the target-to-source key column mapping.
* *
* @return unknown * @return array
*/ */
public function getTargetToSourceKeyColumns() public function getTargetToSourceKeyColumns()
{ {
...@@ -117,7 +119,7 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat ...@@ -117,7 +119,7 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat
} }
/** /**
* Whether the association is one-to-one. * {@inheritdoc}
* *
* @return boolean * @return boolean
* @override * @override
...@@ -128,37 +130,33 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat ...@@ -128,37 +130,33 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat
} }
/** /**
* Lazy-loads the associated entity for a given entity. * {@inheritdoc}
* *
* @param Doctrine\ORM\Entity $entity * @param Doctrine\ORM\Entity $entity
* @return void * @return void
*/ */
public function lazyLoadFor($entity) public function lazyLoadFor($entity, $entityManager)
{ {
if ($entity->getClassName() != $this->_sourceClass->getClassName()) { $sourceClass = $entityManager->getClassMetadata($this->_sourceEntityName);
//error? $targetClass = $entityManager->getClassMetadata($this->_targetEntityName);
}
$dql = 'SELECT t.* FROM ' . $this->_targetClass->getClassName() . ' t WHERE '; $dql = 'SELECT t.* FROM ' . $targetClass->getClassName() . ' t WHERE ';
$params = array(); $params = array();
foreach ($this->_sourceToTargetKeyFields as $sourceKeyField => $targetKeyField) { foreach ($this->_sourceToTargetKeyFields as $sourceKeyField => $targetKeyField) {
if ($params) { if ($params) {
$dql .= " AND "; $dql .= " AND ";
} }
$dql .= "t.$targetKeyField = ?"; $dql .= "t.$targetKeyField = ?";
$params[] = $entity->_rawGetField($sourceKeyField); $params[] = $sourceClass->getReflectionProperty($sourceKeyField)->getValue($entity);
} }
$otherEntity = $this->_targetClass->getEntityManager() $otherEntity = $entityManager->query($dql, $params)->getFirst();
->query($dql, $params)
->getFirst();
if ( ! $otherEntity) { if ( ! $otherEntity) {
$otherEntity = Doctrine_Null::$INSTANCE; $otherEntity = null;
} }
$entity->_internalSetReference($this->_sourceFieldName, $otherEntity); $sourceClass->getReflectionProperty($this->_sourceFieldName)->setValue($entity, $otherEntity);
} }
} }
?>
\ No newline at end of file
<?php
#namespace Doctrine\ORM;
/**
* Represents a virtual proxy that is used for lazy to-one associations.
*
* @author robo
* @since 2.0
*/
class Doctrine_ORM_VirtualProxy
{
private $_assoc;
private $_refProp;
private $_owner;
/**
* Initializes a new VirtualProxy instance that will proxy the specified property on
* the specified owner entity. The given association is used to lazy-load the
* real object on access of the proxy.
*
* @param <type> $owner
* @param <type> $assoc
* @param <type> $refProp
*/
public function __construct($owner, Doctrine_ORM_Mapping_AssociationMapping $assoc, ReflectionProperty $refProp)
{
$this->_owner = $owner;
$this->_assoc = $assoc;
$this->_refProp = $refProp;
}
private function _load()
{
$realInstance = $tis->_assoc->lazyLoadFor($this->_owner);
$this->_refProp->setValue($this->_owner, $realInstance);
return $realInstance;
}
/** All the "magic" interceptors */
public function __call($method, $args)
{
$realInstance = $this->_load();
return call_user_func_array(array($realInstance, $method), $args);
}
public function __get($prop)
{
$realInstance = $this->_load();
return $realInstance->$prop;
}
public function __set($prop, $value)
{
$realInstance = $this->_load();
$realInstance->$prop = $value;
}
public function __isset($prop)
{
$realInstance = $this->_load();
return isset($realInstance->$prop);
}
public function __unset($prop)
{
$realInstance = $this->_load();
unset($realInstance->$prop);
}
}
?>
...@@ -11,13 +11,13 @@ require_once 'Orm/Hydration/AllTests.php'; ...@@ -11,13 +11,13 @@ require_once 'Orm/Hydration/AllTests.php';
require_once 'Orm/Ticket/AllTests.php'; require_once 'Orm/Ticket/AllTests.php';
require_once 'Orm/Entity/AllTests.php'; require_once 'Orm/Entity/AllTests.php';
require_once 'Orm/Associations/AllTests.php'; require_once 'Orm/Associations/AllTests.php';
require_once 'Orm/Mapping/AllTests.php';
// Tests // Tests
require_once 'Orm/UnitOfWorkTest.php'; require_once 'Orm/UnitOfWorkTest.php';
require_once 'Orm/EntityManagerTest.php'; require_once 'Orm/EntityManagerTest.php';
require_once 'Orm/EntityPersisterTest.php'; require_once 'Orm/EntityPersisterTest.php';
require_once 'Orm/CommitOrderCalculatorTest.php'; require_once 'Orm/CommitOrderCalculatorTest.php';
require_once 'Orm/ClassMetadataTest.php';
class Orm_AllTests class Orm_AllTests
{ {
...@@ -34,13 +34,13 @@ class Orm_AllTests ...@@ -34,13 +34,13 @@ class Orm_AllTests
$suite->addTestSuite('Orm_EntityManagerTest'); $suite->addTestSuite('Orm_EntityManagerTest');
$suite->addTestSuite('Orm_EntityPersisterTest'); $suite->addTestSuite('Orm_EntityPersisterTest');
$suite->addTestSuite('Orm_CommitOrderCalculatorTest'); $suite->addTestSuite('Orm_CommitOrderCalculatorTest');
$suite->addTestSuite('Orm_ClassMetadataTest');
$suite->addTest(Orm_Query_AllTests::suite()); $suite->addTest(Orm_Query_AllTests::suite());
$suite->addTest(Orm_Hydration_AllTests::suite()); $suite->addTest(Orm_Hydration_AllTests::suite());
$suite->addTest(Orm_Entity_AllTests::suite()); $suite->addTest(Orm_Entity_AllTests::suite());
$suite->addTest(Orm_Ticket_AllTests::suite()); $suite->addTest(Orm_Ticket_AllTests::suite());
$suite->addTest(Orm_Associations_AllTests::suite()); $suite->addTest(Orm_Associations_AllTests::suite());
$suite->addTest(Orm_Mapping_AllTests::suite());
return $suite; return $suite;
} }
......
<?php
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Orm_Mapping_AllTests::main');
}
require_once 'lib/DoctrineTestInit.php';
// Tests
require_once 'Orm/Mapping/ClassMetadataTest.php';
require_once 'Orm/Mapping/ClassMetadataFactoryTest.php';
class Orm_Mapping_AllTests
{
public static function main()
{
PHPUnit_TextUI_TestRunner::run(self::suite());
}
public static function suite()
{
$suite = new Doctrine_TestSuite('Doctrine Orm Mapping');
$suite->addTestSuite('Orm_Mapping_ClassMetadataTest');
$suite->addTestSuite('Orm_Mapping_ClassMetadataFactoryTest');
return $suite;
}
}
if (PHPUnit_MAIN_METHOD == 'Orm_Mapping_AllTests::main') {
Orm_Mapping_AllTests::main();
}
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
require_once 'lib/DoctrineTestInit.php';
require_once 'lib/mocks/Doctrine_MetadataDriverMock.php';
/**
* Description of ClassMetadataFactoryTest
*
* @author robo
*/
class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase {
public function testGetMetadataForSingleClass() {
//TODO
}
public function testGetMetadataForClassInHierarchy() {
$mockPlatform = new Doctrine_DatabasePlatformMock();
$mockDriver = new Doctrine_MetadataDriverMock();
// Self-made metadata
$cm1 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity1');
$cm1->setInheritanceType('singleTable');
// Add a mapped field
$cm1->mapField(array('fieldName' => 'name', 'type' => 'string'));
// and a mapped association
$cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this'));
$cm2 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity2');
$cm3 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity3');
$cmf = new ClassMetadataFactoryTestSubject($mockDriver, $mockPlatform);
// Set self-made metadata
$cmf->setMetadataForClass('CMFTest_Entity1', $cm1);
$cmf->setMetadataForClass('CMFTest_Entity2', $cm2);
$cmf->setMetadataForClass('CMFTest_Entity3', $cm3);
// Prechecks
$this->assertEquals(array(), $cm1->getParentClasses());
$this->assertEquals(array(), $cm2->getParentClasses());
$this->assertEquals(array(), $cm3->getParentClasses());
$this->assertEquals('none', $cm2->getInheritanceType());
$this->assertEquals('none', $cm3->getInheritanceType());
$this->assertFalse($cm2->hasField('name'));
$this->assertFalse($cm3->hasField('name'));
$this->assertEquals(1, count($cm1->getAssociationMappings()));
$this->assertEquals(0, count($cm2->getAssociationMappings()));
$this->assertEquals(0, count($cm3->getAssociationMappings()));
// Go
$cm3 = $cmf->getMetadataFor('CMFTest_Entity3');
// Metadata gathering should start at the root of the hierarchy, from there on downwards
$this->assertEquals(array('CMFTest_Entity1', 'CMFTest_Entity2', 'CMFTest_Entity3'), $cmf->getRequestedClasses());
// Parent classes should be assigned by factory
$this->assertEquals(array('CMFTest_Entity2', 'CMFTest_Entity1'), $cm3->getParentClasses());
$this->assertEquals('CMFTest_Entity1', $cm3->getRootClassName());
$this->assertEquals('CMFTest_Entity1', $cm2->getRootClassName());
$this->assertEquals('CMFTest_Entity1', $cm1->getRootClassName());
// Inheritance type should be inherited to Entity2
$this->assertEquals('singleTable', $cm2->getInheritanceType());
$this->assertEquals('singleTable', $cm3->getInheritanceType());
// Field mappings should be inherited
$this->assertTrue($cm2->hasField('name'));
$this->assertTrue($cm3->hasField('name'));
// Association mappings should be inherited
$this->assertEquals(1, count($cm2->getAssociationMappings()));
$this->assertEquals(1, count($cm3->getAssociationMappings()));
$this->assertTrue($cm2->hasAssociation('other'));
$this->assertTrue($cm3->hasAssociation('other'));
}
}
/* Test subject class with overriden factory method for mocking purposes */
class ClassMetadataFactoryTestSubject extends Doctrine_ORM_Mapping_ClassMetadataFactory {
private $_mockMetadata = array();
private $_requestedClasses = array();
/** @override */
protected function _newClassMetadataInstance($className) {
$this->_requestedClasses[] = $className;
if ( ! isset($this->_mockMetadata[$className])) {
throw new InvalidArgumentException("No mock metadata found for class $className.");
}
return $this->_mockMetadata[$className];
}
public function setMetadataForClass($className, $metadata) {
$this->_mockMetadata[$className] = $metadata;
}
public function getRequestedClasses() { return $this->_requestedClasses; }
}
/* Test classes */
class CMFTest_Entity1 {}
class CMFTest_Entity2 extends CMFTest_Entity1 {}
class CMFTest_Entity3 extends CMFTest_Entity2 {}
<?php <?php
require_once 'lib/DoctrineTestInit.php';
class Orm_ClassMetadataTest extends Doctrine_OrmTestCase #namespace Doctrine\Tests\ORM\Mapping;
{
protected function setUp() {
;
}
protected function tearDown() { require_once 'lib/DoctrineTestInit.php';
;
}
class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase
{
public function testClassMetadataInstanceSerialization() { public function testClassMetadataInstanceSerialization() {
$cm = new Doctrine_ORM_Mapping_ClassMetadata('CmsUser'); $cm = new Doctrine_ORM_Mapping_ClassMetadata('CmsUser');
...@@ -50,8 +45,4 @@ class Orm_ClassMetadataTest extends Doctrine_OrmTestCase ...@@ -50,8 +45,4 @@ class Orm_ClassMetadataTest extends Doctrine_OrmTestCase
$this->assertEquals('Bar', $oneOneMapping->getTargetEntityName()); $this->assertEquals('Bar', $oneOneMapping->getTargetEntityName());
} }
public function testTransientEntityIsManaged()
{
;
}
} }
\ No newline at end of file
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of Doctrine_MetadataDriverMock
*
* @author robo
*/
class Doctrine_MetadataDriverMock {
public function loadMetadataForClass($className, Doctrine_ORM_Mapping_ClassMetadata $metadata) {
return;
}
}
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