Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
c2ab01bf
Commit
c2ab01bf
authored
Jan 06, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added first ClassMetadataFactory tests.
parent
957a6b2c
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
324 additions
and
126 deletions
+324
-126
Configuration.php
lib/Doctrine/ORM/Configuration.php
+13
-1
EntityManager.php
lib/Doctrine/ORM/EntityManager.php
+8
-5
AssociationMapping.php
lib/Doctrine/ORM/Mapping/AssociationMapping.php
+2
-66
ClassMetadata.php
lib/Doctrine/ORM/Mapping/ClassMetadata.php
+17
-2
ClassMetadataFactory.php
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
+36
-11
ManyToManyMapping.php
lib/Doctrine/ORM/Mapping/ManyToManyMapping.php
+0
-1
OneToManyMapping.php
lib/Doctrine/ORM/Mapping/OneToManyMapping.php
+1
-1
OneToOneMapping.php
lib/Doctrine/ORM/Mapping/OneToOneMapping.php
+21
-23
VirtualProxy.php
lib/Doctrine/ORM/VirtualProxy.php
+71
-0
AllTests.php
tests/Orm/AllTests.php
+2
-2
AllTests.php
tests/Orm/Mapping/AllTests.php
+32
-0
ClassMetadataFactoryTest.php
tests/Orm/Mapping/ClassMetadataFactoryTest.php
+99
-0
ClassMetadataTest.php
tests/Orm/Mapping/ClassMetadataTest.php
+5
-14
Doctrine_MetadataDriverMock.php
tests/lib/mocks/Doctrine_MetadataDriverMock.php
+17
-0
No files found.
lib/Doctrine/ORM/Configuration.php
View file @
c2ab01bf
...
...
@@ -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
()
{
...
...
lib/Doctrine/ORM/EntityManager.php
View file @
c2ab01bf
...
...
@@ -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
;
}
...
...
lib/Doctrine/ORM/Mapping/AssociationMapping.php
View file @
c2ab01bf
...
...
@@ -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
);
}
lib/Doctrine/ORM/Mapping/ClassMetadata.php
View file @
c2ab01bf
...
...
@@ -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.
*
...
...
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
View file @
c2ab01bf
...
...
@@ -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\Class
Metadata
*/
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
);
}
}
...
...
lib/Doctrine/ORM/Mapping/ManyToManyMapping.php
View file @
c2ab01bf
...
...
@@ -85,4 +85,3 @@ class Doctrine_ORM_Mapping_ManyToManyMapping extends Doctrine_ORM_Mapping_Associ
}
}
?>
\ No newline at end of file
lib/Doctrine/ORM/Mapping/OneToManyMapping.php
View file @
c2ab01bf
...
...
@@ -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
)
{
}
...
...
lib/Doctrine/ORM/Mapping/OneToOneMapping.php
View file @
c2ab01bf
...
...
@@ -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
);
}
}
?>
\ No newline at end of file
lib/Doctrine/ORM/VirtualProxy.php
0 → 100644
View file @
c2ab01bf
<?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
);
}
}
?>
tests/Orm/AllTests.php
View file @
c2ab01bf
...
...
@@ -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
;
}
...
...
tests/Orm/Mapping/AllTests.php
0 → 100644
View file @
c2ab01bf
<?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
();
}
tests/Orm/Mapping/ClassMetadataFactoryTest.php
0 → 100644
View file @
c2ab01bf
<?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
{}
tests/Orm/ClassMetadataTest.php
→
tests/Orm/
Mapping/
ClassMetadataTest.php
View file @
c2ab01bf
<?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
()
{
;
}
}
\ No newline at end of file
tests/lib/mocks/Doctrine_MetadataDriverMock.php
0 → 100644
View file @
c2ab01bf
<?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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment