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
7363fc3e
Commit
7363fc3e
authored
Jan 06, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More ClassMetadataFactory tests
parent
c2ab01bf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
19 deletions
+58
-19
ClassMetadata.php
lib/Doctrine/ORM/Mapping/ClassMetadata.php
+1
-0
ClassMetadataFactory.php
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
+1
-6
AnnotationDriver.php
lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
+3
-1
EntityPersisterTest.php
tests/Orm/EntityPersisterTest.php
+11
-11
ClassMetadataFactoryTest.php
tests/Orm/Mapping/ClassMetadataFactoryTest.php
+42
-1
No files found.
lib/Doctrine/ORM/Mapping/ClassMetadata.php
View file @
7363fc3e
...
...
@@ -340,6 +340,7 @@ class Doctrine_ORM_Mapping_ClassMetadata
public
function
__construct
(
$entityName
)
{
$this
->
_entityName
=
$entityName
;
$this
->
_tableName
=
$this
->
_entityName
;
$this
->
_rootEntityName
=
$entityName
;
$this
->
_reflectionClass
=
new
ReflectionClass
(
$entityName
);
$reflectionProps
=
$this
->
_reflectionClass
->
getProperties
();
...
...
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
View file @
7363fc3e
...
...
@@ -132,6 +132,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
$subClass
->
setInheritanceType
(
$parent
->
getInheritanceType
());
$subClass
->
setDiscriminatorMap
(
$parent
->
getDiscriminatorMap
());
$subClass
->
setDiscriminatorColumn
(
$parent
->
getDiscriminatorColumn
());
$subClass
->
setIdGeneratorType
(
$parent
->
getIdGeneratorType
());
$this
->
_addInheritedFields
(
$subClass
,
$parent
);
$this
->
_addInheritedRelations
(
$subClass
,
$parent
);
$this
->
_loadClassMetadata
(
$subClass
,
$subclassName
);
...
...
@@ -205,12 +206,6 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
// load user-specified mapping metadata through the driver
$this
->
_driver
->
loadMetadataForClass
(
$name
,
$class
);
// set default table name, if necessary
$tableName
=
$class
->
getTableName
();
if
(
!
isset
(
$tableName
))
{
$class
->
setTableName
(
Doctrine
::
tableize
(
$class
->
getClassName
()));
}
// Complete Id generator mapping. If AUTO is specified we choose the generator
// most appropriate for the target platform.
...
...
lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
View file @
7363fc3e
...
...
@@ -28,7 +28,9 @@ class Doctrine_ORM_Mapping_Driver_AnnotationDriver {
throw
new
Doctrine_ORM_Exceptions_MappingException
(
"
$className
is no entity."
);
}
$metadata
->
setTableName
(
$entityAnnot
->
tableName
);
if
(
$entityAnnot
->
tableName
)
{
$metadata
->
setTableName
(
$entityAnnot
->
tableName
);
}
$metadata
->
setCustomRepositoryClass
(
$entityAnnot
->
repositoryClass
);
if
(
$inheritanceTypeAnnot
=
$annotClass
->
getAnnotation
(
'DoctrineInheritanceType'
))
{
...
...
tests/Orm/EntityPersisterTest.php
View file @
7363fc3e
...
...
@@ -47,8 +47,8 @@ class Orm_EntityPersisterTest extends Doctrine_OrmTestCase
$inserts
=
$this
->
_connMock
->
getInserts
();
//check
$this
->
assertEquals
(
1
,
count
(
$inserts
));
$this
->
assertTrue
(
isset
(
$inserts
[
'
forum_a
vatar'
]));
$this
->
assertEquals
(
1
,
count
(
$inserts
[
'
forum_a
vatar'
]));
$this
->
assertTrue
(
isset
(
$inserts
[
'
ForumA
vatar'
]));
$this
->
assertEquals
(
1
,
count
(
$inserts
[
'
ForumA
vatar'
]));
$this
->
assertEquals
(
null
,
$user
->
avatar
->
id
);
$user
->
avatar
->
id
=
0
;
// Fake that we got an id
...
...
@@ -58,18 +58,18 @@ class Orm_EntityPersisterTest extends Doctrine_OrmTestCase
//check
$this
->
assertEquals
(
2
,
count
(
$inserts
));
$this
->
assertEquals
(
null
,
$user
->
id
);
$this
->
assertTrue
(
isset
(
$inserts
[
'
forum_u
ser'
]));
$this
->
assertEquals
(
1
,
count
(
$inserts
[
'
forum_u
ser'
]));
$this
->
assertEquals
(
3
,
count
(
$inserts
[
'
forum_u
ser'
][
0
]));
$this
->
assertTrue
(
isset
(
$inserts
[
'
ForumU
ser'
]));
$this
->
assertEquals
(
1
,
count
(
$inserts
[
'
ForumU
ser'
]));
$this
->
assertEquals
(
3
,
count
(
$inserts
[
'
ForumU
ser'
][
0
]));
//username column
$this
->
assertTrue
(
isset
(
$inserts
[
'
forum_u
ser'
][
0
][
'username'
]));
$this
->
assertEquals
(
'romanb'
,
$inserts
[
'
forum_u
ser'
][
0
][
'username'
]);
$this
->
assertTrue
(
isset
(
$inserts
[
'
ForumU
ser'
][
0
][
'username'
]));
$this
->
assertEquals
(
'romanb'
,
$inserts
[
'
ForumU
ser'
][
0
][
'username'
]);
//avatar_id join column
$this
->
assertTrue
(
isset
(
$inserts
[
'
forum_u
ser'
][
0
][
'avatar_id'
]));
$this
->
assertEquals
(
0
,
$inserts
[
'
forum_u
ser'
][
0
][
'avatar_id'
]);
$this
->
assertTrue
(
isset
(
$inserts
[
'
ForumU
ser'
][
0
][
'avatar_id'
]));
$this
->
assertEquals
(
0
,
$inserts
[
'
ForumU
ser'
][
0
][
'avatar_id'
]);
//dtype discriminator column
$this
->
assertTrue
(
isset
(
$inserts
[
'
forum_u
ser'
][
0
][
'dtype'
]));
$this
->
assertEquals
(
'user'
,
$inserts
[
'
forum_u
ser'
][
0
][
'dtype'
]);
$this
->
assertTrue
(
isset
(
$inserts
[
'
ForumU
ser'
][
0
][
'dtype'
]));
$this
->
assertEquals
(
'user'
,
$inserts
[
'
ForumU
ser'
][
0
][
'dtype'
]);
}
}
\ No newline at end of file
tests/Orm/Mapping/ClassMetadataFactoryTest.php
View file @
7363fc3e
...
...
@@ -13,12 +13,43 @@ require_once 'lib/mocks/Doctrine_MetadataDriverMock.php';
* @author robo
*/
class
Orm_Mapping_ClassMetadataFactoryTest
extends
Doctrine_OrmTestCase
{
public
function
testGetMetadataForSingleClass
()
{
//TODO
$mockPlatform
=
new
Doctrine_DatabasePlatformMock
();
$mockDriver
=
new
Doctrine_MetadataDriverMock
();
// Self-made metadata
$cm1
=
new
Doctrine_ORM_Mapping_ClassMetadata
(
'CMFTest_Entity1'
);
// Add a mapped field
$cm1
->
mapField
(
array
(
'fieldName'
=>
'name'
,
'type'
=>
'string'
));
// and a mapped association
$cm1
->
mapOneToOne
(
array
(
'fieldName'
=>
'other'
,
'targetEntity'
=>
'Other'
,
'mappedBy'
=>
'this'
));
// and an id generator type
$cm1
->
setIdGeneratorType
(
'auto'
);
// SUT
$cmf
=
new
ClassMetadataFactoryTestSubject
(
$mockDriver
,
$mockPlatform
);
$cmf
->
setMetadataForClass
(
'CMFTest_Entity1'
,
$cm1
);
// Prechecks
$this
->
assertEquals
(
array
(),
$cm1
->
getParentClasses
());
$this
->
assertEquals
(
'none'
,
$cm1
->
getInheritanceType
());
$this
->
assertTrue
(
$cm1
->
hasField
(
'name'
));
$this
->
assertEquals
(
1
,
count
(
$cm1
->
getAssociationMappings
()));
$this
->
assertEquals
(
'auto'
,
$cm1
->
getIdGeneratorType
());
// Go
$cm1
=
$cmf
->
getMetadataFor
(
'CMFTest_Entity1'
);
$this
->
assertEquals
(
array
(),
$cm1
->
getParentClasses
());
$this
->
assertTrue
(
$cm1
->
hasField
(
'name'
));
// The default fallback for id generation is the table strategy
$this
->
assertEquals
(
'table'
,
$cm1
->
getIdGeneratorType
());
}
public
function
testGetMetadataForClassInHierarchy
()
{
$mockPlatform
=
new
Doctrine_DatabasePlatformMock
();
$mockPlatform
->
setPrefersIdentityColumns
(
true
);
$mockDriver
=
new
Doctrine_MetadataDriverMock
();
// Self-made metadata
...
...
@@ -28,6 +59,9 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase {
$cm1
->
mapField
(
array
(
'fieldName'
=>
'name'
,
'type'
=>
'string'
));
// and a mapped association
$cm1
->
mapOneToOne
(
array
(
'fieldName'
=>
'other'
,
'targetEntity'
=>
'Other'
,
'mappedBy'
=>
'this'
));
// and an id generator type
$cm1
->
setIdGeneratorType
(
'auto'
);
$cm2
=
new
Doctrine_ORM_Mapping_ClassMetadata
(
'CMFTest_Entity2'
);
$cm3
=
new
Doctrine_ORM_Mapping_ClassMetadata
(
'CMFTest_Entity3'
);
...
...
@@ -48,6 +82,8 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase {
$this
->
assertEquals
(
1
,
count
(
$cm1
->
getAssociationMappings
()));
$this
->
assertEquals
(
0
,
count
(
$cm2
->
getAssociationMappings
()));
$this
->
assertEquals
(
0
,
count
(
$cm3
->
getAssociationMappings
()));
$this
->
assertEquals
(
'none'
,
$cm2
->
getIdGeneratorType
());
$this
->
assertEquals
(
'none'
,
$cm3
->
getIdGeneratorType
());
// Go
$cm3
=
$cmf
->
getMetadataFor
(
'CMFTest_Entity3'
);
...
...
@@ -70,6 +106,11 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase {
$this
->
assertEquals
(
1
,
count
(
$cm3
->
getAssociationMappings
()));
$this
->
assertTrue
(
$cm2
->
hasAssociation
(
'other'
));
$this
->
assertTrue
(
$cm3
->
hasAssociation
(
'other'
));
// Id generator 'auto' should have been resolved to 'identity' as preferred by our
// mock platform (see above). And it should be inherited.
$this
->
assertEquals
(
'identity'
,
$cm1
->
getIdGeneratorType
());
$this
->
assertEquals
(
'identity'
,
$cm2
->
getIdGeneratorType
());
$this
->
assertEquals
(
'identity'
,
$cm3
->
getIdGeneratorType
());
}
}
...
...
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