Added first ClassMetadataFactory tests.
This commit is contained in:
parent
957a6b2c89
commit
c2ab01bf7e
@ -22,6 +22,7 @@
|
||||
#namespace Doctrine\ORM;
|
||||
|
||||
#use Doctrine\DBAL\Configuration;
|
||||
#use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
|
||||
|
||||
/**
|
||||
* Configuration container for all configuration options of Doctrine.
|
||||
@ -43,9 +44,20 @@ class Doctrine_ORM_Configuration extends Doctrine_DBAL_Configuration
|
||||
$this->_attributes = array_merge($this->_attributes, array(
|
||||
'resultCacheImpl' => 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()
|
||||
{
|
||||
|
@ -135,7 +135,7 @@ class Doctrine_ORM_EntityManager
|
||||
/**
|
||||
* The maintained (cached) Id generators.
|
||||
*
|
||||
* @var <type>
|
||||
* @var array
|
||||
*/
|
||||
private $_idGenerators = array();
|
||||
|
||||
@ -148,6 +148,8 @@ class Doctrine_ORM_EntityManager
|
||||
*
|
||||
* @param Doctrine\DBAL\Connection $conn
|
||||
* @param string $name
|
||||
* @param Doctrine\ORM\Configuration $config
|
||||
* @param Doctrine\Common\EventManager $eventManager
|
||||
*/
|
||||
protected function __construct(
|
||||
Doctrine_DBAL_Connection $conn,
|
||||
@ -160,16 +162,16 @@ class Doctrine_ORM_EntityManager
|
||||
$this->_config = $config;
|
||||
$this->_eventManager = $eventManager;
|
||||
$this->_metadataFactory = new Doctrine_ORM_Mapping_ClassMetadataFactory(
|
||||
new Doctrine_ORM_Mapping_Driver_AnnotationDriver(),
|
||||
$this->_config->getMetadataDriverImpl(),
|
||||
$this->_conn->getDatabasePlatform());
|
||||
$this->_metadataFactory->setCacheDriver($this->_config->getMetadataCacheImpl());
|
||||
$this->_unitOfWork = new Doctrine_ORM_UnitOfWork($this);
|
||||
$this->_nullObject = Doctrine_ORM_Internal_Null::$INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the database connection object used by the EntityManager.
|
||||
*
|
||||
* @return Doctrine_Connection
|
||||
* @return Doctrine\DBAL\Connection
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
@ -178,6 +180,8 @@ class Doctrine_ORM_EntityManager
|
||||
|
||||
/**
|
||||
* Gets the metadata factory used to gather the metadata of classes.
|
||||
*
|
||||
* @return Doctrine\ORM\Mapping\ClassMetadataFactory
|
||||
*/
|
||||
public function getMetadataFactory()
|
||||
{
|
||||
@ -609,7 +613,6 @@ class Doctrine_ORM_EntityManager
|
||||
}
|
||||
|
||||
$em = new Doctrine_ORM_EntityManager($conn, $name, $config, $eventManager);
|
||||
$em->activate();
|
||||
|
||||
return $em;
|
||||
}
|
||||
|
@ -52,9 +52,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
|
||||
protected $_isCascadeSave;
|
||||
protected $_isCascadeRefresh;
|
||||
|
||||
protected $_customAccessor;
|
||||
protected $_customMutator;
|
||||
|
||||
/**
|
||||
* The fetch mode used for the association.
|
||||
*
|
||||
@ -110,14 +107,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
|
||||
*/
|
||||
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.
|
||||
*
|
||||
@ -125,11 +114,8 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
|
||||
*/
|
||||
protected $_joinTable;
|
||||
|
||||
//protected $_mapping = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Creates a new AssociationMapping.
|
||||
* Initializes a new instance of a class derived from AssociationMapping.
|
||||
*
|
||||
* @param array $mapping The mapping definition.
|
||||
*/
|
||||
@ -151,8 +137,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
|
||||
'mappedBy' => null,
|
||||
'joinColumns' => null,
|
||||
'joinTable' => null,
|
||||
'accessor' => null,
|
||||
'mutator' => null,
|
||||
'optional' => true,
|
||||
'cascades' => array()
|
||||
);
|
||||
@ -193,12 +177,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
|
||||
}
|
||||
|
||||
// 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']) ?
|
||||
(bool)$mapping['optional'] : true;
|
||||
$this->_cascades = isset($mapping['cascade']) ?
|
||||
@ -387,48 +365,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
|
||||
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()
|
||||
{
|
||||
return false;
|
||||
@ -444,6 +380,6 @@ abstract class Doctrine_ORM_Mapping_AssociationMapping
|
||||
return false;
|
||||
}
|
||||
|
||||
abstract public function lazyLoadFor($entity);
|
||||
abstract public function lazyLoadFor($entity, $entityManager);
|
||||
}
|
||||
|
||||
|
@ -1185,7 +1185,12 @@ class Doctrine_ORM_Mapping_ClassMetadata
|
||||
}
|
||||
$this->_fieldMappings[$mapping['fieldName']] = $mapping;
|
||||
}
|
||||
|
||||
|
||||
public function addAssociationMapping(Doctrine_ORM_Mapping_AssociationMapping $mapping)
|
||||
{
|
||||
$this->_storeAssociationMapping($mapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a one-to-one mapping.
|
||||
*
|
||||
@ -1256,7 +1261,7 @@ class Doctrine_ORM_Mapping_ClassMetadata
|
||||
{
|
||||
$sourceFieldName = $assocMapping->getSourceFieldName();
|
||||
if (isset($this->_associationMappings[$sourceFieldName])) {
|
||||
throw Doctrine_MappingException::duplicateFieldMapping();
|
||||
throw Doctrine_ORM_Exceptions_MappingException::duplicateFieldMapping();
|
||||
}
|
||||
$this->_associationMappings[$sourceFieldName] = $assocMapping;
|
||||
$this->_registerMappingIfInverse($assocMapping);
|
||||
@ -1412,6 +1417,16 @@ class Doctrine_ORM_Mapping_ClassMetadata
|
||||
$this->_discriminatorColumn = $columnDef;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $fieldName
|
||||
* @param <type> $mapping
|
||||
*/
|
||||
/*public function addFieldMapping($fieldName, array $mapping)
|
||||
{
|
||||
$this->_fieldMappings[$fieldName] = $mapping;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Gets the discriminator column definition.
|
||||
*
|
||||
|
@ -40,6 +40,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
|
||||
/** The targeted database platform. */
|
||||
private $_targetPlatform;
|
||||
private $_driver;
|
||||
private $_cacheDriver;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -53,16 +54,35 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
|
||||
$this->_targetPlatform = $targetPlatform;
|
||||
}
|
||||
|
||||
public function setCacheDriver($cacheDriver)
|
||||
{
|
||||
$this->_cacheDriver = $cacheDriver;
|
||||
}
|
||||
|
||||
public function getCacheDriver()
|
||||
{
|
||||
return $this->_cacheDriver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the metadata object for a class.
|
||||
*
|
||||
* @param string $className The name of the class.
|
||||
* @return Doctrine_Metadata
|
||||
* @return Doctrine\ORM\Mapping\ClassMetadata
|
||||
*/
|
||||
public function getMetadataFor($className)
|
||||
{
|
||||
if ( ! isset($this->_loadedMetadata[$className])) {
|
||||
$this->_loadMetadata($className);
|
||||
if ($this->_cacheDriver) {
|
||||
if ($this->_cacheDriver->contains("$className\$CLASSMETADATA")) {
|
||||
$this->_loadedMetadata[$className] = $this->_cacheDriver->get("$className\$CLASSMETADATA");
|
||||
} else {
|
||||
$this->_loadMetadata($className);
|
||||
$this->_cacheDriver->put("$className\$CLASSMETADATA", $this->_loadedMetadata[$className]);
|
||||
}
|
||||
} else {
|
||||
$this->_loadMetadata($className);
|
||||
}
|
||||
}
|
||||
return $this->_loadedMetadata[$className];
|
||||
}
|
||||
@ -93,7 +113,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
|
||||
$class = $this->_loadedMetadata[$loadedParentClass];
|
||||
} else {
|
||||
$rootClassOfHierarchy = count($parentClasses) > 0 ? array_shift($parentClasses) : $name;
|
||||
$class = new Doctrine_ORM_Mapping_ClassMetadata($rootClassOfHierarchy);
|
||||
$class = $this->_newClassMetadataInstance($rootClassOfHierarchy);
|
||||
$this->_loadClassMetadata($class, $rootClassOfHierarchy);
|
||||
$this->_loadedMetadata[$rootClassOfHierarchy] = $class;
|
||||
}
|
||||
@ -108,7 +128,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
|
||||
// Move down the hierarchy of parent classes, starting from the topmost class
|
||||
$parent = $class;
|
||||
foreach ($parentClasses as $subclassName) {
|
||||
$subClass = new Doctrine_ORM_Mapping_ClassMetadata($subclassName);
|
||||
$subClass = $this->_newClassMetadataInstance($subclassName);
|
||||
$subClass->setInheritanceType($parent->getInheritanceType());
|
||||
$subClass->setDiscriminatorMap($parent->getDiscriminatorMap());
|
||||
$subClass->setDiscriminatorColumn($parent->getDiscriminatorColumn());
|
||||
@ -122,12 +142,17 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
|
||||
$parent = $subClass;
|
||||
}
|
||||
}
|
||||
|
||||
protected function _newClassMetadataInstance($className)
|
||||
{
|
||||
return new Doctrine_ORM_Mapping_ClassMetadata($className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds inherited fields to the subclass mapping.
|
||||
*
|
||||
* @param Doctrine::ORM::Mapping::ClassMetadata $subClass
|
||||
* @param Doctrine::ORM::Mapping::ClassMetadata $parentClass
|
||||
* @param Doctrine\ORM\Mapping\ClassMetadata $subClass
|
||||
* @param Doctrine\ORM\Mapping\ClassMetadata $parentClass
|
||||
*/
|
||||
private function _addInheritedFields($subClass, $parentClass)
|
||||
{
|
||||
@ -135,20 +160,20 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
|
||||
if ( ! isset($mapping['inherited'])) {
|
||||
$mapping['inherited'] = $parentClass->getClassName();
|
||||
}
|
||||
$subClass->addFieldMapping($fieldName, $mapping);
|
||||
$subClass->mapField($mapping);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds inherited associations to the subclass mapping.
|
||||
*
|
||||
* @param unknown_type $subClass
|
||||
* @param unknown_type $parentClass
|
||||
* @param Doctrine\ORM\Mapping\ClassMetadata $subClass
|
||||
* @param Doctrine\ORM\Mapping\ClassMetadata $parentClass
|
||||
*/
|
||||
private function _addInheritedRelations($subClass, $parentClass)
|
||||
{
|
||||
foreach ($parentClass->getAssociationMappings() as $fieldName => $mapping) {
|
||||
$subClass->addAssociationMapping($name, $mapping);
|
||||
foreach ($parentClass->getAssociationMappings() as $mapping) {
|
||||
$subClass->addAssociationMapping($mapping);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,4 +85,3 @@ class Doctrine_ORM_Mapping_ManyToManyMapping extends Doctrine_ORM_Mapping_Associ
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -111,7 +111,7 @@ class Doctrine_ORM_Mapping_OneToManyMapping extends Doctrine_ORM_Mapping_Associa
|
||||
* @param <type> $entity
|
||||
* @override
|
||||
*/
|
||||
public function lazyLoadFor($entity)
|
||||
public function lazyLoadFor($entity, $entityManager)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -19,9 +19,7 @@
|
||||
* <http://www.phpdoctrine.org>.
|
||||
*/
|
||||
|
||||
#namespace Doctrine::ORM::Mappings;
|
||||
|
||||
#use Doctrine::ORM::Entity;
|
||||
#namespace Doctrine\ORM\Mappings;
|
||||
|
||||
/**
|
||||
* A one-to-one mapping describes a uni-directional mapping from one entity
|
||||
@ -29,7 +27,6 @@
|
||||
*
|
||||
* @since 2.0
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @todo Rename to OneToOneMapping
|
||||
*/
|
||||
class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_AssociationMapping
|
||||
{
|
||||
@ -64,7 +61,12 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat
|
||||
{
|
||||
parent::__construct($mapping);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
protected function _initMappingArray()
|
||||
{
|
||||
parent::_initMappingArray();
|
||||
@ -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.
|
||||
* @return array The validated & completed mapping.
|
||||
@ -99,7 +101,7 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat
|
||||
/**
|
||||
* Gets the source-to-target key column mapping.
|
||||
*
|
||||
* @return unknown
|
||||
* @return array
|
||||
*/
|
||||
public function getSourceToTargetKeyColumns()
|
||||
{
|
||||
@ -109,7 +111,7 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat
|
||||
/**
|
||||
* Gets the target-to-source key column mapping.
|
||||
*
|
||||
* @return unknown
|
||||
* @return array
|
||||
*/
|
||||
public function getTargetToSourceKeyColumns()
|
||||
{
|
||||
@ -117,7 +119,7 @@ class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_Associat
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the association is one-to-one.
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return boolean
|
||||
* @override
|
||||
@ -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
|
||||
* @return void
|
||||
*/
|
||||
public function lazyLoadFor($entity)
|
||||
public function lazyLoadFor($entity, $entityManager)
|
||||
{
|
||||
if ($entity->getClassName() != $this->_sourceClass->getClassName()) {
|
||||
//error?
|
||||
}
|
||||
|
||||
$dql = 'SELECT t.* FROM ' . $this->_targetClass->getClassName() . ' t WHERE ';
|
||||
$sourceClass = $entityManager->getClassMetadata($this->_sourceEntityName);
|
||||
$targetClass = $entityManager->getClassMetadata($this->_targetEntityName);
|
||||
|
||||
$dql = 'SELECT t.* FROM ' . $targetClass->getClassName() . ' t WHERE ';
|
||||
$params = array();
|
||||
foreach ($this->_sourceToTargetKeyFields as $sourceKeyField => $targetKeyField) {
|
||||
if ($params) {
|
||||
$dql .= " AND ";
|
||||
}
|
||||
$dql .= "t.$targetKeyField = ?";
|
||||
$params[] = $entity->_rawGetField($sourceKeyField);
|
||||
$params[] = $sourceClass->getReflectionProperty($sourceKeyField)->getValue($entity);
|
||||
}
|
||||
|
||||
$otherEntity = $this->_targetClass->getEntityManager()
|
||||
->query($dql, $params)
|
||||
->getFirst();
|
||||
$otherEntity = $entityManager->query($dql, $params)->getFirst();
|
||||
|
||||
if ( ! $otherEntity) {
|
||||
$otherEntity = Doctrine_Null::$INSTANCE;
|
||||
$otherEntity = null;
|
||||
}
|
||||
$entity->_internalSetReference($this->_sourceFieldName, $otherEntity);
|
||||
$sourceClass->getReflectionProperty($this->_sourceFieldName)->setValue($entity, $otherEntity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
71
lib/Doctrine/ORM/VirtualProxy.php
Normal file
71
lib/Doctrine/ORM/VirtualProxy.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?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';
|
||||
require_once 'Orm/Ticket/AllTests.php';
|
||||
require_once 'Orm/Entity/AllTests.php';
|
||||
require_once 'Orm/Associations/AllTests.php';
|
||||
require_once 'Orm/Mapping/AllTests.php';
|
||||
|
||||
// Tests
|
||||
require_once 'Orm/UnitOfWorkTest.php';
|
||||
require_once 'Orm/EntityManagerTest.php';
|
||||
require_once 'Orm/EntityPersisterTest.php';
|
||||
require_once 'Orm/CommitOrderCalculatorTest.php';
|
||||
require_once 'Orm/ClassMetadataTest.php';
|
||||
|
||||
class Orm_AllTests
|
||||
{
|
||||
@ -34,13 +34,13 @@ class Orm_AllTests
|
||||
$suite->addTestSuite('Orm_EntityManagerTest');
|
||||
$suite->addTestSuite('Orm_EntityPersisterTest');
|
||||
$suite->addTestSuite('Orm_CommitOrderCalculatorTest');
|
||||
$suite->addTestSuite('Orm_ClassMetadataTest');
|
||||
|
||||
$suite->addTest(Orm_Query_AllTests::suite());
|
||||
$suite->addTest(Orm_Hydration_AllTests::suite());
|
||||
$suite->addTest(Orm_Entity_AllTests::suite());
|
||||
$suite->addTest(Orm_Ticket_AllTests::suite());
|
||||
$suite->addTest(Orm_Associations_AllTests::suite());
|
||||
$suite->addTest(Orm_Mapping_AllTests::suite());
|
||||
|
||||
return $suite;
|
||||
}
|
||||
|
32
tests/Orm/Mapping/AllTests.php
Normal file
32
tests/Orm/Mapping/AllTests.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?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();
|
||||
}
|
99
tests/Orm/Mapping/ClassMetadataFactoryTest.php
Normal file
99
tests/Orm/Mapping/ClassMetadataFactoryTest.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?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 {}
|
||||
|
@ -1,16 +1,11 @@
|
||||
<?php
|
||||
|
||||
#namespace Doctrine\Tests\ORM\Mapping;
|
||||
|
||||
require_once 'lib/DoctrineTestInit.php';
|
||||
|
||||
class Orm_ClassMetadataTest extends Doctrine_OrmTestCase
|
||||
{
|
||||
protected function setUp() {
|
||||
;
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
;
|
||||
}
|
||||
|
||||
class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase
|
||||
{
|
||||
public function testClassMetadataInstanceSerialization() {
|
||||
$cm = new Doctrine_ORM_Mapping_ClassMetadata('CmsUser');
|
||||
|
||||
@ -50,8 +45,4 @@ class Orm_ClassMetadataTest extends Doctrine_OrmTestCase
|
||||
$this->assertEquals('Bar', $oneOneMapping->getTargetEntityName());
|
||||
}
|
||||
|
||||
public function testTransientEntityIsManaged()
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
17
tests/lib/mocks/Doctrine_MetadataDriverMock.php
Normal file
17
tests/lib/mocks/Doctrine_MetadataDriverMock.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user