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
efaaf83e
Commit
efaaf83e
authored
Jan 04, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test and collection cleanup
parent
b9ecb8de
Changes
48
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
48 changed files
with
309 additions
and
1033 deletions
+309
-1033
Collection.php
lib/Doctrine/Common/Collections/Collection.php
+62
-19
Collection.php
lib/Doctrine/ORM/Collection.php
+10
-441
EntityManager.php
lib/Doctrine/ORM/EntityManager.php
+40
-28
ObjectDriver.php
lib/Doctrine/ORM/Internal/Hydration/ObjectDriver.php
+1
-1
NativeQuery.php
lib/Doctrine/ORM/NativeQuery.php
+1
-1
Query.php
lib/Doctrine/ORM/Query.php
+9
-11
CacheHandler.php
lib/Doctrine/ORM/Query/CacheHandler.php
+4
-3
UnitOfWork.php
lib/Doctrine/ORM/UnitOfWork.php
+56
-16
AllTests.php
tests/AllTests.php
+1
-0
AllTests.php
tests/Orm/AllTests.php
+2
-2
CommitOrderCalculatorTest.php
tests/Orm/CommitOrderCalculatorTest.php
+5
-6
AccessTest.php
tests/Orm/Component/AccessTest.php
+0
-189
AllTests.php
tests/Orm/Component/AllTests.php
+0
-32
CollectionTest.php
tests/Orm/Component/CollectionTest.php
+0
-130
AccessorTest.php
tests/Orm/Entity/AccessorTest.php
+1
-0
ConstructorTest.php
tests/Orm/Entity/ConstructorTest.php
+1
-2
EntityManagerFactoryTest.php
tests/Orm/EntityManagerFactoryTest.php
+0
-35
EntityManagerTest.php
tests/Orm/EntityManagerTest.php
+9
-2
BasicHydrationTest.php
tests/Orm/Hydration/BasicHydrationTest.php
+4
-1
IdentifierRecognitionTest.php
tests/Orm/Query/IdentifierRecognitionTest.php
+6
-0
UnitOfWorkTest.php
tests/Orm/UnitOfWorkTest.php
+8
-7
DoctrineTestInit.php
tests/lib/DoctrineTestInit.php
+4
-2
Doctrine_DbalTestCase.php
tests/lib/Doctrine_DbalTestCase.php
+3
-16
Doctrine_DbalTestSuite.php
tests/lib/Doctrine_DbalTestSuite.php
+5
-14
Doctrine_OrmFunctionalTestCase.php
tests/lib/Doctrine_OrmFunctionalTestCase.php
+3
-0
Doctrine_OrmFunctionalTestSuite.php
tests/lib/Doctrine_OrmFunctionalTestSuite.php
+4
-1
Doctrine_OrmTestCase.php
tests/lib/Doctrine_OrmTestCase.php
+15
-17
Doctrine_OrmTestSuite.php
tests/lib/Doctrine_OrmTestSuite.php
+4
-21
Doctrine_TestCase.php
tests/lib/Doctrine_TestCase.php
+3
-1
Doctrine_TestSuite.php
tests/lib/Doctrine_TestSuite.php
+4
-2
Doctrine_TestUtil.php
tests/lib/Doctrine_TestUtil.php
+2
-0
Doctrine_ClassMetadataMock.php
tests/lib/mocks/Doctrine_ClassMetadataMock.php
+2
-1
Doctrine_ConnectionMock.php
tests/lib/mocks/Doctrine_ConnectionMock.php
+4
-1
Doctrine_DatabasePlatformMock.php
tests/lib/mocks/Doctrine_DatabasePlatformMock.php
+4
-1
Doctrine_DriverConnectionMock.php
tests/lib/mocks/Doctrine_DriverConnectionMock.php
+2
-1
Doctrine_DriverMock.php
tests/lib/mocks/Doctrine_DriverMock.php
+2
-0
Doctrine_EntityManagerMock.php
tests/lib/mocks/Doctrine_EntityManagerMock.php
+2
-1
Doctrine_EntityPersisterMock.php
tests/lib/mocks/Doctrine_EntityPersisterMock.php
+3
-0
Doctrine_HydratorMockStatement.php
tests/lib/mocks/Doctrine_HydratorMockStatement.php
+3
-1
Doctrine_IdentityIdGeneratorMock.php
tests/lib/mocks/Doctrine_IdentityIdGeneratorMock.php
+3
-5
Doctrine_SequenceMock.php
tests/lib/mocks/Doctrine_SequenceMock.php
+2
-1
Doctrine_UnitOfWorkMock.php
tests/lib/mocks/Doctrine_UnitOfWorkMock.php
+2
-4
ForumAdministrator.php
tests/models/forum/ForumAdministrator.php
+2
-0
ForumAvatar.php
tests/models/forum/ForumAvatar.php
+1
-6
ForumBoard.php
tests/models/forum/ForumBoard.php
+3
-0
ForumCategory.php
tests/models/forum/ForumCategory.php
+3
-0
ForumEntry.php
tests/models/forum/ForumEntry.php
+3
-9
ForumUser.php
tests/models/forum/ForumUser.php
+1
-2
No files found.
lib/Doctrine/Common/Collections/Collection.php
View file @
efaaf83e
...
...
@@ -18,7 +18,7 @@
*
* @author robo
*/
class
Doctrine_Common_Collection
implements
Countable
,
IteratorAggregate
,
Serializable
,
ArrayAccess
{
class
Doctrine_Common_Collection
s_Collection
implements
Countable
,
IteratorAggregate
,
Serializable
,
ArrayAccess
{
/**
* An array containing the entries of this collection.
* This is the wrapped php array.
...
...
@@ -205,7 +205,7 @@ class Doctrine_Common_Collection implements Countable, IteratorAggregate, Serial
/**
*
*/
public
function
search
(
Doctrine_ORM_Entity
$record
)
public
function
search
(
$record
)
{
return
array_search
(
$record
,
$this
->
_data
,
true
);
}
...
...
@@ -287,11 +287,6 @@ class Doctrine_Common_Collection implements Countable, IteratorAggregate, Serial
*/
public
function
add
(
$value
,
$key
=
null
)
{
//TODO: really only allow entities?
if
(
!
$value
instanceof
Doctrine_ORM_Entity
)
{
throw
new
Doctrine_Record_Exception
(
'Value variable in collection is not an instance of Doctrine_Entity.'
);
}
// TODO: Really prohibit duplicates?
if
(
in_array
(
$value
,
$this
->
_data
,
true
))
{
return
false
;
...
...
@@ -306,16 +301,6 @@ class Doctrine_Common_Collection implements Countable, IteratorAggregate, Serial
$this
->
_data
[]
=
$value
;
}
if
(
$this
->
_hydrationFlag
)
{
if
(
$this
->
_backRefFieldName
)
{
// set back reference to owner
$value
->
_internalSetReference
(
$this
->
_backRefFieldName
,
$this
->
_owner
);
}
}
else
{
//TODO: Register collection as dirty with the UoW if necessary
$this
->
_changed
();
}
return
true
;
}
...
...
@@ -351,12 +336,36 @@ class Doctrine_Common_Collection implements Countable, IteratorAggregate, Serial
return
new
ArrayIterator
(
$data
);
}
/**
* @todo Experiment. Waiting for 5.3 closures.
* Example usage:
*
* $map = $coll->mapElements(function($key, $entity) {
* return array($entity->id, $entity->name);
* });
*
* or:
*
* $map = $coll->mapElements(function($key, $entity) {
* return array($entity->name, strtoupper($entity->name));
* });
*
*/
public
function
mapElements
(
$lambda
)
{
$result
=
array
();
foreach
(
$this
->
_data
as
$key
=>
$entity
)
{
list
(
$key
,
$value
)
=
each
(
$lambda
(
$key
,
$entity
));
$result
[
$key
]
=
$value
;
}
return
$result
;
}
/**
* returns a string representation of this object
*/
public
function
__toString
()
{
return
Doctrine_Lib
::
getCollectionAsString
(
$this
);
return
__CLASS__
.
'@'
.
spl_object_hash
(
$this
);
}
/**
...
...
@@ -368,5 +377,39 @@ class Doctrine_Common_Collection implements Countable, IteratorAggregate, Serial
{
$this
->
_data
=
array
();
}
/* Serializable implementation */
/**
* Serializes the collection.
* This method is automatically called when the Collection is serialized.
*
* Part of the implementation of the Serializable interface.
*
* @return array
*/
public
function
serialize
()
{
$vars
=
get_object_vars
(
$this
);
//TODO
return
serialize
(
$vars
);
}
/**
* Reconstitutes the collection object from it's serialized form.
* This method is automatically called everytime the Collection object is unserialized.
*
* Part of the implementation of the Serializable interface.
*
* @param string $serialized The serialized data
*
* @return void
*/
public
function
unserialize
(
$serialized
)
{
//TODO
}
}
?>
lib/Doctrine/ORM/Collection.php
View file @
efaaf83e
This diff is collapsed.
Click to expand it.
lib/Doctrine/ORM/EntityManager.php
View file @
efaaf83e
...
...
@@ -131,16 +131,28 @@ class Doctrine_ORM_EntityManager
* @var EventManager
*/
private
$_eventManager
;
/**
* The maintained (cached) Id generators.
*
* @var <type>
*/
private
$_idGenerators
=
array
();
/** Whether the EntityManager is closed or not. */
private
$_closed
=
false
;
/**
* Creates a new EntityManager that operates on the given database connection.
* Creates a new EntityManager that operates on the given database connection
* and uses the given Configuration and EventManager implementations.
*
* @param Doctrine
_
Connection $conn
* @param Doctrine
\DBAL\
Connection $conn
* @param string $name
*/
protected
function
__construct
(
Doctrine_DBAL_Connection
$conn
,
$name
,
Doctrine_ORM_Configuration
$config
,
protected
function
__construct
(
Doctrine_DBAL_Connection
$conn
,
$name
,
Doctrine_ORM_Configuration
$config
,
Doctrine_Common_EventManager
$eventManager
)
{
$this
->
_conn
=
$conn
;
...
...
@@ -183,7 +195,7 @@ class Doctrine_ORM_EntityManager
}
/**
* Starts a
database transa
ction.
* Starts a
transaction on the underlying conne
ction.
*/
public
function
beginTransaction
()
{
...
...
@@ -191,11 +203,11 @@ class Doctrine_ORM_EntityManager
}
/**
* Commits a running
database
transaction.
* Commits a running transaction.
* This causes a flush() of the EntityManager if the flush mode is set to
* AUTO or COMMIT.
*
* @return
unknow
n
* @return
boolea
n
*/
public
function
commit
()
{
...
...
@@ -275,7 +287,7 @@ class Doctrine_ORM_EntityManager
{
if
(
!
isset
(
$this
->
_persisters
[
$entityName
]))
{
$class
=
$this
->
getClassMetadata
(
$entityName
);
if
(
$class
->
getInheritanceType
()
==
Doctrine_ORM_Mapping_ClassMetadata
::
INHERITANCE_TYPE_JOINED
)
{
if
(
$class
->
isInheritanceTypeJoined
()
)
{
$persister
=
new
Doctrine_EntityPersister_JoinedSubclass
(
$this
,
$class
);
}
else
{
$persister
=
new
Doctrine_ORM_Persisters_StandardEntityPersister
(
$this
,
$class
);
...
...
@@ -288,8 +300,8 @@ class Doctrine_ORM_EntityManager
/**
* Detaches an entity from the manager. It's lifecycle is no longer managed.
*
* @param Doctrine
_
Entity $entity
* @return
unknow
n
* @param Doctrine
\ORM\
Entity $entity
* @return
boolea
n
*/
public
function
detach
(
Doctrine_ORM_Entity
$entity
)
{
...
...
@@ -342,11 +354,11 @@ class Doctrine_ORM_EntityManager
/**
* Finds an Entity by its identifier.
* This is just a convenient shortcut for getRepository(
)->find(
).
* This is just a convenient shortcut for getRepository(
$entityName)->find($id
).
*
* @param string $entityName
* @param mixed $identifier
* @return Doctrine
::ORM::
Entity
* @return Doctrine
\ORM\
Entity
*/
public
function
find
(
$entityName
,
$identifier
)
{
...
...
@@ -391,23 +403,19 @@ class Doctrine_ORM_EntityManager
}
/**
* Clears the persistence context, detaching all entities.
*
* @return void
* @todo package:orm
* Clears the persistence context, effectively detaching all managed entities.
*/
public
function
clear
(
$entityName
=
null
)
{
if
(
$entityName
===
null
)
{
$this
->
_unitOfWork
->
detachAll
();
}
else
{
//
...
//
TODO
}
}
/**
* Closes the EntityManager.
*
*/
public
function
close
()
{
...
...
@@ -418,7 +426,6 @@ class Doctrine_ORM_EntityManager
* Saves the given entity, persisting it's state.
*
* @param Doctrine\ORM\Entity $entity
* @return void
*/
public
function
save
(
Doctrine_ORM_Entity
$entity
)
{
...
...
@@ -430,10 +437,9 @@ class Doctrine_ORM_EntityManager
}
/**
*
Removes the given entity from the persistent store
.
*
Deletes the persistent state of the given entity
.
*
* @param Doctrine\ORM\Entity $entity
* @return void
*/
public
function
delete
(
Doctrine_ORM_Entity
$entity
)
{
...
...
@@ -448,8 +454,7 @@ class Doctrine_ORM_EntityManager
* Refreshes the persistent state of the entity from the database,
* overriding any local changes that have not yet been persisted.
*
* @param Doctrine::ORM::Entity $entity
* @return void
* @param Doctrine\ORM\Entity $entity
* @todo FIX Impl
*/
public
function
refresh
(
Doctrine_ORM_Entity
$entity
)
...
...
@@ -462,8 +467,8 @@ class Doctrine_ORM_EntityManager
/**
* Creates a copy of the given entity. Can create a shallow or a deep copy.
*
* @param Doctrine
::ORM::
Entity $entity The entity to copy.
* @return Doctrine
::ORM::
Entity The new entity.
* @param Doctrine
\ORM\
Entity $entity The entity to copy.
* @return Doctrine
\ORM\
Entity The new entity.
*/
public
function
copy
(
Doctrine_ORM_Entity
$entity
,
$deep
=
false
)
{
...
...
@@ -474,7 +479,7 @@ class Doctrine_ORM_EntityManager
* Gets the repository for an Entity.
*
* @param string $entityName The name of the Entity.
* @return Doctrine
::ORM::
EntityRepository The repository.
* @return Doctrine
\ORM\
EntityRepository The repository.
*/
public
function
getRepository
(
$entityName
)
{
...
...
@@ -497,7 +502,7 @@ class Doctrine_ORM_EntityManager
/**
* Checks if the instance is managed by the EntityManager.
*
* @param Doctrine
::ORM::
Entity $entity
* @param Doctrine
\ORM\
Entity $entity
* @return boolean TRUE if this EntityManager currently manages the given entity
* (and has it in the identity map), FALSE otherwise.
*/
...
...
@@ -552,6 +557,8 @@ class Doctrine_ORM_EntityManager
/**
* Checks whether this EntityManager is the currently active one.
*
* Note:This is only useful in scenarios where {@link ActiveEntity}s are used.
*
* @return boolean
*/
public
function
isActive
()
...
...
@@ -562,7 +569,7 @@ class Doctrine_ORM_EntityManager
/**
* Makes this EntityManager the currently active one.
*
*
@return void
*
Note: This is only useful in scenarios where {@link ActiveEntity}s are used.
*/
public
function
activate
()
{
...
...
@@ -582,7 +589,10 @@ class Doctrine_ORM_EntityManager
* @param EventManager $eventManager The EventManager instance to use.
* @return EntityManager The created EntityManager.
*/
public
static
function
create
(
$conn
,
$name
,
Doctrine_ORM_Configuration
$config
=
null
,
public
static
function
create
(
$conn
,
$name
,
Doctrine_ORM_Configuration
$config
=
null
,
Doctrine_Common_EventManager
$eventManager
=
null
)
{
if
(
is_array
(
$conn
))
{
...
...
@@ -607,6 +617,8 @@ class Doctrine_ORM_EntityManager
/**
* Static lookup to get the currently active EntityManager.
*
* Note: Used by {@link ActiveEntity}s to actively lookup an EntityManager.
*
* @return Doctrine\ORM\EntityManager
*/
public
static
function
getActiveEntityManager
()
...
...
lib/Doctrine/ORM/Internal/Hydration/ObjectDriver.php
View file @
efaaf83e
...
...
@@ -55,7 +55,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver
public
function
getElementCollection
(
$component
)
{
$coll
=
new
Doctrine_ORM_Collection
(
$component
);
$coll
=
new
Doctrine_ORM_Collection
(
$
this
->
_em
,
$
component
);
$this
->
_collections
[]
=
$coll
;
return
$coll
;
}
...
...
lib/Doctrine/ORM/NativeQuery.php
View file @
efaaf83e
<?php
#namespace Doctrine
::
ORM;
#namespace Doctrine
\
ORM;
/**
* @todo Migrate the old RawSql to NativeQuery.
...
...
lib/Doctrine/ORM/Query.php
View file @
efaaf83e
...
...
@@ -20,7 +20,7 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine
::
ORM;
#namespace Doctrine
\
ORM;
/**
* A Doctrine_ORM_Query object represents a DQL query. It is used to query databases for
...
...
@@ -28,7 +28,7 @@
* and is dbms independant.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.
phpdoctrine
.org
* @link www.
doctrine-project
.org
* @since 1.0
* @version $Revision: 3938 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
...
...
@@ -60,17 +60,17 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract
const
HYDRATE_NONE
=
5
;
/**
* @var Doctrine
_ORM_
EntityManager The entity manager used by this query object.
* @var Doctrine
\ORM\
EntityManager The entity manager used by this query object.
*/
protected
$_entityManager
;
/**
* @var Doctrine
_ORM_Internal_Hydration
The hydrator object used to hydrate query results.
* @var Doctrine
\ORM\Internal\Hydrator
The hydrator object used to hydrate query results.
*/
protected
$_hydrator
;
/**
* @var Doctrine
_ORM_Query_
ParserResult The parser result that holds DQL => SQL information.
* @var Doctrine
\ORM\Query\
ParserResult The parser result that holds DQL => SQL information.
*/
protected
$_parserResult
;
...
...
@@ -120,20 +120,19 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract
/**
* Initializes a new instance of the Query class.
*
* @param EntityManager $entityManager
* @param
Doctrine\ORM\
EntityManager $entityManager
*/
public
function
__construct
(
Doctrine_ORM_EntityManager
$entityManager
)
{
$this
->
_entityManager
=
$entityManager
;
$this
->
_hydrator
=
new
Doctrine_ORM_Internal_Hydration_StandardHydrator
(
$entityManager
);
$this
->
free
();
}
/**
* Retrieves the assocated EntityManager to this Doctrine_ORM_Query
*
* @return Doctrine
_
EntityManager
* @return Doctrine
\ORM\
EntityManager
*/
public
function
getEntityManager
()
{
...
...
@@ -143,7 +142,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract
/**
* Returns the hydrator associated with this query object
*
* @return Doctrine
_ORM_Internal_Hydration
The hydrator associated with this query object
* @return Doctrine
\ORM\Internal\StandardHydrator
The hydrator associated with this query object
*/
public
function
getHydrator
()
{
...
...
@@ -166,7 +165,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract
*
* @param string $params Parameters
* @param int $hydrationMode Hydration mode
* @return mixed Array or Doctrine
_
Collection or false if no result.
* @return mixed Array or Doctrine
\Common\
Collection or false if no result.
*/
public
function
fetchOne
(
$params
=
array
(),
$hydrationMode
=
null
)
{
...
...
@@ -191,7 +190,6 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract
* @param string $query DQL query
* @param array $params prepared statement parameters
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
* @see Doctrine::FETCH_* constants
* @return mixed
*/
public
function
query
(
$query
,
$params
=
array
(),
$hydrationMode
=
null
)
...
...
lib/Doctrine/ORM/Query/CacheHandler.php
View file @
efaaf83e
<?php
/*
* $Id: Cache.php 3938 2008-03-06 19:36:50Z romanb $
*
...
...
@@ -20,12 +19,14 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine\ORM\Query;
/**
* Doctrine_ORM_Query_CacheHandler
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.
phpdoctrine
.com
* @since
1
.0
* @link www.
doctrine-project
.com
* @since
2
.0
* @version $Revision: 1393 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
...
...
lib/Doctrine/ORM/UnitOfWork.php
View file @
efaaf83e
...
...
@@ -650,19 +650,28 @@ class Doctrine_ORM_UnitOfWork
public
function
getEntityState
(
$entity
)
{
$oid
=
spl_object_hash
(
$entity
);
return
isset
(
$this
->
_entityStates
[
$oid
])
?
$this
->
_entityStates
[
$oid
]
:
self
::
STATE_NEW
;
if
(
!
isset
(
$this
->
_entityStates
[
$oid
]))
{
if
(
isset
(
$this
->
_entityIdentifiers
[
$oid
]))
{
$this
->
_entityStates
[
$oid
]
=
self
::
STATE_DETACHED
;
}
else
{
$this
->
_entityStates
[
$oid
]
=
self
::
STATE_NEW
;
}
}
return
$this
->
_entityStates
[
$oid
];
}
/**
* Removes an entity from the identity map.
* Removes an entity from the identity map. This effectively detaches the
* entity from the persistence management of Doctrine.
*
* @param Doctrine\ORM\Entity $entity
* @return boolean
*/
public
function
removeFromIdentityMap
(
$entity
)
{
$oid
=
spl_object_hash
(
$entity
);
$classMetadata
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
$idHash
=
$this
->
getIdentifierHash
(
$this
->
_entityIdentifiers
[
spl_object_hash
(
$entity
)
]);
$idHash
=
$this
->
getIdentifierHash
(
$this
->
_entityIdentifiers
[
$oid
]);
if
(
$idHash
===
''
)
{
throw
new
Doctrine_Exception
(
"Entity with oid '"
.
spl_object_hash
(
$entity
)
.
"' has no identity and therefore can't be removed from the identity map."
);
...
...
@@ -670,6 +679,7 @@ class Doctrine_ORM_UnitOfWork
$className
=
$classMetadata
->
getRootClassName
();
if
(
isset
(
$this
->
_identityMap
[
$className
][
$idHash
]))
{
unset
(
$this
->
_identityMap
[
$className
][
$idHash
]);
$this
->
_entityStates
[
$oid
]
=
self
::
STATE_DETACHED
;
return
true
;
}
...
...
@@ -677,7 +687,7 @@ class Doctrine_ORM_UnitOfWork
}
/**
*
Find
s an entity in the identity map by its identifier hash.
*
Get
s an entity in the identity map by its identifier hash.
*
* @param string $idHash
* @param string $rootClassName
...
...
@@ -692,8 +702,8 @@ class Doctrine_ORM_UnitOfWork
* Tries to get an entity by its identifier hash. If no entity is found for
* the given hash, FALSE is returned.
*
* @param
<type>
$idHash
* @param
<type>
$rootClassName
* @param
string
$idHash
* @param
string
$rootClassName
* @return mixed The found entity or FALSE.
*/
public
function
tryGetByIdHash
(
$idHash
,
$rootClassName
)
...
...
@@ -760,7 +770,7 @@ class Doctrine_ORM_UnitOfWork
/**
* Saves an entity as part of the current unit of work.
*
* @param Doctrine
_ORM_Entity $entity
The entity to save.
* @param Doctrine
\ORM\Entity $entity
The entity to save.
*/
public
function
save
(
$entity
)
{
...
...
@@ -775,7 +785,7 @@ class Doctrine_ORM_UnitOfWork
foreach
(
$commitOrder
as
$class
)
{
$this
->
_executeInserts
(
$class
);
}
// remove them from _newEntities
// remove them from _newEntities
and _dataChangeSets
$this
->
_newEntities
=
array_diff_key
(
$this
->
_newEntities
,
$insertNow
);
$this
->
_dataChangeSets
=
array_diff_key
(
$this
->
_dataChangeSets
,
$insertNow
);
}
...
...
@@ -786,7 +796,7 @@ class Doctrine_ORM_UnitOfWork
* This method is internally called during save() cascades as it tracks
* the already visited entities to prevent infinite recursions.
*
* @param Doctrine
_ORM_Entity $entity
The entity to save.
* @param Doctrine
\ORM\Entity $entity
The entity to save.
* @param array $visited The already visited entities.
*/
private
function
_doSave
(
$entity
,
array
&
$visited
,
array
&
$insertNow
)
...
...
@@ -909,33 +919,61 @@ class Doctrine_ORM_UnitOfWork
}
}
/**
* Cascades the delete operation to associated entities.
*
* @param Doctrine\ORM\Entity $entity
*/
private
function
_cascadeDelete
(
$entity
)
{
$class
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
foreach
(
$class
->
getAssociationMappings
()
as
$assocMapping
)
{
if
(
!
$assocMapping
->
isCascadeDelete
())
{
continue
;
}
$relatedEntities
=
$class
->
getReflectionProperty
(
$assocMapping
->
getSourceFieldName
())
->
getValue
(
$entity
);
if
(
$relatedEntities
instanceof
Doctrine_ORM_Collection
&&
count
(
$relatedEntities
)
>
0
)
{
foreach
(
$relatedEntities
as
$relatedEntity
)
{
$this
->
_doDelete
(
$relatedEntity
,
$visited
,
$insertNow
);
}
}
else
if
(
is_object
(
$relatedEntities
))
{
$this
->
_doDelete
(
$relatedEntities
,
$visited
,
$insertNow
);
}
}
}
/**
* Gets the CommitOrderCalculator used by the UnitOfWork to order commits.
*
* @return Doctrine\ORM\Internal\CommitOrderCalculator
*/
public
function
getCommitOrderCalculator
()
{
return
$this
->
_commitOrderCalculator
;
}
/**
* Closes the UnitOfWork.
*/
public
function
close
()
{
//...
$this
->
_commitOrderCalculator
->
clear
();
}
public
function
scheduleCollectionUpdate
(
Doctrine_Collection
$coll
)
public
function
scheduleCollectionUpdate
(
Doctrine_
ORM_
Collection
$coll
)
{
$this
->
_collectionUpdates
[]
=
$coll
;
}
public
function
isCollectionScheduledForUpdate
(
Doctrine_Collection
$coll
)
public
function
isCollectionScheduledForUpdate
(
Doctrine_
ORM_
Collection
$coll
)
{
//...
}
public
function
scheduleCollectionDeletion
(
Doctrine_Collection
$coll
)
public
function
scheduleCollectionDeletion
(
Doctrine_
ORM_
Collection
$coll
)
{
//TODO: if $coll is already scheduled for recreation ... what to do?
// Just remove $coll from the scheduled recreations?
...
...
@@ -1097,7 +1135,9 @@ class Doctrine_ORM_UnitOfWork
* INTERNAL:
* For hydration purposes only.
*
* Adds a managed collection to the UnitOfWork.
* Adds a managed collection to the UnitOfWork. On commit time, the UnitOfWork
* checks all these managed collections for modifications and then initiates
* the appropriate database synchronization.
*
* @param Doctrine\ORM\Collection $coll
*/
...
...
tests/AllTests.php
View file @
efaaf83e
<?php
if
(
!
defined
(
'PHPUnit_MAIN_METHOD'
))
{
define
(
'PHPUnit_MAIN_METHOD'
,
'AllTests::main'
);
}
...
...
tests/Orm/AllTests.php
View file @
efaaf83e
...
...
@@ -6,7 +6,6 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
require_once
'lib/DoctrineTestInit.php'
;
// Suites
require_once
'Orm/Component/AllTests.php'
;
require_once
'Orm/Query/AllTests.php'
;
require_once
'Orm/Hydration/AllTests.php'
;
require_once
'Orm/Ticket/AllTests.php'
;
...
...
@@ -17,6 +16,7 @@ require_once 'Orm/Associations/AllTests.php';
require_once
'Orm/UnitOfWorkTest.php'
;
require_once
'Orm/EntityManagerTest.php'
;
require_once
'Orm/EntityPersisterTest.php'
;
require_once
'Orm/CommitOrderCalculatorTest.php'
;
class
Orm_AllTests
{
...
...
@@ -32,8 +32,8 @@ class Orm_AllTests
$suite
->
addTestSuite
(
'Orm_UnitOfWorkTest'
);
$suite
->
addTestSuite
(
'Orm_EntityManagerTest'
);
$suite
->
addTestSuite
(
'Orm_EntityPersisterTest'
);
$suite
->
addTestSuite
(
'Orm_CommitOrderCalculatorTest'
);
$suite
->
addTest
(
Orm_Component_AllTests
::
suite
());
$suite
->
addTest
(
Orm_Query_AllTests
::
suite
());
$suite
->
addTest
(
Orm_Hydration_AllTests
::
suite
());
$suite
->
addTest
(
Orm_Entity_AllTests
::
suite
());
...
...
tests/Orm/
Internal/
CommitOrderCalculatorTest.php
→
tests/Orm/CommitOrderCalculatorTest.php
View file @
efaaf83e
...
...
@@ -8,20 +8,21 @@ require_once 'lib/DoctrineTestInit.php';
* can have many valid orderings, so you may want to build a graph that has only
* 1 valid order to simplify your tests.
*/
class
Orm_
Internal_
CommitOrderCalculatorTest
extends
Doctrine_OrmTestCase
class
Orm_CommitOrderCalculatorTest
extends
Doctrine_OrmTestCase
{
private
$_calc
;
protected
function
setUp
()
{
$this
->
_calc
=
new
Doctrine_Internal_CommitOrderCalculator
();
$this
->
_calc
=
new
Doctrine_
ORM_
Internal_CommitOrderCalculator
();
}
/** Helper to create an array of nodes */
private
function
_createNodes
(
array
$names
)
{
$nodes
=
array
();
foreach
(
$names
as
$name
)
{
$node
=
new
Doctrine_Internal_CommitOrderNode
(
$name
,
$this
->
_calc
);
$node
=
new
Doctrine_
ORM_
Internal_CommitOrderNode
(
$name
,
$this
->
_calc
);
$nodes
[
$name
]
=
$node
;
$this
->
_calc
->
addNode
(
$node
->
getClass
(),
$node
);
}
...
...
@@ -46,6 +47,4 @@ class Orm_Internal_CommitOrderCalculatorTest extends Doctrine_OrmTestCase
$this
->
assertSame
(
$correctOrder
,
$sorted
);
}
}
tests/Orm/Component/AccessTest.php
deleted
100644 → 0
View file @
b9ecb8de
<?php
/*
* $Id: Doctrine.php 3754 2008-02-13 10:53:07Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
/**
* Testcase for basic accessor/mutator functionality.
*
* @package Doctrine
* @author Bjarte Stien Karlsen <doctrine@bjartek.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 2.0
* @version $Revision: 3754 $
*/
require_once
'lib/DoctrineTestInit.php'
;
class
AccessStub
extends
Doctrine_Access
{}
class
Orm_Component_AccessTest
extends
Doctrine_OrmTestCase
{
private
$user
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
user
=
new
ForumUser
();
}
/*public function testAccessorOverridePerformance() {
$this->user->username;
$start = microtime(true);
for ($i = 0; $i < 1; $i++) {
$this->user->username;
}
$end = microtime(true);
echo ($end - $start) . " seconds" . PHP_EOL;
}*/
/**
* @test
*/
public
function
shouldMarkEmptyFieldAsNotSetOnNewRecord
()
{
$this
->
assertFalse
(
isset
(
$this
->
user
->
username
));
$this
->
assertFalse
(
isset
(
$this
->
user
[
'username'
]));
}
/**
* @test
*/
public
function
shouldMarkNonExistantFieldAsNotSetOnNewRecord
()
{
$this
->
assertFalse
(
isset
(
$this
->
user
->
rat
));
$this
->
assertFalse
(
isset
(
$this
->
user
[
'rat'
]));
}
/**
* @test
*/
public
function
shouldSetSingleValueInRecord
()
{
$this
->
user
->
username
=
'meus'
;
$this
->
assertEquals
(
'meus'
,
$this
->
user
->
username
);
$this
->
assertEquals
(
'meus'
,
$this
->
user
[
'username'
]);
}
/**
* @test
*/
public
function
shouldSetSingleValueInRecordWithOffset
()
{
$this
->
user
[
'username'
]
=
'meus'
;
$this
->
assertEquals
(
'meus'
,
$this
->
user
->
username
);
$this
->
assertEquals
(
'meus'
,
$this
->
user
[
'username'
]);
}
/**
* @test
* @expectedException Doctrine_ORM_Exceptions_EntityException
*/
public
function
shouldNotBeAbleToSetNonExistantField
()
{
$this
->
user
->
rat
=
'meus'
;
}
/**
* @test
* @expectedException Doctrine_ORM_Exceptions_EntityException
*/
public
function
shouldNotBeAbleToSetNonExistantFieldWithOffset
()
{
$this
->
user
[
'rat'
]
=
'meus'
;
}
/**
* @test
*/
public
function
newCollectionShouldBeEmpty
()
{
$col
=
new
Doctrine_Collection
(
'ForumUser'
);
$this
->
assertEquals
(
0
,
count
(
$col
));
$this
->
assertFalse
(
isset
(
$coll
[
0
]));
}
/**
* @test
*/
public
function
shouldBeAbleToUnsetWithOffsetFromCollection
()
{
$col
=
new
Doctrine_Collection
(
'ForumUser'
);
$col
[
0
]
=
new
ForumUser
();
$this
->
assertTrue
(
isset
(
$col
[
0
]));
unset
(
$col
[
0
]);
$this
->
assertFalse
(
isset
(
$col
[
0
]));
}
/**
* @test
*/
public
function
shouldBeAbleToUnsetFromCollection
()
{
$col
=
new
Doctrine_Collection
(
'ForumUser'
);
$col
->
test
=
new
ForumUser
();
$this
->
assertTrue
(
isset
(
$col
->
test
));
unset
(
$col
->
test
);
$this
->
assertFalse
(
isset
(
$col
->
test
));
}
/**
* @test
* @expectedException Doctrine_Exception
*/
public
function
shouldNotBeAbleToUseContainsWhenNotImplemented
()
{
$stub
=
new
AccessStub
();
isset
(
$stub
[
'foo'
]);
}
/**
* @test
* @expectedException Doctrine_Exception
*/
public
function
shouldNotBeAbleToUseSetWhenNotImplemented
()
{
$stub
=
new
AccessStub
();
$stub
[
'foo'
]
=
'foo'
;
}
/**
* @test
* @expectedException Doctrine_Exception
*/
public
function
shouldNotBeAbleToUseUnsetWhenNotImplemented
()
{
$stub
=
new
AccessStub
();
unset
(
$stub
[
'foo'
]);
}
/**
* @test
* @expectedException Doctrine_Exception
*/
public
function
shouldNotBeAbleToUseGetWhenNotImplemented
()
{
$stub
=
new
AccessStub
();
$stub
[
'foo'
];
}
}
tests/Orm/Component/AllTests.php
deleted
100644 → 0
View file @
b9ecb8de
<?php
if
(
!
defined
(
'PHPUnit_MAIN_METHOD'
))
{
define
(
'PHPUnit_MAIN_METHOD'
,
'Orm_Component_AllTests::main'
);
}
require_once
'lib/DoctrineTestInit.php'
;
// Tests
//require_once 'Orm/Component/AccessTest.php';
require_once
'Orm/Component/CollectionTest.php'
;
class
Orm_Component_AllTests
{
public
static
function
main
()
{
PHPUnit_TextUI_TestRunner
::
run
(
self
::
suite
());
}
public
static
function
suite
()
{
$suite
=
new
Doctrine_TestSuite
(
'Doctrine Orm Component'
);
//$suite->addTestSuite('Orm_Component_AccessTest');
$suite
->
addTestSuite
(
'Orm_Component_CollectionTest'
);
return
$suite
;
}
}
if
(
PHPUnit_MAIN_METHOD
==
'Orm_Component_AllTests::main'
)
{
Orm_Component_AllTests
::
main
();
}
tests/Orm/Component/CollectionTest.php
deleted
100644 → 0
View file @
b9ecb8de
<?php
/* vim: set et sw=4 ts=4: */
/*
* $Id: Doctrine.php 3754 2008-02-13 10:53:07Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine
* the base class of Doctrine framework
*
* @package Doctrine
* @author Bjarte Stien Karlsen <doctrine@bjartek.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 2.0
* @version $Revision: 3754 $
*/
require_once
'lib/DoctrineTestInit.php'
;
class
Orm_Component_CollectionTest
extends
Doctrine_OrmTestCase
{
private
$coll
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
coll
=
new
Doctrine_ORM_Collection
(
'ForumUser'
);
//we create a CmsUser with username as key column and add a user to it
$cmsColl
=
new
Doctrine_ORM_Collection
(
'CmsUser'
,
'username'
);
$user
=
new
CmsUser
();
$user
->
username
=
'test'
;
$cmsColl
[]
=
$user
;
$this
->
cmsColl
=
$cmsColl
;
$this
->
cmsUser
=
$user
;
}
/**
* @test
*/
public
function
shouldHaveBlankAsDefaultKeyColumn
()
{
$this
->
assertEquals
(
''
,
$this
->
coll
->
getKeyField
());
}
/**
* @test
*/
public
function
shouldUseSpecifiedKeyColumn
()
{
$coll
=
new
Doctrine_ORM_Collection
(
'ForumUser'
,
'id'
);
$this
->
assertEquals
(
'id'
,
$coll
->
getKeyField
());
}
/**
* This test is currently failing. I do not understand why it should be
* possible to set this to something that is not valid.
*
* @test
* @expectedException Doctrine_Exception
*/
public
function
shouldThrowExceptionIfNonValidFieldSetAsKey
()
{
$coll
=
new
Doctrine_ORM_Collection
(
'ForumUser'
,
'xxNonValidFieldxx'
);
}
/**
* @test
*/
public
function
shouldSerializeEmptyCollection
()
{
$serialized
=
serialize
(
$this
->
coll
);
$this
->
assertTrue
(
is_string
(
$serialized
));
}
/**
* @test
*/
public
function
shouldUnserializeEmptyCollectionIntoObject
()
{
$serialized
=
serialize
(
$this
->
coll
);
$coll
=
unserialize
(
$serialized
);
$this
->
assertEquals
(
'Doctrine_ORM_Collection'
,
get_class
(
$coll
));
}
/**
* @test
*/
/*public function shouldSetKeyColumnWhenAddingNewRowAsArray()
{
$this->assertTrue(isset($this->cmsColl['test']));
$this->assertEquals($this->cmsUser, $this->cmsColl['test']);
}*/
/**
* @test
*/
/*public function shouldSerializeAndUnserializeCollectionWithData()
{
$serialized = serialize($this->cmsColl);
$coll = unserialize($serialized);
$this->assertEquals('username', $coll->getKeyField());
$this->assertTrue(isset($coll['test']));
$user = $coll['test'];
$this->assertTrue($user instanceOf CmsUser);
$this->assertEquals('test', $user['username']);
}*/
}
tests/Orm/Entity/AccessorTest.php
View file @
efaaf83e
<?php
/* CURRENTLY NOT USED */
require_once
'lib/DoctrineTestInit.php'
;
class
Orm_Entity_AccessorTest
extends
Doctrine_OrmTestCase
...
...
tests/Orm/Entity/ConstructorTest.php
View file @
efaaf83e
...
...
@@ -12,7 +12,7 @@ class Orm_Entity_ConstructorTest extends Doctrine_OrmTestCase
class
ConstructorTestEntity1
{
p
ublic
$id
;
p
rivate
$id
;
public
$username
;
public
function
__construct
(
$username
=
null
)
...
...
@@ -45,4 +45,3 @@ class ConstructorTestEntity1
}
}
?>
\ No newline at end of file
tests/Orm/EntityManagerFactoryTest.php
deleted
100644 → 0
View file @
b9ecb8de
<?php
require_once
'lib/DoctrineTestInit.php'
;
#namespace Doctrine::Tests::ORM;
/**
* EntityManagerFactory tests.
*/
class
Orm_EntityManagerFactoryTest
extends
Doctrine_OrmTestCase
{
private
$_mockOptions
=
array
(
'driver'
=>
'mock'
,
'user'
=>
''
,
'password'
=>
''
);
protected
function
tearDown
()
{
parent
::
tearDown
();
}
private
function
_createNamedManager
(
$name
)
{
return
$this
->
_emf
->
createEntityManager
(
$this
->
_mockOptions
,
$name
);
}
/*public function testBindingEntityToNamedManager()
{
$myEM = $this->_createNamedManager('myEM');
$this->_emf->bindEntityToManager('SomeEntity', 'myEM');
$this->assertSame($myEM, $this->_emf->getEntityManager('SomeEntity'));
$this->_emf->releaseEntityManager($myEM);
}
public function testStaticLookup()
{
$this->assertTrue(Doctrine_EntityManagerFactory::getManager() instanceof Doctrine_EntityManager);
}*/
}
\ No newline at end of file
tests/Orm/EntityManagerTest.php
View file @
efaaf83e
<?php
require_once
'lib/DoctrineTestInit.php'
;
#namespace Doctrine
::Tests::
ORM;
#namespace Doctrine
\Tests\
ORM;
/**
* EntityManager tests.
*/
class
Orm_EntityManagerTest
extends
Doctrine_OrmTestCase
{
private
$_em
;
function
setUp
()
{
parent
::
setUp
();
$this
->
_em
=
$this
->
_getTestEntityManager
();
}
public
function
testSettingInvalidFlushModeThrowsException
()
{
$prev
=
$this
->
_em
->
getFlushMode
();
...
...
tests/Orm/Hydration/BasicHydrationTest.php
View file @
efaaf83e
...
...
@@ -7,9 +7,12 @@ require_once 'lib/mocks/Doctrine_HydratorMockStatement.php';
class
Orm_Hydration_BasicHydrationTest
extends
Doctrine_OrmTestCase
{
private
$_em
;
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
_em
=
$this
->
_getTestEntityManager
();
}
/** Getter for the hydration mode dataProvider */
...
...
tests/Orm/Query/IdentifierRecognitionTest.php
View file @
efaaf83e
...
...
@@ -36,6 +36,12 @@ require_once 'lib/DoctrineTestInit.php';
*/
class
Orm_Query_IdentifierRecognitionTest
extends
Doctrine_OrmTestCase
{
private
$_em
;
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
_em
=
$this
->
_getTestEntityManager
();
}
public
function
testSingleAliasDeclarationIsSupported
()
{
...
...
tests/Orm/UnitOfWorkTest.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\ORM;
require_once
'lib/DoctrineTestInit.php'
;
require_once
'lib/mocks/Doctrine_EntityManagerMock.php'
;
require_once
'lib/mocks/Doctrine_ConnectionMock.php'
;
...
...
@@ -7,25 +10,20 @@ require_once 'lib/mocks/Doctrine_IdentityIdGeneratorMock.php';
/**
* UnitOfWork tests.
* These tests run without a database through mocking the
* persister/connection/sequence used by the UnitOfWork.
*/
class
Orm_UnitOfWorkTest
extends
Doctrine_OrmTestCase
{
// SUT
private
$_unitOfWork
;
// Mocks
// Provides a sequence mock to the UnitOfWork
private
$_connectionMock
;
// The EntityManager mock that provides the mock persister
// The EntityManager mock that provides the mock persister
s
private
$_emMock
;
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
_connectionMock
=
new
Doctrine_ConnectionMock
(
array
());
$this
->
_emMock
=
Doctrine_EntityManagerMock
::
create
(
$this
->
_connectionMock
,
"uowMockEm"
);
// SUT
$this
->
_unitOfWork
=
new
Doctrine_UnitOfWorkMock
(
$this
->
_emMock
);
$this
->
_emMock
->
setUnitOfWork
(
$this
->
_unitOfWork
);
...
...
@@ -136,6 +134,7 @@ class Orm_UnitOfWorkTest extends Doctrine_OrmTestCase
// Fake managed state
$this
->
_unitOfWork
->
setEntityState
(
$user2
,
Doctrine_ORM_UnitOfWork
::
STATE_MANAGED
);
// Fake original entity date
$this
->
_unitOfWork
->
setOriginalEntityData
(
$user1
,
array
(
'id'
=>
1
,
'username'
=>
'roman'
));
...
...
@@ -143,8 +142,10 @@ class Orm_UnitOfWorkTest extends Doctrine_OrmTestCase
'id'
=>
2
,
'username'
=>
'jon'
));
// Go
$this
->
_unitOfWork
->
computeDataChangeSet
(
array
(
$user1
,
$user2
));
// Verify
$user1ChangeSet
=
$this
->
_unitOfWork
->
getDataChangeSet
(
$user1
);
$this
->
assertTrue
(
is_array
(
$user1ChangeSet
));
$this
->
assertEquals
(
2
,
count
(
$user1ChangeSet
));
...
...
tests/lib/DoctrineTestInit.php
View file @
efaaf83e
<?php
/*
* This file bootstraps the test environment.
*/
require_once
'PHPUnit/Framework.php'
;
require_once
'PHPUnit/TextUI/TestRunner.php'
;
//require_once '../lib/Doctrine.php';
require_once
'../lib/Doctrine/Common/ClassLoader.php'
;
$classLoader
=
new
Doctrine_Common_ClassLoader
();
...
...
tests/lib/Doctrine_DbalTestCase.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests;
/**
* Base testcase class for all dbal testcases.
*/
class
Doctrine_DbalTestCase
extends
Doctrine_TestCase
{
protected
$_conn
;
/**
* setUp()
*/
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
[
'conn'
]))
{
$this
->
_conn
=
$this
->
sharedFixture
[
'conn'
];
}
else
{
$this
->
sharedFixture
[
'conn'
]
=
Doctrine_TestUtil
::
getConnection
();
$this
->
_conn
=
$this
->
sharedFixture
[
'conn'
];
}
}
}
\ No newline at end of file
tests/lib/Doctrine_DbalTestSuite.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests;
/**
* The outermost test suite for all dbal related testcases & suites.
*
* Currently the dbal suite uses a normal connection object, too, just like the orm suite.
* Upon separation of the DBAL and ORM package this suite should just use a DBAL
* connection in the shared fixture.
*/
class
Doctrine_DbalTestSuite
extends
Doctrine_TestSuite
{
protected
function
setUp
()
{
$this
->
sharedFixture
[
'conn'
]
=
Doctrine_TestUtil
::
getConnection
();
}
protected
function
tearDown
()
{}
}
\ No newline at end of file
tests/lib/Doctrine_OrmFunctionalTestCase.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests;
/**
* Base testcase class for all orm testcases.
*
...
...
tests/lib/Doctrine_OrmFunctionalTestSuite.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests;
/**
* The outermost test suite for all orm related testcases & suites.
*
...
...
tests/lib/Doctrine_OrmTestCase.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests;
require_once
'lib/mocks/Doctrine_DriverMock.php'
;
require_once
'lib/mocks/Doctrine_ConnectionMock.php'
;
/**
* Base testcase class for all orm testcases.
*
* Base testcase class for all ORM testcases.
*/
class
Doctrine_OrmTestCase
extends
Doctrine_TestCase
{
protected
$_em
;
protected
function
setUp
()
{
if
(
isset
(
$this
->
sharedFixture
[
'em'
]))
{
$this
->
_em
=
$this
->
sharedFixture
[
'em'
];
}
else
{
/**
* Creates an EntityManager for testing purposes.
*
* @return Doctrine\ORM\EntityManager
*/
protected
function
_getTestEntityManager
(
$conf
=
null
,
$eventManager
=
null
)
{
$config
=
new
Doctrine_ORM_Configuration
();
$eventManager
=
new
Doctrine_Common_EventManager
();
$connectionOptions
=
array
(
...
...
@@ -23,9 +24,6 @@ class Doctrine_OrmTestCase extends Doctrine_TestCase
'user'
=>
'john'
,
'password'
=>
'wayne'
);
$em
=
Doctrine_ORM_EntityManager
::
create
(
$connectionOptions
,
'mockEM'
,
$config
,
$eventManager
);
$this
->
_em
=
$em
;
}
$this
->
_em
->
activate
();
return
Doctrine_ORM_EntityManager
::
create
(
$connectionOptions
,
'mockEM'
,
$config
,
$eventManager
);
}
}
tests/lib/Doctrine_OrmTestSuite.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests;
/**
* The outermost test suite for all orm related testcases & suites.
*
* Currently the orm suite uses a normal connection object.
* Upon separation of the DBAL and ORM package this suite should just use a orm
* connection/session/manager instance as the shared fixture.
*/
class
Doctrine_OrmTestSuite
extends
Doctrine_TestSuite
{
protected
function
setUp
()
{
$config
=
new
Doctrine_ORM_Configuration
();
$eventManager
=
new
Doctrine_Common_EventManager
();
$connectionOptions
=
array
(
'driverClass'
=>
'Doctrine_DriverMock'
,
'wrapperClass'
=>
'Doctrine_ConnectionMock'
,
'user'
=>
'john'
,
'password'
=>
'wayne'
);
$em
=
Doctrine_ORM_EntityManager
::
create
(
$connectionOptions
,
'mockEM'
,
$config
,
$eventManager
);
$this
->
sharedFixture
[
'em'
]
=
$em
;
}
protected
function
tearDown
()
{}
}
\ No newline at end of file
tests/lib/Doctrine_TestCase.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests;
/**
* Base testcase class for all Doctrine testcases.
*/
class
Doctrine_TestCase
extends
PHPUnit_Framework_TestCase
{
}
\ No newline at end of file
tests/lib/Doctrine_TestSuite.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests;
/**
* Doctrine's basic test suite implementation. Provides functionality needed by all
* test suites.
*/
class
Doctrine_TestSuite
extends
PHPUnit_Framework_TestSuite
{
}
\ No newline at end of file
tests/lib/Doctrine_TestUtil.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests;
class
Doctrine_TestUtil
{
public
static
function
getConnection
()
...
...
tests/lib/mocks/Doctrine_ClassMetadataMock.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Mocks;
class
Doctrine_ClassMetadataMock
extends
Doctrine_ORM_Mapping_ClassMetadata
{
/* Mock API */
...
...
@@ -10,4 +12,3 @@ class Doctrine_ClassMetadataMock extends Doctrine_ORM_Mapping_ClassMetadata
}
?>
\ No newline at end of file
tests/lib/mocks/Doctrine_ConnectionMock.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Mocks;
#use Doctrine\DBAL\Connection;
require_once
'lib/mocks/Doctrine_SequenceMock.php'
;
require_once
'lib/mocks/Doctrine_DatabasePlatformMock.php'
;
...
...
@@ -73,4 +77,3 @@ class Doctrine_ConnectionMock extends Doctrine_DBAL_Connection
}
}
?>
\ No newline at end of file
tests/lib/mocks/Doctrine_DatabasePlatformMock.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Mocks;
#use Doctrine\DBAL\Platforms\AbstractPlatform;
class
Doctrine_DatabasePlatformMock
extends
Doctrine_DBAL_Platforms_AbstractPlatform
{
private
$_prefersIdentityColumns
=
false
;
...
...
@@ -30,4 +34,3 @@ class Doctrine_DatabasePlatformMock extends Doctrine_DBAL_Platforms_AbstractPlat
}
?>
\ No newline at end of file
tests/lib/mocks/Doctrine_DriverConnectionMock.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Mocks;
class
Doctrine_DriverConnectionMock
implements
Doctrine_DBAL_Driver_Connection
{
public
function
prepare
(
$prepareString
)
{}
...
...
@@ -14,4 +16,3 @@ class Doctrine_DriverConnectionMock implements Doctrine_DBAL_Driver_Connection
public
function
errorInfo
()
{}
}
?>
\ No newline at end of file
tests/lib/mocks/Doctrine_DriverMock.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Mocks;
require_once
'lib/mocks/Doctrine_DriverConnectionMock.php'
;
require_once
'lib/mocks/Doctrine_DatabasePlatformMock.php'
;
...
...
tests/lib/mocks/Doctrine_EntityManagerMock.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Mocks;
require_once
'lib/mocks/Doctrine_EntityPersisterMock.php'
;
/**
...
...
@@ -88,4 +90,3 @@ class Doctrine_EntityManagerMock extends Doctrine_ORM_EntityManager
}
}
?>
\ No newline at end of file
tests/lib/mocks/Doctrine_EntityPersisterMock.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Mocks;
/**
* EntityPersister implementation used for mocking during tests.
*/
...
...
tests/lib/mocks/Doctrine_HydratorMockStatement.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Mocks;
/**
* This class is a mock of the PDOStatement class that can be passed in to the Hydrator
* to test the hydration standalone with faked result sets.
...
...
tests/lib/mocks/Doctrine_IdentityIdGeneratorMock.php
View file @
efaaf83e
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
#namespace Doctrine\Tests\Mocks;
/**
* Description of Doctrine_IdentityIdGeneratorMock
...
...
@@ -17,4 +15,4 @@ class Doctrine_IdentityIdGeneratorMock extends Doctrine_ORM_Id_IdentityGenerator
$this
->
_mockPostInsertId
=
$id
;
}
}
?>
tests/lib/mocks/Doctrine_SequenceMock.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Mocks;
class
Doctrine_SequenceMock
extends
Doctrine_ORM_Id_SequenceGenerator
{
private
$_sequenceNumber
=
0
;
...
...
@@ -52,4 +54,3 @@ class Doctrine_SequenceMock extends Doctrine_ORM_Id_SequenceGenerator
}
}
?>
\ No newline at end of file
tests/lib/mocks/Doctrine_UnitOfWorkMock.php
View file @
efaaf83e
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
#namespace Doctrine\Tests\Mocks;
/**
* Description of Doctrine_UnitOfWorkMock
...
...
tests/models/forum/ForumAdministrator.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Models\Forum;
class
ForumAdministrator
extends
ForumUser
{
public
$accessLevel
;
...
...
tests/models/forum/ForumAvatar.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\
ORM\
Models\Forum;
#namespace Doctrine\Tests\Models\Forum;
#use Doctrine\ORM\Entity;
#use Doctrine\Common\VirtualPropertySystem;
class
ForumAvatar
{
public
$id
;
/*static function construct() {
Doctrine_Common_VirtualPropertySystem::register(__CLASS__, 'id', 'int');
}*/
public
static
function
initMetadata
(
$mapping
)
{
$mapping
->
mapField
(
array
(
...
...
tests/models/forum/ForumBoard.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Models\Forum;
class
ForumBoard
{
public
$id
;
...
...
tests/models/forum/ForumCategory.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\Models\Forum;
class
ForumCategory
{
private
$id
;
...
...
tests/models/forum/ForumEntry.php
View file @
efaaf83e
<?php
#namespace Doctrine
::Test::ORM::Models
;
#namespace Doctrine
\Tests\Models\Forum
;
#use Doctrine
::ORM::
Entity;
#use Doctrine
\ORM\
Entity;
class
ForumEntry
extend
s
Doctrine_ORM_Entity
class
ForumEntry
implement
s
Doctrine_ORM_Entity
{
public
$id
;
public
$topic
;
static
function
construct
()
{
Doctrine_Common_VirtualPropertySystem
::
register
(
__CLASS__
,
'id'
,
'int'
);
Doctrine_Common_VirtualPropertySystem
::
register
(
__CLASS__
,
'topic'
,
'string'
);
}
public
static
function
initMetadata
(
$mapping
)
{
$mapping
->
mapField
(
array
(
...
...
@@ -33,4 +28,3 @@ class ForumEntry extends Doctrine_ORM_Entity
}
?>
\ No newline at end of file
tests/models/forum/ForumUser.php
View file @
efaaf83e
<?php
#namespace Doctrine\Tests\
ORM\
Models\Forum;
#namespace Doctrine\Tests\Models\Forum;
#use Doctrine\ORM\Entity;
#use Doctrine\Common\VirtualPropertySystem;
class
ForumUser
{
...
...
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