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
613d08f9
Commit
613d08f9
authored
May 17, 2008
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged dbal bugfixes from 0.11.
parent
7ffd4140
Changes
31
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
401 additions
and
976 deletions
+401
-976
ClassMetadata.php
lib/Doctrine/ClassMetadata.php
+41
-10
Factory.php
lib/Doctrine/ClassMetadata/Factory.php
+2
-2
Collection.php
lib/Doctrine/Collection.php
+12
-7
Connection.php
lib/Doctrine/Connection.php
+27
-507
Db2.php
lib/Doctrine/Connection/Db2.php
+2
-2
Mock.php
lib/Doctrine/Connection/Mock.php
+1
-1
Oracle.php
lib/Doctrine/Connection/Oracle.php
+55
-35
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+55
-16
Entity.php
lib/Doctrine/Entity.php
+43
-89
Exception.php
lib/Doctrine/Entity/Exception.php
+5
-0
EntityRepository.php
lib/Doctrine/EntityRepository.php
+5
-5
Abstract.php
lib/Doctrine/Hydrator/Abstract.php
+1
-1
RecordDriver.php
lib/Doctrine/Hydrator/RecordDriver.php
+2
-2
HydratorNew.php
lib/Doctrine/HydratorNew.php
+4
-0
Manager.php
lib/Doctrine/Manager.php
+1
-1
Mapper.php
lib/Doctrine/Mapper.php
+20
-69
Query.php
lib/Doctrine/Query.php
+7
-8
Abstract.php
lib/Doctrine/Query/Abstract.php
+3
-3
Relation.php
lib/Doctrine/Relation.php
+3
-4
Parser.php
lib/Doctrine/Relation/Parser.php
+2
-2
AccessTest.php
tests/Orm/Component/AccessTest.php
+7
-7
AllTests.php
tests/Orm/Component/AllTests.php
+0
-2
CollectionTest.php
tests/Orm/Component/CollectionTest.php
+2
-0
TestTest.php
tests/Orm/Component/TestTest.php
+0
-38
EntityManagerTest.php
tests/Orm/EntityManagerTest.php
+49
-0
BasicHydrationTest.php
tests/Orm/Hydration/BasicHydrationTest.php
+46
-44
UnitOfWorkTestCase.php
tests/Orm/UnitOfWorkTestCase.php
+2
-1
DoctrineTestInit.php
tests/lib/DoctrineTestInit.php
+2
-0
Doctrine_OrmTestCase.php
tests/lib/Doctrine_OrmTestCase.php
+0
-113
Doctrine_OrmTestSuite.php
tests/lib/Doctrine_OrmTestSuite.php
+1
-7
CmsUser.php
tests/models/cms/CmsUser.php
+1
-0
No files found.
lib/Doctrine/ClassMetadata.php
View file @
613d08f9
...
...
@@ -272,14 +272,12 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*
* @param string $entityName Name of the entity class the metadata info is used for.
*/
public
function
__construct
(
$entityName
,
Doctrine_
Connection
$conn
)
public
function
__construct
(
$entityName
,
Doctrine_
EntityManager
$em
)
{
$this
->
_entityName
=
$entityName
;
$this
->
_rootEntityName
=
$entityName
;
$this
->
_conn
=
$
conn
;
$this
->
_conn
=
$
em
;
$this
->
_parser
=
new
Doctrine_Relation_Parser
(
$this
);
$this
->
_filters
[]
=
new
Doctrine_Record_Filter_Standard
();
$this
->
setConfigurableParent
(
$this
->
_conn
);
}
/**
...
...
@@ -289,6 +287,11 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
{
return
$this
->
_conn
;
}
public
function
getEntityManager
()
{
return
$this
->
_conn
;
}
/**
* getComponentName
...
...
@@ -598,7 +601,13 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
$this
->
_columnCount
++
;
}
/**
* Gets the default length for a field type.
*
* @param unknown_type $type
* @return unknown
*/
private
function
_getDefaultLength
(
$type
)
{
switch
(
$type
)
{
...
...
@@ -625,6 +634,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return
25
;
}
}
/**
* Maps an embedded value object.
*
* @todo Implementation.
*/
public
function
mapEmbeddedValue
()
{
//...
}
/**
* setColumn
...
...
@@ -956,11 +975,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return
$this
->
getColumnDefinition
(
$columnName
);
}
/**
* Gets the mapping information for a field.
*
* @param string $fieldName
* @return array
*/
public
function
getMappingForField
(
$fieldName
)
{
$columnName
=
$this
->
getColumnName
(
$fieldName
);
return
$this
->
getColumnDefinition
(
$columnName
);
}
...
...
@@ -974,7 +998,13 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
{
return
$this
->
getTypeOfColumn
(
$this
->
getColumnName
(
$fieldName
));
}
/**
* Gets the type of a field.
*
* @param string $fieldName
* @return string
*/
public
function
getTypeOfField
(
$fieldName
)
{
return
$this
->
getTypeOfColumn
(
$this
->
getColumnName
(
$fieldName
));
...
...
@@ -1022,7 +1052,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/
public
function
addNamedQuery
(
$name
,
$query
)
{
//...
}
public
function
bindRelation
(
$args
,
$type
)
...
...
@@ -1622,7 +1652,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/
public
function
setTableName
(
$tableName
)
{
$this
->
setTableOption
(
'tableName'
,
$this
->
_conn
->
formatter
->
getTableName
(
$tableName
));
$this
->
setTableOption
(
'tableName'
,
$this
->
_conn
->
getConnection
()
->
formatter
->
getTableName
(
$tableName
));
}
/**
...
...
lib/Doctrine/ClassMetadata/Factory.php
View file @
613d08f9
...
...
@@ -44,9 +44,9 @@ class Doctrine_ClassMetadata_Factory
* @param $conn The connection to use.
* @param $driver The metadata driver to use.
*/
public
function
__construct
(
Doctrine_
Connection
$conn
,
$driver
)
public
function
__construct
(
Doctrine_
EntityManager
$em
,
$driver
)
{
$this
->
_conn
=
$
conn
;
$this
->
_conn
=
$
em
;
$this
->
_driver
=
$driver
;
}
...
...
lib/Doctrine/Collection.php
View file @
613d08f9
...
...
@@ -31,9 +31,12 @@
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @todo Rename to EntityCollection
*/
class
Doctrine_Collection
extends
Doctrine_Access
implements
Countable
,
IteratorAggregate
,
Serializable
{
protected
$_entityBaseType
;
/**
* An array containing the records of this collection.
*
...
...
@@ -101,10 +104,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param string $keyColumn The field name that will be used as the key
* in the collection.
*/
public
function
__construct
(
$
mapper
,
$keyField
=
null
)
public
function
__construct
(
$
entityBaseType
,
$keyField
=
null
)
{
if
(
is_string
(
$mapper
))
{
$mapper
=
Doctrine_Manager
::
getInstance
()
->
getMapper
(
$mapper
);
if
(
is_string
(
$entityBaseType
))
{
$this
->
_entityBaseType
=
$entityBaseType
;
$mapper
=
Doctrine_EntityManager
::
getManager
(
$entityBaseType
)
->
getEntityPersister
(
$entityBaseType
);
}
$this
->
_mapper
=
$mapper
;
...
...
@@ -204,16 +208,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
public
function
unserialize
(
$serialized
)
{
$manager
=
Doctrine_
Manager
::
getInstance
();
$connection
=
$manager
->
getC
urrentC
onnection
();
$manager
=
Doctrine_
EntityManager
::
getManager
();
$connection
=
$manager
->
getConnection
();
$array
=
unserialize
(
$serialized
);
foreach
(
$array
as
$name
=>
$values
)
{
$this
->
$name
=
$values
;
}
$this
->
_mapper
=
$
connection
->
getMapper
(
$this
->
_mapper
);
$this
->
_mapper
=
$
manager
->
getEntityPersister
(
$this
->
_entityBaseType
);
$keyColumn
=
isset
(
$array
[
'keyField'
])
?
$array
[
'keyField'
]
:
null
;
if
(
$keyColumn
===
null
)
{
...
...
@@ -506,6 +510,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
public
function
add
(
$record
,
$key
=
null
)
{
/** @TODO Use raw getters/setters */
if
(
!
$record
instanceof
Doctrine_Entity
)
{
throw
new
Doctrine_Record_Exception
(
'Value variable in set is not an instance of Doctrine_Entity.'
);
}
...
...
lib/Doctrine/Connection.php
View file @
613d08f9
This diff is collapsed.
Click to expand it.
lib/Doctrine/Connection/Db2.php
View file @
613d08f9
...
...
@@ -55,8 +55,8 @@ class Doctrine_Connection_Db2 extends Doctrine_Connection
$col
=
explode
(
'select'
,
$select
);
$sql
=
'WITH OFFSET AS('
.
$select
.
', ROW_NUMBER() '
.
'OVER(ORDER BY '
.
$col
[
1
]
.
') AS d
ctrn
_rownum FROM '
.
$table
.
')'
.
$select
.
'FROM OFFSET WHERE d
ctrn
_rownum BETWEEN '
.
$offset
.
'OVER(ORDER BY '
.
$col
[
1
]
.
') AS d
octrine
_rownum FROM '
.
$table
.
')'
.
$select
.
'FROM OFFSET WHERE d
octrine
_rownum BETWEEN '
.
$offset
.
'AND '
.
(
$offset
+
$limit
-
1
);
return
$sql
;
}
...
...
lib/Doctrine/Connection/Mock.php
View file @
613d08f9
...
...
@@ -44,7 +44,7 @@ class Doctrine_Connection_Mock extends Doctrine_Connection_Common
* @param Doctrine_Manager $manager
* @param PDO|Doctrine_Adapter $adapter database handler
*/
public
function
__construct
(
Doctrine_Manager
$manager
,
$adapter
)
public
function
__construct
()
{
}
...
...
lib/Doctrine/Connection/Oracle.php
View file @
613d08f9
...
...
@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine
::
autoload
(
'Doctrine_Connection'
);
/**
* Doctrine_Connection_Oracle
*
...
...
@@ -80,39 +80,59 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection
$this
->
exec
(
'ALTER SESSION SET NLS_DATE_FORMAT = "'
.
$format
.
'"'
);
}
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query query to modify
* @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset
* @return string the modified query
*/
public
function
modifyLimitQuery
(
$query
,
$limit
,
$offset
)
{
/**
$e = explode("select ",strtolower($query));
$e2 = explode(" from ",$e[1]);
$fields = $e2[0];
*/
$limit
=
(
int
)
$limit
;
$offset
=
(
int
)
$offset
;
if
(
preg_match
(
'/^\s*SELECT/i'
,
$query
))
{
if
(
!
preg_match
(
'/\sFROM\s/i'
,
$query
))
{
$query
.=
" FROM dual"
;
}
if
(
$limit
>
0
)
{
// taken from http://svn.ez.no/svn/ezcomponents/packages/Database
$max
=
$offset
+
$limit
;
if
(
$offset
>
0
)
{
$min
=
$offset
+
1
;
$query
=
'SELECT * FROM (SELECT a.*, ROWNUM dctrn_rownum FROM ('
.
$query
.
') a WHERE ROWNUM <= '
.
$max
.
') WHERE dctrn_rownum >= '
.
$min
;
}
else
{
$query
=
'SELECT a.* FROM ('
.
$query
.
') a WHERE ROWNUM <= '
.
$max
;
}
}
}
return
$query
;
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query query to modify
* @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset
* @return string the modified query
*/
public
function
modifyLimitQuery
(
$query
,
$limit
=
false
,
$offset
=
false
,
$isManip
=
false
)
{
return
$this
->
_createLimitSubquery
(
$query
,
$limit
,
$offset
);
}
private
function
_createLimitSubquery
(
$query
,
$limit
,
$offset
,
$column
=
null
)
{
$limit
=
(
int
)
$limit
;
$offset
=
(
int
)
$offset
;
if
(
preg_match
(
'/^\s*SELECT/i'
,
$query
))
{
if
(
!
preg_match
(
'/\sFROM\s/i'
,
$query
))
{
$query
.=
" FROM dual"
;
}
if
(
$limit
>
0
)
{
$max
=
$offset
+
$limit
;
$column
=
$column
===
null
?
'*'
:
$column
;
if
(
$offset
>
0
)
{
$min
=
$offset
+
1
;
$query
=
'SELECT b.'
.
$column
.
' FROM ('
.
'SELECT a.*, ROWNUM AS doctrine_rownum FROM ('
.
$query
.
') a '
.
') b '
.
'WHERE doctrine_rownum BETWEEN '
.
$min
.
' AND '
.
$max
;
}
else
{
$query
=
'SELECT a.'
.
$column
.
' FROM ('
.
$query
.
') a WHERE ROWNUM <= '
.
$max
;
}
}
}
return
$query
;
}
/**
* Creates the SQL for Oracle that can be used in the subquery for the limit-subquery
* algorithm.
*/
public
function
modifyLimitSubquery
(
Doctrine_ClassMetadata
$rootClass
,
$query
,
$limit
=
false
,
$offset
=
false
,
$isManip
=
false
)
{
// NOTE: no composite key support
$columnNames
=
$rootClass
->
getIdentifierColumnNames
();
if
(
count
(
$columnNames
)
>
1
)
{
throw
new
Doctrine_Connection_Exception
(
"Composite keys in LIMIT queries are "
.
"currently not supported."
);
}
$column
=
$columnNames
[
0
];
return
$this
->
_createLimitSubquery
(
$query
,
$limit
,
$offset
,
$column
);
}
}
\ No newline at end of file
lib/Doctrine/Connection/UnitOfWork.php
View file @
613d08f9
...
...
@@ -25,18 +25,21 @@
*
* Some terminology:
*
* <b>New entity</b>:
From the point of view of the unitOfWork is an entity tha
t
*
already has an identity but is not yet persisted into the database. This
*
is usually the case for all newly saved entities that use a SEQUENCE id
*
generator. Entities with an IDENTITY id generator get persisted as soon
*
as they're saved in order to obtain the identifier. Therefore entities that
*
use an IDENTITY id generator
never appear in the list of new entities of the UoW.
* <b>New entity</b>:
A new entity is an entity that already has an identity bu
t
*
is not yet persisted into the database. This is usually the case for all
*
newly saved entities that use a SEQUENCE id generator. Entities with an
*
IDENTITY id generator get persisted as soon as they're saved in order to
*
obtain the identifier. Therefore entities that use an IDENTITY id generator
* never appear in the list of new entities of the UoW.
*
* <b>Dirty entity</b>: ...
* <b>Dirty entity</b>: A dirty entity is a managed entity whose values have
* been altered.
*
* <b>Removed entity</b>: ...
* <b>Removed entity</b>: A removed entity is a managed entity that is scheduled
* for deletion from the database.
*
* <b>Clean entity</b>: ...
* <b>Clean entity</b>: A clean entity is a managed entity that has been fetched
* from the database and whose values have not yet been altered.
*
* @package Doctrine
* @subpackage Connection
...
...
@@ -226,7 +229,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$index
=
max
(
array_keys
(
$tree
));
}
$rels
=
$mapper
->
get
Table
()
->
getRelations
();
$rels
=
$mapper
->
get
ClassMetadata
()
->
getRelations
();
// group relations
...
...
@@ -355,7 +358,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
/**
* @param integer $oid object identifier
* @return boolean whether ot not the operation was successful
* @deprecated
* @deprecated The new implementation of detach() should remove the entity
* from the identity map.
*/
public
function
detach
(
Doctrine_Entity
$entity
)
{
...
...
@@ -371,6 +375,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
* Detaches all currently managed entities.
*
* @return integer The number of detached entities.
* @todo Deprecated. The new implementation should remove all entities from
* the identity map.
*/
public
function
detachAll
()
{
...
...
@@ -401,11 +407,24 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return
true
;
}
/**
* Enter description here...
*
* @param unknown_type $entityName
* @todo unify with detachAll()
*/
public
function
clearIdentitiesForEntity
(
$entityName
)
{
$this
->
_identityMap
[
$entityName
]
=
array
();
}
/**
* Removes an entity from the identity map.
*
* @param Doctrine_Entity $entity
* @return unknown
* @todo This will be the new detach().
*/
public
function
unregisterIdentity
(
Doctrine_Entity
$entity
)
{
$idHash
=
$this
->
getIdentifierHash
(
$entity
->
identifier
());
...
...
@@ -422,6 +441,13 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return
false
;
}
/**
* Finds an entity in the identity map by its identifier hash.
*
* @param unknown_type $idHash
* @param unknown_type $rootClassName
* @return unknown
*/
public
function
getByIdHash
(
$idHash
,
$rootClassName
)
{
return
$this
->
_identityMap
[
$rootClassName
][
$idHash
];
...
...
@@ -435,6 +461,12 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return
false
;
}
/**
* Gets the identifier hash for a set of identifier values.
*
* @param array $id
* @return string
*/
public
function
getIdentifierHash
(
array
$id
)
{
return
implode
(
' '
,
$id
);
...
...
@@ -448,15 +480,22 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
*/
public
function
contains
(
Doctrine_Entity
$entity
)
{
$id
=
implode
(
' '
,
$entity
->
identifier
());
if
(
!
$id
)
{
$id
Hash
=
$this
->
getIdentifierHash
(
$entity
->
identifier
());
if
(
!
$id
Hash
)
{
return
false
;
}
return
isset
(
$this
->
_identityMap
[
$entity
->
getClassMetadata
()
->
getRootClassName
()
][
$id
]);
return
isset
(
$this
->
_identityMap
[
$entity
->
getClassMetadata
()
->
getRootClassName
()]
[
$idHash
]);
}
/**
* Checks whether an identifier hash exists in the identity map.
*
* @param string $idHash
* @param string $rootClassName
* @return boolean
*/
public
function
containsIdHash
(
$idHash
,
$rootClassName
)
{
return
isset
(
$this
->
_identityMap
[
$rootClassName
][
$idHash
]);
...
...
lib/Doctrine/Entity.php
View file @
613d08f9
This diff is collapsed.
Click to expand it.
lib/Doctrine/Entity/Exception.php
View file @
613d08f9
...
...
@@ -23,6 +23,11 @@ class Doctrine_Entity_Exception extends Doctrine_Exception
return
new
self
(
"Invalid value. The value of a reference in a ManyToMany "
.
"association must be a Collection."
);
}
public
static
function
invalidField
(
$field
)
{
return
new
self
(
"Invalid field: '
$field
'."
);
}
}
?>
\ No newline at end of file
lib/Doctrine/EntityRepository.php
View file @
613d08f9
...
...
@@ -35,13 +35,13 @@
class
Doctrine_EntityRepository
{
protected
$_entityName
;
protected
$_
conn
;
protected
$_
em
;
protected
$_classMetadata
;
public
function
__construct
(
$entityName
,
Doctrine_ClassMetadata
$classMetadata
)
{
$this
->
_entityName
=
$entityName
;
$this
->
_
conn
=
$classMetadata
->
getConnection
();
$this
->
_
em
=
$classMetadata
->
getConnection
();
$this
->
_classMetadata
=
$classMetadata
;
}
...
...
@@ -59,7 +59,7 @@ class Doctrine_EntityRepository
if
(
!
empty
(
$alias
))
{
$alias
=
' '
.
trim
(
$alias
);
}
return
Doctrine_Query
::
create
(
$this
->
_
conn
)
->
from
(
$this
->
_entityName
.
$alias
);
return
Doctrine_Query
::
create
(
$this
->
_
em
)
->
from
(
$this
->
_entityName
.
$alias
);
}
/**
...
...
@@ -69,7 +69,7 @@ class Doctrine_EntityRepository
*/
public
function
clear
()
{
$this
->
_
conn
->
unitOfWork
->
clearIdentitiesForEntity
(
$this
->
_classMetadata
->
getRootClassName
());
$this
->
_
em
->
unitOfWork
->
clearIdentitiesForEntity
(
$this
->
_classMetadata
->
getRootClassName
());
}
/**
...
...
@@ -170,7 +170,7 @@ class Doctrine_EntityRepository
*/
public
function
findByDql
(
$dql
,
array
$params
=
array
(),
$hydrationMode
=
null
)
{
$query
=
new
Doctrine_Query
(
$this
->
_
conn
);
$query
=
new
Doctrine_Query
(
$this
->
_
em
);
$component
=
$this
->
getComponentName
();
$dql
=
'FROM '
.
$component
.
' WHERE '
.
$dql
;
...
...
lib/Doctrine/Hydrator/Abstract.php
View file @
613d08f9
...
...
@@ -63,7 +63,7 @@ abstract class Doctrine_Hydrator_Abstract
*
* @param Doctrine_Connection|null $connection
*/
public
function
__construct
(
Doctrine_
Connection
$em
)
public
function
__construct
(
Doctrine_
EntityManager
$em
)
{
$this
->
_em
=
$em
;
$this
->
_nullObject
=
Doctrine_Null
::
$INSTANCE
;
...
...
lib/Doctrine/Hydrator/RecordDriver.php
View file @
613d08f9
...
...
@@ -43,7 +43,7 @@ class Doctrine_Hydrator_RecordDriver
/** The EntityManager */
private
$_em
;
public
function
__construct
(
Doctrine_
Connection
$em
)
public
function
__construct
(
Doctrine_
EntityManager
$em
)
{
$this
->
_nullObject
=
Doctrine_Null
::
$INSTANCE
;
$this
->
_em
=
$em
;
...
...
@@ -93,7 +93,7 @@ class Doctrine_Hydrator_RecordDriver
public
function
getElement
(
array
$data
,
$className
)
{
return
$this
->
_em
->
createEntity
2
(
$className
,
$data
);
return
$this
->
_em
->
createEntity
(
$className
,
$data
);
}
public
function
addRelatedIndexedElement
(
Doctrine_Entity
$entity1
,
$property
,
...
...
lib/Doctrine/HydratorNew.php
View file @
613d08f9
...
...
@@ -375,6 +375,10 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
foreach
(
$data
as
$key
=>
$value
)
{
// Parse each column name only once. Cache the results.
if
(
!
isset
(
$cache
[
$key
]))
{
// check ignored names. fastest solution for now. if we get more we'll start
// to introduce a list.
if
(
$key
==
'doctrine_rownum'
)
continue
;
// cache general information like the column name <-> field name mapping
$e
=
explode
(
'__'
,
$key
);
$columnName
=
strtolower
(
array_pop
(
$e
));
...
...
lib/Doctrine/Manager.php
View file @
613d08f9
...
...
@@ -680,7 +680,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*/
public
function
getMapper
(
$componentName
)
{
return
$this
->
getConnectionForComponent
(
$componentName
)
->
get
Mapp
er
(
$componentName
);
return
$this
->
getConnectionForComponent
(
$componentName
)
->
get
EntityPersist
er
(
$componentName
);
}
/**
...
...
lib/Doctrine/Mapper.php
View file @
613d08f9
...
...
@@ -30,7 +30,6 @@
* @version $Revision: 3406 $
* @link www.phpdoctrine.org
* @since 2.0
* @todo Move all finder stuff to EntityRepository.
* @todo Rename to "EntityPersister" or similar.
*/
class
Doctrine_Mapper
...
...
@@ -69,6 +68,12 @@ class Doctrine_Mapper
*/
private
$_entityListeners
=
array
();
/**
* Enter description here...
*
* @var unknown_type
* @todo To EntityManager.
*/
private
$_dataTemplate
=
array
();
...
...
@@ -121,6 +126,7 @@ class Doctrine_Mapper
* @param $array an array where keys are field names and
* values representing field values
* @return Doctrine_Entity the created record object
* @todo To EntityManager.
*/
public
function
create
(
array
$array
=
array
())
{
...
...
@@ -158,24 +164,16 @@ class Doctrine_Mapper
}
}
public
function
detach
(
Doctrine_Entity
$entity
)
{
return
$this
->
_conn
->
unitOfWork
->
detach
(
$entity
);
}
/**
* E
xecutes a named query
.
* E
nter description here..
.
*
* @param string $queryName The name that was used when storing the query.
* @param array $params The query parameters.
* @return mixed The result.
* @deprecated
* @param Doctrine_Entity $entity
* @return unknown
* @todo To EntityManager
*/
public
function
executeNamedQuery
(
$queryName
,
$params
=
array
(),
$hydrationMode
=
Doctrine
::
HYDRATE_RECORD
)
public
function
detach
(
Doctrine_Entity
$entity
)
{
return
Doctrine_Manager
::
getInstance
()
->
createNamedQuery
(
$queryName
)
->
execute
(
$params
,
$hydrationMode
);
return
$this
->
_conn
->
unitOfWork
->
detach
(
$entity
);
}
/**
...
...
@@ -184,6 +182,7 @@ class Doctrine_Mapper
*
* @return void
* @todo what about a more descriptive name? clearIdentityMap?
* @todo To EntityManager
*/
public
function
clear
()
{
...
...
@@ -197,6 +196,7 @@ class Doctrine_Mapper
* @param Doctrine_Entity $record record to be added
* @return boolean
* @todo Better name? registerRecord? Move elsewhere to the new location of the identity maps.
* @todo Remove.
*/
public
function
addRecord
(
Doctrine_Entity
$record
)
{
...
...
@@ -213,6 +213,7 @@ class Doctrine_Mapper
*
* @return boolean TRUE if the entity was previously not managed and is now managed,
* FALSE otherwise (the entity is already managed).
* @todo Remove.
*/
public
function
manage
(
Doctrine_Entity
$record
)
{
...
...
@@ -244,6 +245,7 @@ class Doctrine_Mapper
* returns a new record.
*
* @return Doctrine_Entity
* @todo To EntityManager.
*/
public
function
getRecord
(
array
$data
)
{
...
...
@@ -310,6 +312,7 @@ class Doctrine_Mapper
* applyInheritance
* @param $where query where part to be modified
* @return string query where part with column aggregation inheritance added
* @todo What to do with this? Remove if possible.
*/
final
public
function
applyInheritance
(
$where
)
{
...
...
@@ -357,6 +360,8 @@ class Doctrine_Mapper
* for the field can be skipped. Used i.e. during hydration to
* improve performance on large and/or complex results.
* @return mixed prepared value
* @todo To EntityManager. Make private and use in createEntity().
* .. Or, maybe better: Move to hydrator for performance reasons.
*/
public
function
prepareValue
(
$fieldName
,
$value
,
$typeHint
=
null
)
{
...
...
@@ -398,43 +403,6 @@ class Doctrine_Mapper
}
return
$value
;
}
/**
* Hydrates the given data into the entity.
*
*/
/*public function hydrate(Doctrine_Entity $entity, array $data)
{
$this->_values = array_merge($this->_values, $this->cleanData($data));
$this->_data = array_merge($this->_data, $data);
$this->_extractIdentifier(true);
}*/
/**
* getTree
*
* getter for associated tree
*
* @return mixed if tree return instance of Doctrine_Tree, otherwise returns false
* @todo Part of the NestedSet Behavior plugin. Move outta here some day...
*/
public
function
getTree
()
{
return
$this
->
_classMetadata
->
getTree
();
}
/**
* isTree
*
* determine if table acts as tree
*
* @return mixed if tree return true, otherwise returns false
* @todo Part of the NestedSet Behavior plugin. Move outta here some day...
*/
public
function
isTree
()
{
return
$this
->
_classMetadata
->
isTree
();
}
/**
* getComponentName
...
...
@@ -729,26 +697,11 @@ class Doctrine_Mapper
return
true
;
}
public
function
executeQuery
(
Doctrine_Query
$query
)
{
}
public
function
getTable
()
{
return
$this
->
_classMetadata
;
}
public
function
getClassMetadata
()
{
return
$this
->
_classMetadata
;
}
public
function
dump
()
{
var_dump
(
$this
->
_invokedMethods
);
}
public
function
free
()
{
$this
->
_mappingStrategy
=
null
;
...
...
@@ -759,8 +712,6 @@ class Doctrine_Mapper
return
$this
->
_mappingStrategy
;
}
public
function
getFieldName
(
$columnName
)
{
return
$this
->
_mappingStrategy
->
getFieldName
(
$columnName
);
...
...
lib/Doctrine/Query.php
View file @
613d08f9
...
...
@@ -1129,7 +1129,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$modifyLimit
=
true
;
if
(
!
empty
(
$this
->
_sqlParts
[
'limit'
])
||
!
empty
(
$this
->
_sqlParts
[
'offset'
]))
{
if
(
$needsSubQuery
)
{
$subquery
=
$this
->
getLimitSubquery
();
// what about composite keys?
...
...
@@ -1138,7 +1137,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
switch
(
strtolower
(
$this
->
_conn
->
getDriverName
()))
{
case
'mysql'
:
// mysql doesn't support LIMIT in subqueries
$list
=
$this
->
_conn
->
execute
(
$subquery
,
$params
)
->
fetchAll
(
Doctrine
::
FETCH_COLUMN
);
$list
=
$this
->
_conn
->
execute
(
$subquery
,
$params
)
->
fetchAll
(
Doctrine
::
FETCH_COLUMN
);
$subquery
=
implode
(
', '
,
array_map
(
array
(
$this
->
_conn
,
'quote'
),
$list
));
break
;
case
'pgsql'
:
...
...
@@ -1192,18 +1191,18 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
*/
public
function
getLimitSubquery
()
{
$map
=
reset
(
$this
->
_queryComponents
);
$table
=
$map
[
'table'
];
$map
=
reset
(
$this
->
_queryComponents
);
$table
=
$map
[
'table'
];
$componentAlias
=
key
(
$this
->
_queryComponents
);
// get short alias
$alias
=
$this
->
getTableAlias
(
$componentAlias
);
$alias
=
$this
->
getTableAlias
(
$componentAlias
);
// what about composite keys?
$idFieldNames
=
(
array
)
$table
->
getIdentifier
();
$primaryKey
=
$alias
.
'.'
.
$table
->
getColumnName
(
$idFieldNames
[
0
]);
// initialize the base of the subquery
$subquery
=
'SELECT DISTINCT '
.
$this
->
_conn
->
quoteIdentifier
(
$primaryKey
);
$subquery
=
'SELECT DISTINCT '
.
$this
->
_conn
->
quoteIdentifier
(
$primaryKey
);
$driverName
=
$this
->
_conn
->
getAttribute
(
Doctrine
::
ATTR_DRIVER_NAME
);
...
...
@@ -1261,7 +1260,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$subquery
.=
(
!
empty
(
$this
->
_sqlParts
[
'orderby'
]))
?
' ORDER BY '
.
implode
(
', '
,
$this
->
_sqlParts
[
'orderby'
])
:
''
;
// add driver specific limit clause
$subquery
=
$this
->
_conn
->
modifyLimit
Query
(
$subquery
,
$this
->
_sqlParts
[
'limit'
],
$this
->
_sqlParts
[
'offset'
]);
$subquery
=
$this
->
_conn
->
modifyLimit
Subquery
(
$table
,
$subquery
,
$this
->
_sqlParts
[
'limit'
],
$this
->
_sqlParts
[
'offset'
]);
$parts
=
$this
->
_tokenizer
->
quoteExplode
(
$subquery
,
' '
,
"'"
,
"'"
);
...
...
@@ -1643,7 +1642,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$this
->
_sqlParts
[
'from'
][]
=
$queryPart
;
//echo "<br /><br />" . $table->getComponentName() . "---3---" . $name . "<br /><br />";
$this
->
_queryComponents
[
$componentAlias
]
=
array
(
'table'
=>
$table
,
'mapper'
=>
$this
->
_conn
->
get
Mapp
er
(
$name
),
'map'
=>
null
);
'table'
=>
$table
,
'mapper'
=>
$this
->
_conn
->
get
EntityPersist
er
(
$name
),
'map'
=>
null
);
return
$table
;
}
...
...
lib/Doctrine/Query/Abstract.php
View file @
613d08f9
...
...
@@ -530,7 +530,7 @@ abstract class Doctrine_Query_Abstract
{
$table
=
$this
->
_conn
->
getMetadata
(
$componentName
);
$tableAlias
=
$this
->
getSqlTableAlias
(
$componentAlias
,
$table
->
getTableName
());
$customJoins
=
$this
->
_conn
->
get
Mapp
er
(
$componentName
)
->
getCustomJoins
();
$customJoins
=
$this
->
_conn
->
get
EntityPersist
er
(
$componentName
)
->
getCustomJoins
();
$sql
=
''
;
foreach
(
$customJoins
as
$componentName
=>
$joinType
)
{
$joinedTable
=
$this
->
_conn
->
getMetadata
(
$componentName
);
...
...
@@ -1051,12 +1051,12 @@ abstract class Doctrine_Query_Abstract
$e
=
explode
(
'.'
,
$components
[
0
]);
if
(
count
(
$e
)
===
1
)
{
$queryComponents
[
$alias
][
'mapper'
]
=
$this
->
_conn
->
getMapper
(
$e
[
0
]);
$queryComponents
[
$alias
][
'table'
]
=
$queryComponents
[
$alias
][
'mapper'
]
->
get
Table
();
$queryComponents
[
$alias
][
'table'
]
=
$queryComponents
[
$alias
][
'mapper'
]
->
get
ClassMetadata
();
}
else
{
$queryComponents
[
$alias
][
'parent'
]
=
$e
[
0
];
$queryComponents
[
$alias
][
'relation'
]
=
$queryComponents
[
$e
[
0
]][
'table'
]
->
getRelation
(
$e
[
1
]);
$queryComponents
[
$alias
][
'mapper'
]
=
$this
->
_conn
->
getMapper
(
$queryComponents
[
$alias
][
'relation'
]
->
getForeignComponentName
());
$queryComponents
[
$alias
][
'table'
]
=
$queryComponents
[
$alias
][
'mapper'
]
->
get
Table
();
$queryComponents
[
$alias
][
'table'
]
=
$queryComponents
[
$alias
][
'mapper'
]
->
get
ClassMetadata
();
}
if
(
isset
(
$components
[
1
]))
{
$queryComponents
[
$alias
][
'agg'
]
=
$components
[
1
];
...
...
lib/Doctrine/Relation.php
View file @
613d08f9
...
...
@@ -154,7 +154,7 @@ abstract class Doctrine_Relation implements ArrayAccess
}
}
$this
->
definition
=
$def
;
$this
->
_foreignMapper
=
$this
->
getTable
()
->
getConnection
()
->
get
Mapp
er
(
$def
[
'class'
]);
$this
->
_foreignMapper
=
$this
->
getTable
()
->
getConnection
()
->
get
EntityPersist
er
(
$def
[
'class'
]);
}
/**
...
...
@@ -257,9 +257,8 @@ abstract class Doctrine_Relation implements ArrayAccess
*/
final
public
function
getTable
()
{
return
Doctrine_Manager
::
getInstance
()
->
getConnectionForComponent
(
$this
->
definition
[
'class'
])
->
getMetadata
(
$this
->
definition
[
'class'
]);
return
Doctrine_EntityManager
::
getManager
(
$this
->
definition
[
'class'
])
->
getClassMetadata
(
$this
->
definition
[
'class'
]);
}
/**
...
...
lib/Doctrine/Relation/Parser.php
View file @
613d08f9
...
...
@@ -271,7 +271,7 @@ class Doctrine_Relation_Parser
*/
public
function
getImpl
(
array
&
$def
,
$key
)
{
$
conn
=
$this
->
_table
->
getConnection
();
$
em
=
$this
->
_table
->
getEntityManager
();
if
(
in_array
(
'Doctrine_Template'
,
class_parents
(
$def
[
$key
])))
{
$impl
=
$this
->
_table
->
getImpl
(
$def
[
$key
]);
if
(
$impl
===
null
)
{
...
...
@@ -280,7 +280,7 @@ class Doctrine_Relation_Parser
$def
[
$key
]
=
$impl
;
}
return
$
conn
->
get
Metadata
(
$def
[
$key
]);
return
$
em
->
getClass
Metadata
(
$def
[
$key
]);
}
protected
function
_isTemplate
(
$className
)
...
...
tests/Orm/Component/AccessTest.php
View file @
613d08f9
...
...
@@ -41,6 +41,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
public
function
setUp
()
{
parent
::
setUp
();
$em
=
new
Doctrine_EntityManager
(
new
Doctrine_Connection_Mock
());
$this
->
user
=
new
ForumUser
();
}
...
...
@@ -57,10 +58,10 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/**
* @test
*/
public
function
shouldMarkE
xistingFieldAs
SetOnNewRecord
()
public
function
shouldMarkE
mptyFieldAsNot
SetOnNewRecord
()
{
$this
->
assert
Tru
e
(
isset
(
$this
->
user
->
username
));
$this
->
assert
Tru
e
(
isset
(
$this
->
user
[
'username'
]));
$this
->
assert
Fals
e
(
isset
(
$this
->
user
->
username
));
$this
->
assert
Fals
e
(
isset
(
$this
->
user
[
'username'
]));
}
/**
...
...
@@ -113,7 +114,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/**
* @test
* @expectedException Doctrine_
Record
_Exception
* @expectedException Doctrine_
Entity
_Exception
*/
public
function
shouldNotBeAbleToSetNonExistantField
()
{
...
...
@@ -122,7 +123,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/**
* @test
* @expectedException Doctrine_
Record
_Exception
* @expectedException Doctrine_
Entity
_Exception
*/
public
function
shouldNotBeAbleToSetNonExistantFieldWithOffset
()
{
...
...
@@ -131,14 +132,13 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/**
* @test
* @expectedException Doctrine_
Record
_Exception
* @expectedException Doctrine_
Entity
_Exception
*/
public
function
shouldNotBeAbleToSetNonExistantFieldAsPartInSetArray
()
{
$this
->
user
->
setArray
(
array
(
'rat'
=>
'meus'
,
'id'
=>
22
));
}
...
...
tests/Orm/Component/AllTests.php
View file @
613d08f9
...
...
@@ -6,7 +6,6 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
require_once
'lib/DoctrineTestInit.php'
;
// Tests
require_once
'Orm/Component/TestTest.php'
;
require_once
'Orm/Component/AccessTest.php'
;
require_once
'Orm/Component/CollectionTest.php'
;
...
...
@@ -21,7 +20,6 @@ class Orm_Component_AllTests
{
$suite
=
new
Doctrine_TestSuite
(
'Doctrine Orm Component'
);
$suite
->
addTestSuite
(
'Orm_Component_TestTest'
);
$suite
->
addTestSuite
(
'Orm_Component_AccessTest'
);
$suite
->
addTestSuite
(
'Orm_Component_CollectionTest'
);
...
...
tests/Orm/Component/CollectionTest.php
View file @
613d08f9
...
...
@@ -40,6 +40,8 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase
public
function
setUp
()
{
parent
::
setUp
();
$em
=
new
Doctrine_EntityManager
(
new
Doctrine_Connection_Mock
());
$this
->
coll
=
new
Doctrine_Collection
(
'ForumUser'
);
//we create a CmsUser with username as key column and add a user to it
...
...
tests/Orm/Component/TestTest.php
deleted
100644 → 0
View file @
7ffd4140
<?php
require_once
'lib/DoctrineTestInit.php'
;
class
Orm_Component_TestTest
extends
Doctrine_OrmTestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
loadFixtures
(
'forum'
,
'common'
,
array
(
'users'
,
'admins'
));
}
public
function
testTest
()
{
$this
->
assertEquals
(
0
,
0
);
}
public
function
testFixture
()
{
$forumUsers
=
$this
->
sharedFixture
[
'connection'
]
->
query
(
"FROM ForumUser u"
);
$this
->
assertEquals
(
2
,
count
(
$forumUsers
));
$forumUsers
[
0
]
->
delete
();
unset
(
$forumUsers
[
0
]);
$this
->
assertEquals
(
1
,
count
(
$forumUsers
));
}
public
function
testFixture2
()
{
$forumUsers
=
$this
->
sharedFixture
[
'connection'
]
->
query
(
"FROM ForumUser u"
);
$this
->
assertEquals
(
2
,
count
(
$forumUsers
));
}
public
function
testFixture3
()
{
$forumAdmins
=
$this
->
sharedFixture
[
'connection'
]
->
query
(
"FROM ForumAdministrator adm"
);
$this
->
assertEquals
(
1
,
count
(
$forumAdmins
));
$forumAdmins
[
0
]
->
delete
();
}
}
\ No newline at end of file
tests/Orm/EntityManagerTest.php
0 → 100644
View file @
613d08f9
<?php
require_once
'lib/DoctrineTestInit.php'
;
class
Orm_EntityManagerTest
extends
Doctrine_OrmTestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
}
protected
function
tearDown
()
{
Doctrine_EntityManager
::
unbindAllManagers
();
Doctrine_EntityManager
::
releaseAllManagers
();
parent
::
tearDown
();
}
public
function
testInstantiationRegistersInstanceInStaticMap
()
{
$em
=
new
Doctrine_EntityManager
(
new
Doctrine_Connection_Mock
());
$this
->
assertSame
(
$em
,
Doctrine_EntityManager
::
getManager
(
'SomeEntity'
));
}
public
function
testStaticGetManagerThrowsExceptionIfNoManagerAvailable
()
{
try
{
Doctrine_EntityManager
::
getManager
(
'SomeEntity'
);
$this
->
fail
(
"Expected exception not thrown."
);
}
catch
(
Doctrine_EntityManager_Exception
$ex
)
{}
}
public
function
testBindingValidEntityToNamedManager
()
{
$em
=
new
Doctrine_EntityManager
(
new
Doctrine_Connection_Mock
(
null
),
'myEM'
);
Doctrine_EntityManager
::
bindEntityToManager
(
'SomeEntity'
,
'myEM'
);
$this
->
assertSame
(
$em
,
Doctrine_EntityManager
::
getManager
(
'SomeEntity'
));
}
public
function
testBindingEntityToInvalidManagerThrowsExceptionOnRetrieval
()
{
// will work. we don't check the existence of the EM during binding
Doctrine_EntityManager
::
bindEntityToManager
(
'SomeEntity'
,
'myEM'
);
// exception on access
try
{
Doctrine_EntityManager
::
getManager
(
'SomeEntity'
);
$this
->
fail
();
}
catch
(
Doctrine_EntityManager_Exception
$ex
)
{}
}
}
\ No newline at end of file
tests/Orm/Hydration/BasicHydrationTest.php
View file @
613d08f9
This diff is collapsed.
Click to expand it.
tests/Orm/UnitOfWorkTestCase.php
View file @
613d08f9
...
...
@@ -8,8 +8,9 @@ class Orm_UnitOfWorkTestCase extends Doctrine_OrmTestCase
protected
function
setUp
()
{
parent
::
setUp
();
$em
=
new
Doctrine_EntityManager
(
new
Doctrine_Connection_Mock
());
$this
->
_user
=
new
ForumUser
();
$this
->
_unitOfWork
=
$
this
->
sharedFixture
[
'connection'
]
->
unitOfWork
;
$this
->
_unitOfWork
=
$
em
->
getUnitOfWork
()
;
}
protected
function
tearDown
()
{
...
...
tests/lib/DoctrineTestInit.php
View file @
613d08f9
...
...
@@ -5,8 +5,10 @@ require_once 'Doctrine_TestCase.php';
require_once
'Doctrine_TestUtil.php'
;
require_once
'Doctrine_DbalTestCase.php'
;
require_once
'Doctrine_OrmTestCase.php'
;
require_once
'Doctrine_OrmFunctionalTestCase.php'
;
require_once
'Doctrine_TestSuite.php'
;
require_once
'Doctrine_OrmTestSuite.php'
;
require_once
'Doctrine_OrmFunctionalTestSuite.php'
;
require_once
'Doctrine_DbalTestSuite.php'
;
require_once
'../lib/Doctrine.php'
;
...
...
tests/lib/Doctrine_OrmTestCase.php
View file @
613d08f9
...
...
@@ -5,118 +5,5 @@
*/
class
Doctrine_OrmTestCase
extends
Doctrine_TestCase
{
/**
* The currently loaded model names of the fixtures for the testcase.
*/
private
$_loadedFixtures
=
array
();
/**
* All loaded fixtures during test execution. Common fixture cache.
*/
private
static
$_fixtures
=
array
();
/**
* The names of all tables that were already exported. Each table is exported
* only once. Then it's just filled & erased for each testmethod in a testcase
* that uses one or more fixtures.
*/
private
static
$_exportedTables
=
array
();
/**
* setUp()
*
* Note: This setUp() and the one of DbalTestCase currently look identical. However,
* please dont pull this method up. In the future with a separation of Dbal/Orm
* this setUp() will take care of a ORM connection/session/manager initialization
* and the DBAL setUp() will take care of just a DBAL connection.
*/
protected
function
setUp
()
{
// Setup a db connection if there is none, yet. This makes it possible
// to run tests that use a connection standalone.
if
(
!
isset
(
$this
->
sharedFixture
[
'connection'
]))
{
$this
->
sharedFixture
[
'connection'
]
=
Doctrine_TestUtil
::
getConnection
();
}
}
/**
* Loads a data fixture into the database. This method must only be called
* from within the setUp() method of testcases. The database will then be
* populated with fresh data of all loaded fixtures for each test method.
*
* WARNING: A single testcase should never load fixtures from different scenarios of
* the same package as the concistency and uniqueness of keys is not guaranteed.
*
* @param string $package The package name. Must be one of Doctrine's test model packages
* (forum, cms or ecommerce).
* @param string $scenario The fixture scenario. A model package can have many fixture
* scenarios. Within a scenario all primary keys and foreign keys
* of fixtures are consistent and unique.
* @param string $name The name of the fixture to load from the specified package.
*/
protected
function
loadFixture
(
$package
,
$scenario
,
$name
)
{
$uniqueName
=
$package
.
'/'
.
$scenario
.
'/'
.
$name
;
if
(
!
isset
(
self
::
$_fixtures
[
$uniqueName
]))
{
// load fixture file
$fixtureFile
=
'fixtures'
.
DIRECTORY_SEPARATOR
.
$package
.
DIRECTORY_SEPARATOR
.
$scenario
.
DIRECTORY_SEPARATOR
.
$name
.
'.php'
;
require
$fixtureFile
;
self
::
$_fixtures
[
$uniqueName
]
=
$fixture
;
}
$fixture
=
self
::
$_fixtures
[
$uniqueName
];
$this
->
_loadedFixtures
[]
=
$fixture
[
'model'
];
$conn
=
$this
->
sharedFixture
[
'connection'
];
$classMetadata
=
$conn
->
getClassMetadata
(
$fixture
[
'model'
]);
$tableName
=
$classMetadata
->
getTableName
();
if
(
!
in_array
(
$tableName
,
self
::
$_exportedTables
))
{
$conn
->
export
->
exportClasses
(
array
(
$fixture
[
'model'
]));
self
::
$_exportedTables
[]
=
$tableName
;
}
foreach
(
$fixture
[
'rows'
]
as
$row
)
{
$conn
->
insert
(
$tableName
,
$row
);
}
}
/**
* Loads multiple fixtures of the same package and scenario.
* This method must only be called from within the setUp() method of testcases.
* The database will then be populated with fresh data of all loaded fixtures for each
* test method.
*
* WARNING: A single testcase should never load fixtures from different scenarios of
* the same package as the concistency and uniqueness of keys is not guaranteed.
*
* @param string $package The package name. Must be one of Doctrine's test model packages
* (forum, cms or ecommerce).
* @param string $scenario The fixture scenario. A model package can have many fixture
* scenarios. Within a scenario all primary keys and foreign keys
* of fixtures are consistent and unique.
* @param array $names The names of the fixtures to load from the specified package.
*/
protected
function
loadFixtures
(
$package
,
$scenario
,
array
$names
)
{
foreach
(
$names
as
$name
)
{
$this
->
loadFixture
(
$package
,
$scenario
,
$name
);
}
}
/**
* Sweeps the database tables of all used fixtures.
*/
protected
function
tearDown
()
{
$conn
=
$this
->
sharedFixture
[
'connection'
];
foreach
(
array_reverse
(
$this
->
_loadedFixtures
)
as
$model
)
{
$conn
->
exec
(
"DELETE FROM "
.
$conn
->
getClassMetadata
(
$model
)
->
getTableName
());
}
}
}
\ No newline at end of file
tests/lib/Doctrine_OrmTestSuite.php
View file @
613d08f9
...
...
@@ -8,11 +8,5 @@
*/
class
Doctrine_OrmTestSuite
extends
Doctrine_TestSuite
{
protected
function
setUp
()
{
$this
->
sharedFixture
[
'connection'
]
=
Doctrine_TestUtil
::
getConnection
();
}
protected
function
tearDown
()
{}
}
\ No newline at end of file
tests/models/cms/CmsUser.php
View file @
613d08f9
...
...
@@ -4,6 +4,7 @@ class CmsUser extends Doctrine_Entity
public
static
function
initMetadata
(
$class
)
{
$class
->
mapColumn
(
'id'
,
'integer'
,
4
,
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
));
$class
->
mapColumn
(
'status'
,
'string'
,
50
);
$class
->
mapColumn
(
'username'
,
'string'
,
255
);
$class
->
mapColumn
(
'name'
,
'string'
,
255
);
...
...
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