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
7778d2b0
Commit
7778d2b0
authored
May 15, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IdentityMap map added, small enhancements and bug fixes
parent
c9877af4
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
335 additions
and
167 deletions
+335
-167
Association.class.php
classes/Association.class.php
+7
-2
Collection.class.php
classes/Collection.class.php
+2
-3
Configurable.class.php
classes/Configurable.class.php
+15
-5
Doctrine.class.php
classes/Doctrine.class.php
+15
-1
Iterator.class.php
classes/Iterator.class.php
+15
-3
Query.class.php
classes/Query.class.php
+39
-12
Record.class.php
classes/Record.class.php
+15
-12
Relation.class.php
classes/Relation.class.php
+2
-5
Session.class.php
classes/Session.class.php
+23
-19
Table.class.php
classes/Table.class.php
+92
-32
AccessTestCase.class.php
tests/AccessTestCase.class.php
+38
-21
CollectionTestCase.class.php
tests/CollectionTestCase.class.php
+3
-1
ConfigurableTestCase.class.php
tests/ConfigurableTestCase.class.php
+6
-2
EventListenerTestCase.class.php
tests/EventListenerTestCase.class.php
+2
-0
ManagerTestCase.class.php
tests/ManagerTestCase.class.php
+2
-0
QueryTestCase.class.php
tests/QueryTestCase.class.php
+0
-1
RecordTestCase.class.php
tests/RecordTestCase.class.php
+36
-27
SessionTestCase.class.php
tests/SessionTestCase.class.php
+2
-2
UnitTestCase.class.php
tests/UnitTestCase.class.php
+10
-12
ValidatorTestCase.class.php
tests/ValidatorTestCase.class.php
+11
-7
No files found.
classes/Association.class.php
View file @
7778d2b0
...
@@ -2,8 +2,13 @@
...
@@ -2,8 +2,13 @@
require_once
(
"Relation.class.php"
);
require_once
(
"Relation.class.php"
);
/**
/**
* Doctrine_Association this class takes care of association mapping
* Doctrine_Association this class takes care of association mapping
*
(= many-to-many relationships, where the relationship is handled throug
h an additional relational table
*
(= many-to-many relationships, where the relationship is handled wit
h an additional relational table
* which holds 2 foreign keys)
* which holds 2 foreign keys)
*
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
*/
class
Doctrine_Association
extends
Doctrine_Relation
{
class
Doctrine_Association
extends
Doctrine_Relation
{
/**
/**
...
...
classes/Collection.class.php
View file @
7778d2b0
<?php
<?php
/**
/**
* class Doctrine_Collection a collection of data access objects
* Doctrine_Collection
* Collection of Doctrine_Record objects.
*
*
* @author Konsta Vesterinen
* @package Doctrine ORM
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @url www.phpdoctrine.com
* @license LGPL
* @license LGPL
* @version 1.0 alpha
*/
*/
class
Doctrine_Collection
extends
Doctrine_Access
implements
Countable
,
IteratorAggregate
{
class
Doctrine_Collection
extends
Doctrine_Access
implements
Countable
,
IteratorAggregate
{
/**
/**
...
...
classes/Configurable.class.php
View file @
7778d2b0
...
@@ -4,12 +4,9 @@
...
@@ -4,12 +4,9 @@
* the base for Doctrine_Table, Doctrine_Manager and Doctrine_Session
* the base for Doctrine_Table, Doctrine_Manager and Doctrine_Session
*
*
*
*
* @author Konsta Vesterinen
* @package Doctrine ORM
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @url www.phpdoctrine.com
* @license LGPL
* @license LGPL
* @version 1.0 beta2
*
*/
*/
abstract
class
Doctrine_Configurable
{
abstract
class
Doctrine_Configurable
{
...
@@ -22,7 +19,9 @@ abstract class Doctrine_Configurable {
...
@@ -22,7 +19,9 @@ abstract class Doctrine_Configurable {
*/
*/
private
$parent
;
private
$parent
;
/**
/**
* @throws Exception if the value is invalid
* sets a given attribute
*
* @throws Doctrine_Exception if the value is invalid
* @param integer $attribute
* @param integer $attribute
* @param mixed $value
* @param mixed $value
* @return void
* @return void
...
@@ -124,7 +123,10 @@ abstract class Doctrine_Configurable {
...
@@ -124,7 +123,10 @@ abstract class Doctrine_Configurable {
$this
->
attributes
[
$i
]
=
$listener
;
$this
->
attributes
[
$i
]
=
$listener
;
}
}
/**
/**
* @return mixed the value of the attribute
* returns the value of an attribute
*
* @param integer $attribute
* @return mixed
*/
*/
final
public
function
getAttribute
(
$attribute
)
{
final
public
function
getAttribute
(
$attribute
)
{
$attribute
=
(
int
)
$attribute
;
$attribute
=
(
int
)
$attribute
;
...
@@ -142,12 +144,17 @@ abstract class Doctrine_Configurable {
...
@@ -142,12 +144,17 @@ abstract class Doctrine_Configurable {
}
}
/**
/**
* getAttributes
* getAttributes
* returns all attributes as an array
*
* @return array
* @return array
*/
*/
final
public
function
getAttributes
()
{
final
public
function
getAttributes
()
{
return
$this
->
attributes
;
return
$this
->
attributes
;
}
}
/**
/**
* sets a parent for this configurable component
* the parent must be configurable component itself
*
* @param Doctrine_Configurable $component
* @param Doctrine_Configurable $component
* @return void
* @return void
*/
*/
...
@@ -156,6 +163,9 @@ abstract class Doctrine_Configurable {
...
@@ -156,6 +163,9 @@ abstract class Doctrine_Configurable {
}
}
/**
/**
* getParent
* getParent
* returns the parent of this component
*
* @return Doctrine_Configurable
*/
*/
final
public
function
getParent
()
{
final
public
function
getParent
()
{
return
$this
->
parent
;
return
$this
->
parent
;
...
...
classes/Doctrine.class.php
View file @
7778d2b0
...
@@ -3,6 +3,10 @@ require_once("Exception.class.php");
...
@@ -3,6 +3,10 @@ require_once("Exception.class.php");
/**
/**
* Doctrine
* Doctrine
* the base class of Doctrine framework
* the base class of Doctrine framework
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
*/
final
class
Doctrine
{
final
class
Doctrine
{
/**
/**
...
@@ -202,7 +206,11 @@ final class Doctrine {
...
@@ -202,7 +206,11 @@ final class Doctrine {
* @var string $path doctrine root directory
* @var string $path doctrine root directory
*/
*/
private
static
$path
;
private
static
$path
;
/**
* returns the doctrine root
*
* @return string
*/
public
static
function
getPath
()
{
public
static
function
getPath
()
{
if
(
!
self
::
$path
)
if
(
!
self
::
$path
)
self
::
$path
=
dirname
(
__FILE__
);
self
::
$path
=
dirname
(
__FILE__
);
...
@@ -211,6 +219,8 @@ final class Doctrine {
...
@@ -211,6 +219,8 @@ final class Doctrine {
}
}
/**
/**
* loads all runtime classes
* loads all runtime classes
*
* @return void
*/
*/
public
static
function
loadAll
()
{
public
static
function
loadAll
()
{
if
(
!
self
::
$path
)
if
(
!
self
::
$path
)
...
@@ -253,6 +263,10 @@ final class Doctrine {
...
@@ -253,6 +263,10 @@ final class Doctrine {
}
}
/**
/**
* simple autoload function
* simple autoload function
* returns true if the class was loaded, otherwise false
*
* @param string $classname
* @return boolean
*/
*/
public
static
function
autoload
(
$classname
)
{
public
static
function
autoload
(
$classname
)
{
if
(
!
self
::
$path
)
if
(
!
self
::
$path
)
...
...
classes/Iterator.class.php
View file @
7778d2b0
...
@@ -2,6 +2,10 @@
...
@@ -2,6 +2,10 @@
/**
/**
* Doctrine_Iterator
* Doctrine_Iterator
* iterates through Doctrine_Collection
* iterates through Doctrine_Collection
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
*/
abstract
class
Doctrine_Iterator
implements
Iterator
{
abstract
class
Doctrine_Iterator
implements
Iterator
{
/**
/**
...
@@ -35,6 +39,8 @@ abstract class Doctrine_Iterator implements Iterator {
...
@@ -35,6 +39,8 @@ abstract class Doctrine_Iterator implements Iterator {
$this
->
count
=
$this
->
collection
->
count
();
$this
->
count
=
$this
->
collection
->
count
();
}
}
/**
/**
* rewinds the iterator
*
* @return void
* @return void
*/
*/
public
function
rewind
()
{
public
function
rewind
()
{
...
@@ -45,18 +51,24 @@ abstract class Doctrine_Iterator implements Iterator {
...
@@ -45,18 +51,24 @@ abstract class Doctrine_Iterator implements Iterator {
}
}
/**
/**
* @return integer the current key
* returns the current key
*
* @return integer
*/
*/
public
function
key
()
{
public
function
key
()
{
return
$this
->
key
;
return
$this
->
key
;
}
}
/**
/**
* @return Doctrine_Record the current record
* returns the current record
*
* @return Doctrine_Record
*/
*/
public
function
current
()
{
public
function
current
()
{
return
$this
->
collection
->
get
(
$this
->
key
);
return
$this
->
collection
->
get
(
$this
->
key
);
}
}
/**
/**
* advances the internal pointer
*
* @return void
* @return void
*/
*/
public
function
next
()
{
public
function
next
()
{
...
...
classes/Query.class.php
View file @
7778d2b0
...
@@ -67,6 +67,8 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -67,6 +67,8 @@ class Doctrine_Query extends Doctrine_Access {
"offset"
=>
false
,
"offset"
=>
false
,
);
);
/**
/**
* constructor
*
* @param Doctrine_Session $session
* @param Doctrine_Session $session
*/
*/
public
function
__construct
(
Doctrine_Session
$session
)
{
public
function
__construct
(
Doctrine_Session
$session
)
{
...
@@ -75,6 +77,8 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -75,6 +77,8 @@ class Doctrine_Query extends Doctrine_Access {
/**
/**
* clear
* clear
* resets all the variables
* resets all the variables
*
* @return void
*/
*/
private
function
clear
()
{
private
function
clear
()
{
$this
->
fetchModes
=
array
();
$this
->
fetchModes
=
array
();
...
@@ -99,10 +103,11 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -99,10 +103,11 @@ class Doctrine_Query extends Doctrine_Access {
$this
->
joined
=
array
();
$this
->
joined
=
array
();
}
}
/**
/**
* loadFields -- this method loads fields for a given factory and
* loadFields
* loads fields for a given table and
* constructs a little bit of sql for every field
* constructs a little bit of sql for every field
*
*
*
fields of the factori
es become: [tablename].[fieldname] as [tablename]__[fieldname]
*
fields of the tabl
es become: [tablename].[fieldname] as [tablename]__[fieldname]
*
*
* @access private
* @access private
* @param object Doctrine_Table $table a Doctrine_Table object
* @param object Doctrine_Table $table a Doctrine_Table object
...
@@ -141,8 +146,11 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -141,8 +146,11 @@ class Doctrine_Query extends Doctrine_Access {
}
}
}
}
/**
/**
* sets a query part
*
* @param string $name
* @param string $name
* @param array $args
* @param array $args
* @return void
*/
*/
public
function
__call
(
$name
,
$args
)
{
public
function
__call
(
$name
,
$args
)
{
$name
=
strtolower
(
$name
);
$name
=
strtolower
(
$name
);
...
@@ -168,6 +176,8 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -168,6 +176,8 @@ class Doctrine_Query extends Doctrine_Access {
return
$this
;
return
$this
;
}
}
/**
/**
* returns a query part
*
* @param $name query part name
* @param $name query part name
* @return mixed
* @return mixed
*/
*/
...
@@ -178,6 +188,8 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -178,6 +188,8 @@ class Doctrine_Query extends Doctrine_Access {
return
$this
->
parts
[
$name
];
return
$this
->
parts
[
$name
];
}
}
/**
/**
* sets a query part
*
* @param $name query part name
* @param $name query part name
* @param $value query part value
* @param $value query part value
* @return boolean
* @return boolean
...
@@ -207,7 +219,9 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -207,7 +219,9 @@ class Doctrine_Query extends Doctrine_Access {
return
false
;
return
false
;
}
}
/**
/**
* @return string the built sql query
* returns the built sql query
*
* @return string
*/
*/
final
public
function
getQuery
()
{
final
public
function
getQuery
()
{
if
(
empty
(
$this
->
parts
[
"columns"
])
||
empty
(
$this
->
parts
[
"from"
]))
if
(
empty
(
$this
->
parts
[
"columns"
])
||
empty
(
$this
->
parts
[
"from"
]))
...
@@ -271,6 +285,7 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -271,6 +285,7 @@ class Doctrine_Query extends Doctrine_Access {
/**
/**
* applyInheritance
* applyInheritance
* applies column aggregation inheritance to DQL query
* applies column aggregation inheritance to DQL query
*
* @return boolean
* @return boolean
*/
*/
final
public
function
applyInheritance
()
{
final
public
function
applyInheritance
()
{
...
@@ -324,8 +339,8 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -324,8 +339,8 @@ class Doctrine_Query extends Doctrine_Access {
}
}
/**
/**
* getData
* getData
* @param $key the
factory
name
* @param $key the
component
name
* @return array the data row for the specified
factory
* @return array the data row for the specified
component
*/
*/
final
public
function
getData
(
$key
)
{
final
public
function
getData
(
$key
)
{
if
(
isset
(
$this
->
data
[
$key
])
&&
is_array
(
$this
->
data
[
$key
]))
if
(
isset
(
$this
->
data
[
$key
])
&&
is_array
(
$this
->
data
[
$key
]))
...
@@ -335,7 +350,8 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -335,7 +350,8 @@ class Doctrine_Query extends Doctrine_Access {
}
}
/**
/**
* execute
* execute
* executes the datagraph and populates Doctrine_Collections
* executes the dql query and populates all collections
*
* @param string $params
* @param string $params
* @return Doctrine_Collection the root collection
* @return Doctrine_Collection the root collection
*/
*/
...
@@ -423,6 +439,8 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -423,6 +439,8 @@ class Doctrine_Query extends Doctrine_Access {
}
}
/**
/**
* parseData
* parseData
* parses a PDOStatement
*
* @return array
* @return array
*/
*/
public
function
parseData
(
PDOStatement
$stmt
)
{
public
function
parseData
(
PDOStatement
$stmt
)
{
...
@@ -447,6 +465,9 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -447,6 +465,9 @@ class Doctrine_Query extends Doctrine_Access {
return
$array
;
return
$array
;
}
}
/**
/**
* returns a Doctrine_Table for given name
*
* @param string $name component name
* @return Doctrine_Table
* @return Doctrine_Table
*/
*/
public
function
getTable
(
$name
)
{
public
function
getTable
(
$name
)
{
...
@@ -454,6 +475,8 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -454,6 +475,8 @@ class Doctrine_Query extends Doctrine_Access {
}
}
/**
/**
* getCollection
* getCollection
*
* @parma string $name component name
* @param integer $index
* @param integer $index
*/
*/
private
function
getCollection
(
$name
)
{
private
function
getCollection
(
$name
)
{
...
@@ -504,6 +527,9 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -504,6 +527,9 @@ class Doctrine_Query extends Doctrine_Access {
}
}
/**
/**
* DQL PARSER
* DQL PARSER
*
* @param string $query DQL query
* @return void
*/
*/
final
public
function
parseQuery
(
$query
)
{
final
public
function
parseQuery
(
$query
)
{
$this
->
clear
();
$this
->
clear
();
...
@@ -588,6 +614,7 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -588,6 +614,7 @@ class Doctrine_Query extends Doctrine_Access {
/**
/**
* DQL SELECT PARSER
* DQL SELECT PARSER
* parses the select part of the query string
* parses the select part of the query string
*
* @param string $str
* @param string $str
* @return void
* @return void
*/
*/
...
...
classes/Record.class.php
View file @
7778d2b0
...
@@ -54,7 +54,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -54,7 +54,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*/
*/
protected
$id
;
protected
$id
;
/**
/**
* @var array $data the
dao
data
* @var array $data the
record
data
*/
*/
protected
$data
=
array
();
protected
$data
=
array
();
...
@@ -63,12 +63,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -63,12 +63,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*/
*/
private
$modified
=
array
();
private
$modified
=
array
();
/**
/**
* @var integer $state the state of this
data access object
* @var integer $state the state of this
record
* @see STATE_* constants
* @see STATE_* constants
*/
*/
private
$state
;
private
$state
;
/**
/**
* @var array $collections the collections this
dao
is in
* @var array $collections the collections this
record
is in
*/
*/
private
$collections
=
array
();
private
$collections
=
array
();
/**
/**
...
@@ -151,12 +151,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -151,12 +151,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
// listen the onLoad event
// listen the onLoad event
$this
->
table
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onLoad
(
$this
);
$this
->
table
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onLoad
(
$this
);
}
}
// add data access object to registry
$this
->
table
->
getRepository
()
->
add
(
$this
);
$this
->
table
->
getRepository
()
->
add
(
$this
);
$this
->
table
->
setData
(
array
());
}
}
}
}
/**
/**
...
@@ -166,6 +161,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -166,6 +161,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public
function
setUp
()
{
}
public
function
setUp
()
{
}
/**
/**
* return the object identifier
* return the object identifier
*
* @return integer
* @return integer
*/
*/
public
function
getOID
()
{
public
function
getOID
()
{
...
@@ -200,6 +196,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -200,6 +196,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
return
$cols
;
return
$cols
;
}
}
/**
/**
* prepares identifiers
*
* @return void
* @return void
*/
*/
public
function
prepareIdentifiers
()
{
public
function
prepareIdentifiers
()
{
...
@@ -217,6 +215,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -217,6 +215,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
}
/**
/**
* this method is automatically called when this Doctrine_Record is serialized
* this method is automatically called when this Doctrine_Record is serialized
*
* @return array
*/
*/
public
function
__sleep
()
{
public
function
__sleep
()
{
$this
->
table
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onSleep
(
$this
);
$this
->
table
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onSleep
(
$this
);
...
@@ -241,6 +241,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -241,6 +241,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
/**
/**
* __wakeup
* __wakeup
* this method is automatically called everytime a Doctrine_Record object is unserialized
* this method is automatically called everytime a Doctrine_Record object is unserialized
*
* @return void
*/
*/
public
function
__wakeup
()
{
public
function
__wakeup
()
{
$this
->
modified
=
array
();
$this
->
modified
=
array
();
...
@@ -388,6 +390,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -388,6 +390,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
}
return
$this
->
data
[
$name
];
return
$this
->
data
[
$name
];
}
}
if
(
$name
==
$this
->
table
->
getIdentifier
())
if
(
$name
==
$this
->
table
->
getIdentifier
())
return
$this
->
id
;
return
$this
->
id
;
...
@@ -755,9 +758,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -755,9 +758,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param integer $id
* @param integer $id
* @return void
* @return void
*/
*/
final
public
function
setID
(
$id
=
null
)
{
final
public
function
setID
(
$id
=
false
)
{
if
(
$id
===
null
)
{
if
(
$id
===
false
)
{
$this
->
id
=
null
;
$this
->
id
=
false
;
$this
->
cleanData
();
$this
->
cleanData
();
$this
->
state
=
Doctrine_Record
::
STATE_TCLEAN
;
$this
->
state
=
Doctrine_Record
::
STATE_TCLEAN
;
$this
->
modified
=
array
();
$this
->
modified
=
array
();
...
...
classes/Relation.class.php
View file @
7778d2b0
<?php
<?php
/**
/**
*
@class
Doctrine_Relation
* Doctrine_Relation
*
*
* @author Konsta Vesterinen
* @package Doctrine ORM
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @url www.phpdoctrine.com
* @license LGPL
* @license LGPL
* @version 1.0 alpha
*
*/
*/
class
Doctrine_Relation
{
class
Doctrine_Relation
{
/**
/**
...
...
classes/Session.class.php
View file @
7778d2b0
...
@@ -193,7 +193,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -193,7 +193,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$class
=
$name
.
"Table"
;
$class
=
$name
.
"Table"
;
if
(
class_exists
(
$class
,
false
)
&&
in_array
(
"Doctrine_Table"
,
class_parents
(
$class
)))
{
if
(
class_exists
(
$class
)
&&
in_array
(
"Doctrine_Table"
,
class_parents
(
$class
)))
{
return
new
$class
(
$name
);
return
new
$class
(
$name
);
}
else
{
}
else
{
...
@@ -386,6 +386,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -386,6 +386,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
* @return void
* @return void
*/
*/
public
function
commit
()
{
public
function
commit
()
{
$this
->
transaction_level
--
;
$this
->
transaction_level
--
;
if
(
$this
->
transaction_level
==
0
)
{
if
(
$this
->
transaction_level
==
0
)
{
...
@@ -399,24 +400,25 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -399,24 +400,25 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onTransactionBegin
(
$this
);
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onTransactionBegin
(
$this
);
}
}
if
(
$this
->
getAttribute
(
Doctrine
::
ATTR_VLD
))
{
if
(
$this
->
getAttribute
(
Doctrine
::
ATTR_VLD
))
$this
->
validator
=
new
Doctrine_Validator
();
$this
->
validator
=
new
Doctrine_Validator
();
}
$this
->
bulkInsert
();
$this
->
bulkInsert
();
$this
->
bulkUpdate
();
$this
->
bulkUpdate
();
$this
->
bulkDelete
();
$this
->
bulkDelete
();
if
(
$this
->
getAttribute
(
Doctrine
::
ATTR_VLD
))
{
if
(
isset
(
$this
->
validator
)
&&
$this
->
validator
->
hasErrors
())
{
if
(
$this
->
validator
->
hasErrors
())
{
$this
->
rollback
();
$this
->
rollback
();
throw
new
Doctrine_Validator_Exception
(
$this
->
validator
);
throw
new
Doctrine_Validator_Exception
(
$this
->
validator
);
}
}
}
$this
->
dbh
->
commit
();
$this
->
dbh
->
commit
();
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onTransactionCommit
(
$this
);
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onTransactionCommit
(
$this
);
$this
->
delete
=
array
(
array
()
);
$this
->
delete
=
array
();
$this
->
state
=
Doctrine_Session
::
STATE_OPEN
;
$this
->
state
=
Doctrine_Session
::
STATE_OPEN
;
$this
->
validator
=
null
;
$this
->
validator
=
null
;
...
@@ -479,6 +481,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -479,6 +481,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
}
}
$record
->
setID
(
$id
);
$record
->
setID
(
$id
);
$id
++
;
$id
++
;
// listen the onInsert event
// listen the onInsert event
...
@@ -556,7 +559,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -556,7 +559,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$ids
=
array
();
$ids
=
array
();
foreach
(
$deletes
as
$k
=>
$record
)
{
foreach
(
$deletes
as
$k
=>
$record
)
{
$ids
[]
=
$record
->
getID
();
$ids
[]
=
$record
->
getID
();
$record
->
setID
(
null
);
$record
->
setID
(
false
);
}
}
if
(
$record
instanceof
Doctrine_Record
)
{
if
(
$record
instanceof
Doctrine_Record
)
{
$table
=
$record
->
getTable
();
$table
=
$record
->
getTable
();
...
@@ -716,6 +719,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -716,6 +719,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
return
false
;
return
false
;
$seq
=
$record
->
getTable
()
->
getSequenceName
();
$seq
=
$record
->
getTable
()
->
getSequenceName
();
if
(
!
empty
(
$seq
))
{
if
(
!
empty
(
$seq
))
{
$id
=
$this
->
getNextID
(
$seq
);
$id
=
$this
->
getNextID
(
$seq
);
$name
=
$record
->
getTable
()
->
getIdentifier
();
$name
=
$record
->
getTable
()
->
getIdentifier
();
...
...
classes/Table.class.php
View file @
7778d2b0
...
@@ -59,8 +59,10 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -59,8 +59,10 @@ class Doctrine_Table extends Doctrine_Configurable {
*/
*/
private
$sequenceName
;
private
$sequenceName
;
/**
/**
* @var
Doctrine_Repository $repository
first level cache
* @var
array $identityMap
first level cache
*/
*/
private
$identityMap
=
array
();
private
$repository
;
private
$repository
;
/**
/**
...
@@ -115,7 +117,7 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -115,7 +117,7 @@ class Doctrine_Table extends Doctrine_Configurable {
do
{
do
{
if
(
$class
==
"Doctrine_Record"
)
break
;
if
(
$class
==
"Doctrine_Record"
)
break
;
$name
=
ucwords
(
strtolower
(
$class
))
;
$name
=
$class
;
$names
[]
=
$name
;
$names
[]
=
$name
;
}
while
(
$class
=
get_parent_class
(
$class
));
}
while
(
$class
=
get_parent_class
(
$class
));
...
@@ -207,7 +209,6 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -207,7 +209,6 @@ class Doctrine_Table extends Doctrine_Configurable {
*/
*/
final
public
function
initComponents
()
{
final
public
function
initComponents
()
{
$this
->
repository
=
new
Doctrine_Repository
(
$this
);
$this
->
repository
=
new
Doctrine_Repository
(
$this
);
switch
(
$this
->
getAttribute
(
Doctrine
::
ATTR_CACHE
))
:
switch
(
$this
->
getAttribute
(
Doctrine
::
ATTR_CACHE
))
:
case
Doctrine
::
CACHE_SQLITE
:
case
Doctrine
::
CACHE_SQLITE
:
$this
->
cache
=
new
Doctrine_Cache_Sqlite
(
$this
);
$this
->
cache
=
new
Doctrine_Cache_Sqlite
(
$this
);
...
@@ -217,6 +218,9 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -217,6 +218,9 @@ class Doctrine_Table extends Doctrine_Configurable {
break
;
break
;
endswitch
;
endswitch
;
}
}
public
function
getRepository
()
{
return
$this
->
repository
;
}
/**
/**
* setColumn
* setColumn
* @param string $name
* @param string $name
...
@@ -322,7 +326,9 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -322,7 +326,9 @@ class Doctrine_Table extends Doctrine_Configurable {
return
$array
;
return
$array
;
}
}
/**
/**
* @var array bound relations
* returns all bound relations
*
* @return array
*/
*/
final
public
function
getBounds
()
{
final
public
function
getBounds
()
{
return
$this
->
bound
;
return
$this
->
bound
;
...
@@ -366,12 +372,6 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -366,12 +372,6 @@ class Doctrine_Table extends Doctrine_Configurable {
final
public
function
getCache
()
{
final
public
function
getCache
()
{
return
$this
->
cache
;
return
$this
->
cache
;
}
}
/**
* @return Doctrine_Repository
*/
final
public
function
getRepository
()
{
return
$this
->
repository
;
}
/**
/**
* @param string $name component name of which a foreign key object is bound
* @param string $name component name of which a foreign key object is bound
* @return Doctrine_Relation
* @return Doctrine_Relation
...
@@ -456,7 +456,9 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -456,7 +456,9 @@ class Doctrine_Table extends Doctrine_Configurable {
}
}
}
}
/**
/**
* @return array an array containing all foreign key objects
* returns an array containing all foreign key objects
*
* @return array
*/
*/
final
public
function
getForeignKeys
()
{
final
public
function
getForeignKeys
()
{
$a
=
array
();
$a
=
array
();
...
@@ -466,6 +468,9 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -466,6 +468,9 @@ class Doctrine_Table extends Doctrine_Configurable {
return
$a
;
return
$a
;
}
}
/**
/**
* sets the database table name
*
* @param string $name database table name
* @return void
* @return void
*/
*/
final
public
function
setTableName
(
$name
)
{
final
public
function
setTableName
(
$name
)
{
...
@@ -473,29 +478,36 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -473,29 +478,36 @@ class Doctrine_Table extends Doctrine_Configurable {
}
}
/**
/**
* @return string database table name this class represents
* returns the database table name
*
* @return string
*/
*/
final
public
function
getTableName
()
{
final
public
function
getTableName
()
{
return
$this
->
tableName
;
return
$this
->
tableName
;
}
}
/**
/**
* createDAO
* create
* creates a new record
*
* @param $array an array where keys are field names and values representing field values
* @param $array an array where keys are field names and values representing field values
* @return Doctrine_Record
A new Data Access Object. Uses an sql insert statement when saved
* @return Doctrine_Record
*/
*/
public
function
create
(
array
$array
=
array
())
{
public
function
create
(
array
$array
=
array
())
{
$this
->
data
=
$array
;
$this
->
data
=
$array
;
$this
->
isNewEntry
=
true
;
$this
->
isNewEntry
=
true
;
$record
=
$this
->
getRecord
(
);
$record
=
new
$this
->
name
(
$this
);
$this
->
isNewEntry
=
false
;
$this
->
isNewEntry
=
false
;
$this
->
data
=
array
();
return
$record
;
return
$record
;
}
}
/**
/**
* finds a record by its identifier
*
* @param $id database row id
* @param $id database row id
* @throws Doctrine_Find_Exception
* @throws Doctrine_Find_Exception
* @return Doctrine_Record a record for given database identifier
* @return Doctrine_Record a record for given database identifier
*/
*/
public
function
find
(
$id
=
null
)
{
public
function
find
(
$id
)
{
if
(
$id
!==
null
)
{
if
(
$id
!==
null
)
{
$query
=
$this
->
query
.
" WHERE "
.
implode
(
" = ? AND "
,
$this
->
primaryKeys
)
.
" = ?"
;
$query
=
$this
->
query
.
" WHERE "
.
implode
(
" = ? AND "
,
$this
->
primaryKeys
)
.
" = ?"
;
$query
=
$this
->
applyInheritance
(
$query
);
$query
=
$this
->
applyInheritance
(
$query
);
...
@@ -507,12 +519,12 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -507,12 +519,12 @@ class Doctrine_Table extends Doctrine_Configurable {
if
(
$this
->
data
===
false
)
if
(
$this
->
data
===
false
)
throw
new
Doctrine_Find_Exception
();
throw
new
Doctrine_Find_Exception
();
}
}
return
new
$this
->
name
(
$this
);
return
$this
->
getRecord
(
);
}
}
/**
/**
* applyInheritance
* applyInheritance
* @param $where query where part to be modified
* @param $where query where part to be modified
* @return
query where part with column aggregation inheritance added
* @return
string
query where part with column aggregation inheritance added
*/
*/
final
public
function
applyInheritance
(
$where
)
{
final
public
function
applyInheritance
(
$where
)
{
if
(
!
empty
(
$this
->
inheritanceMap
))
{
if
(
!
empty
(
$this
->
inheritanceMap
))
{
...
@@ -527,7 +539,9 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -527,7 +539,9 @@ class Doctrine_Table extends Doctrine_Configurable {
}
}
/**
/**
* findAll
* findAll
* @return Doctrine_Collection a collection of all data access objects
* returns a collection of records
*
* @return Doctrine_Collection
*/
*/
public
function
findAll
()
{
public
function
findAll
()
{
$graph
=
new
Doctrine_Query
(
$this
->
session
);
$graph
=
new
Doctrine_Query
(
$this
->
session
);
...
@@ -536,19 +550,49 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -536,19 +550,49 @@ class Doctrine_Table extends Doctrine_Configurable {
}
}
/**
/**
* findBySql
* findBySql
* @return Doctrine_Collection a collection of data access objects
* finds records with given sql where clause
* returns a collection of records
*
* @param string $sql SQL after WHERE clause
* @param array $params query parameters
* @return Doctrine_Collection
*/
*/
public
function
findBySql
(
$sql
,
array
$params
=
array
())
{
public
function
findBySql
(
$sql
,
array
$params
=
array
())
{
$
graph
=
new
Doctrine_Query
(
$this
->
session
);
$
q
=
new
Doctrine_Query
(
$this
->
session
);
$users
=
$
graph
->
query
(
"FROM "
.
$this
->
name
.
" WHERE "
.
$sql
,
$params
);
$users
=
$
q
->
query
(
"FROM "
.
$this
->
name
.
" WHERE "
.
$sql
,
$params
);
return
$users
;
return
$users
;
}
}
/**
* clear
* clears the first level cache (identityMap)
*
* @return void
*/
public
function
clear
()
{
$this
->
identityMap
=
array
();
}
/**
/**
* getRecord
* getRecord
* first checks if record exists in identityMap, if not
* returns a new record
*
* @return Doctrine_Record
* @return Doctrine_Record
*/
*/
public
function
getRecord
()
{
public
function
getRecord
()
{
return
new
$this
->
name
(
$this
);
$key
=
$this
->
getIdentifier
();
if
(
isset
(
$this
->
data
[
$key
]))
{
$id
=
$this
->
data
[
$key
];
if
(
isset
(
$this
->
identityMap
[
$id
]))
$record
=
$this
->
identityMap
[
$id
];
else
{
$record
=
new
$this
->
name
(
$this
);
$this
->
identityMap
[
$id
]
=
$record
;
}
$this
->
data
=
array
();
return
$record
;
}
throw
new
Doctrine_Exception
(
"No primary key found"
);
}
}
/**
/**
* @param $id database row id
* @param $id database row id
...
@@ -571,7 +615,7 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -571,7 +615,7 @@ class Doctrine_Table extends Doctrine_Configurable {
}
}
/**
/**
* getTableDescription
* getTableDescription
* @return Doctrine_Table_Description
the columns object for this factory
* @return Doctrine_Table_Description
*/
*/
final
public
function
getTableDescription
()
{
final
public
function
getTableDescription
()
{
return
$this
->
columns
;
return
$this
->
columns
;
...
@@ -611,20 +655,27 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -611,20 +655,27 @@ class Doctrine_Table extends Doctrine_Configurable {
return
$coll
;
return
$coll
;
}
}
/**
/**
* returns all columns and their definitions
*
* @return array
* @return array
*/
*/
final
public
function
getColumns
()
{
final
public
function
getColumns
()
{
return
$this
->
columns
;
return
$this
->
columns
;
}
}
/**
/**
* @return array an array containing all the column names
* returns an array containing all the column names
*
* @return array
*/
*/
public
function
getColumnNames
()
{
public
function
getColumnNames
()
{
return
array_keys
(
$this
->
columns
);
return
array_keys
(
$this
->
columns
);
}
}
/**
/**
* setData
* setData
* @param array $data internal data, users are strongly discouraged to use this function
* doctrine uses this function internally
* users are strongly discouraged to use this function
*
* @param array $data internal data
* @return void
* @return void
*/
*/
public
function
setData
(
array
$data
)
{
public
function
setData
(
array
$data
)
{
...
@@ -642,25 +693,34 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -642,25 +693,34 @@ class Doctrine_Table extends Doctrine_Configurable {
return
isset
(
$data
[
0
])
?
$data
[
0
]
:
1
;
return
isset
(
$data
[
0
])
?
$data
[
0
]
:
1
;
}
}
/**
/**
* @return boolean whether or not a newly created object is new or not
* return whether or not a newly created object is new or not
*
* @return boolean
*/
*/
final
public
function
isNewEntry
()
{
final
public
function
isNewEntry
()
{
return
$this
->
isNewEntry
;
return
$this
->
isNewEntry
;
}
}
/**
/**
* @return string simple cached query
* returns simple cached query
*
* @return string
*/
*/
final
public
function
getQuery
()
{
final
public
function
getQuery
()
{
return
$this
->
query
;
return
$this
->
query
;
}
}
/**
/**
* @return array internal data, used by Doctrine_Record instances when retrieving data from database
* returns internal data, used by Doctrine_Record instances
* when retrieving data from database
*
* @return array
*/
*/
final
public
function
getData
()
{
final
public
function
getData
()
{
return
$this
->
data
;
return
$this
->
data
;
}
}
/**
/**
* @return string string representation of this object
* returns a string representation of this object
*
* @return string
*/
*/
public
function
__toString
()
{
public
function
__toString
()
{
return
Doctrine_Lib
::
getTableAsString
(
$this
);
return
Doctrine_Lib
::
getTableAsString
(
$this
);
...
...
tests/AccessTestCase.class.php
View file @
7778d2b0
<?php
<?php
class
Doctrine_AccessTestCase
extends
Doctrine_UnitTestCase
{
class
Doctrine_AccessTestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareData
()
{
}
public
function
testOffsetMethods
()
{
public
function
testOffsetMethods
()
{
$this
->
assertEqual
(
$this
->
new
[
"name"
],
null
);
$user
=
new
User
();
$this
->
assertEqual
(
$user
[
"name"
],
null
);
$
this
->
new
[
"name"
]
=
"Jack"
;
$
user
[
"name"
]
=
"Jack"
;
$this
->
assertEqual
(
$
this
->
new
[
"name"
],
"Jack"
);
$this
->
assertEqual
(
$
user
[
"name"
],
"Jack"
);
$
this
->
assertEqual
(
$this
->
old
[
"name"
],
"zYne"
);
$
user
->
save
(
);
$this
->
old
[
"name"
]
=
"Jack"
;
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
$user
->
getID
());
$this
->
assertEqual
(
$this
->
old
[
"name"
],
"Jack"
);
$this
->
assertEqual
(
$user
->
name
,
"Jack"
);
$user
[
"name"
]
=
"Jack"
;
$this
->
assertEqual
(
$user
[
"name"
],
"Jack"
);
$user
[
"name"
]
=
"zYne"
;
$this
->
assertEqual
(
$user
[
"name"
],
"zYne"
);
}
}
public
function
testOverload
()
{
public
function
testOverload
()
{
$this
->
assertEqual
(
$this
->
new
->
name
,
null
);
$user
=
new
User
();
$this
->
assertEqual
(
$user
->
name
,
null
);
$user
->
name
=
"Jack"
;
$this
->
new
->
name
=
"Jack"
;
$this
->
assertEqual
(
$user
->
name
,
"Jack"
);
$this
->
assertEqual
(
$this
->
new
->
name
,
"Jack"
);
$
this
->
assertEqual
(
$this
->
old
->
name
,
"zYne"
);
$
user
->
save
(
);
$this
->
old
->
name
=
"Jack"
;
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
$user
->
getID
());
$this
->
assertEqual
(
$this
->
old
->
name
,
"Jack"
);
$this
->
assertEqual
(
$user
->
name
,
"Jack"
);
$user
->
name
=
"Jack"
;
$this
->
assertEqual
(
$user
->
name
,
"Jack"
);
$user
->
name
=
"zYne"
;
$this
->
assertEqual
(
$user
->
name
,
"zYne"
);
}
}
public
function
testSet
()
{
public
function
testSet
()
{
$this
->
assertEqual
(
$this
->
new
->
get
(
"name"
),
null
);
$user
=
new
User
();
$this
->
assertEqual
(
$user
->
get
(
"name"
),
null
);
$user
->
set
(
"name"
,
"Jack"
);
$this
->
assertEqual
(
$user
->
get
(
"name"
),
"Jack"
);
$this
->
new
->
set
(
"name"
,
"Jack"
);
$user
->
save
();
$this
->
assertEqual
(
$this
->
new
->
get
(
"name"
),
"Jack"
);
$
this
->
assertEqual
(
$this
->
old
->
get
(
"name"
),
"zYne"
);
$
user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
$user
->
getID
()
);
$this
->
old
->
set
(
"name"
,
"Jack"
);
$this
->
assertEqual
(
$user
->
get
(
"name"
),
"Jack"
);
$this
->
assertEqual
(
$this
->
old
->
get
(
"name"
),
"Jack"
);
$this
->
assertEqual
(
$this
->
old
->
getID
(),
4
);
$user
->
set
(
"name"
,
"Jack"
);
$this
->
assertEqual
(
$user
->
get
(
"name"
),
"Jack"
);
}
}
}
}
?>
?>
tests/CollectionTestCase.class.php
View file @
7778d2b0
...
@@ -41,7 +41,9 @@ class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
...
@@ -41,7 +41,9 @@ class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
$generator
=
new
Doctrine_IndexGenerator
(
$this
->
objTable
->
getIdentifier
());
$generator
=
new
Doctrine_IndexGenerator
(
$this
->
objTable
->
getIdentifier
());
$coll
->
setGenerator
(
$generator
);
$coll
->
setGenerator
(
$generator
);
$generator
=
$coll
->
getGenerator
();
$generator
=
$coll
->
getGenerator
();
$this
->
assertEqual
(
$generator
->
getIndex
(
$this
->
old
),
4
);
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
4
);
$this
->
assertEqual
(
$generator
->
getIndex
(
$user
),
4
);
}
}
public
function
testGenerator
()
{
public
function
testGenerator
()
{
...
...
tests/ConfigurableTestCase.class.php
View file @
7778d2b0
...
@@ -2,7 +2,11 @@
...
@@ -2,7 +2,11 @@
require_once
(
"UnitTestCase.class.php"
);
require_once
(
"UnitTestCase.class.php"
);
class
Doctrine_ConfigurableTestCase
extends
Doctrine_UnitTestCase
{
class
Doctrine_ConfigurableTestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareTables
()
{
}
public
function
prepareData
()
{
}
public
function
testSetAttribute
()
{
public
function
testSetAttribute
()
{
$table
=
$this
->
session
->
getTable
(
"User"
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_CACHE_TTL
,
100
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_CACHE_TTL
,
100
);
$this
->
assertEqual
(
$this
->
manager
->
getAttribute
(
Doctrine
::
ATTR_CACHE_TTL
),
100
);
$this
->
assertEqual
(
$this
->
manager
->
getAttribute
(
Doctrine
::
ATTR_CACHE_TTL
),
100
);
...
@@ -64,14 +68,14 @@ class Doctrine_ConfigurableTestCase extends Doctrine_UnitTestCase {
...
@@ -64,14 +68,14 @@ class Doctrine_ConfigurableTestCase extends Doctrine_UnitTestCase {
$e
=
false
;
$e
=
false
;
try
{
try
{
$t
his
->
objT
able
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
"unknown"
);
$table
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
"unknown"
);
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
}
}
$this
->
assertTrue
(
$e
instanceof
Exception
);
$this
->
assertTrue
(
$e
instanceof
Exception
);
$e
=
true
;
$e
=
true
;
try
{
try
{
$t
his
->
objT
able
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
"name"
);
$table
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
"name"
);
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
}
}
$this
->
assertTrue
(
$e
);
$this
->
assertTrue
(
$e
);
...
...
tests/EventListenerTestCase.class.php
View file @
7778d2b0
...
@@ -9,5 +9,7 @@ class Doctrine_EventListenerTestCase extends Doctrine_UnitTestCase {
...
@@ -9,5 +9,7 @@ class Doctrine_EventListenerTestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
$last
->
getObject
()
instanceof
Doctrine_Session
);
$this
->
assertTrue
(
$last
->
getObject
()
instanceof
Doctrine_Session
);
$this
->
assertTrue
(
$last
->
getCode
()
==
Doctrine_Debugger
::
EVENT_OPEN
);
$this
->
assertTrue
(
$last
->
getCode
()
==
Doctrine_Debugger
::
EVENT_OPEN
);
}
}
public
function
prepareData
()
{
}
public
function
prepareTables
()
{
}
}
}
?>
?>
tests/ManagerTestCase.class.php
View file @
7778d2b0
...
@@ -19,5 +19,7 @@ class Doctrine_ManagerTestCase extends Doctrine_UnitTestCase {
...
@@ -19,5 +19,7 @@ class Doctrine_ManagerTestCase extends Doctrine_UnitTestCase {
public
function
testGetSessions
()
{
public
function
testGetSessions
()
{
$this
->
assertEqual
(
count
(
$this
->
manager
->
getSessions
()),
1
);
$this
->
assertEqual
(
count
(
$this
->
manager
->
getSessions
()),
1
);
}
}
public
function
prepareData
()
{
}
public
function
prepareTables
()
{
}
}
}
?>
?>
tests/QueryTestCase.class.php
View file @
7778d2b0
...
@@ -174,7 +174,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
...
@@ -174,7 +174,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection_Immediate
);
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection_Immediate
);
$count2
=
$this
->
session
->
getDBH
()
->
count
();
$count2
=
$this
->
session
->
getDBH
()
->
count
();
$this
->
assertEqual
(
$count
,
$count2
);
$users
=
$query
->
query
(
"FROM User-b"
);
$users
=
$query
->
query
(
"FROM User-b"
);
...
...
tests/RecordTestCase.class.php
View file @
7778d2b0
...
@@ -107,11 +107,16 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
...
@@ -107,11 +107,16 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$user
->
name
,
"Jack Daniels"
);
$this
->
assertEqual
(
$user
->
name
,
"Jack Daniels"
);
$this
->
assertEqual
(
$user
->
created
,
null
);
$this
->
assertEqual
(
$user
->
created
,
null
);
$this
->
assertEqual
(
$user
->
updated
,
null
);
$this
->
assertEqual
(
$user
->
updated
,
null
);
$this
->
assertEqual
(
$user
->
getTable
()
->
getData
(),
array
());
}
}
public
function
testNewOperator
()
{
public
function
testNewOperator
()
{
$table
=
$this
->
session
->
getTable
(
"User"
);
$this
->
assertEqual
(
$this
->
session
->
getTable
(
"User"
)
->
getData
(),
array
());
$user
=
new
User
();
$user
=
new
User
();
$this
->
assert
True
(
$user
->
getState
()
==
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assert
Equal
(
Doctrine_Lib
::
getRecordStateAsString
(
$user
->
getState
()),
Doctrine_Lib
::
getRecordStateAsString
(
Doctrine_Record
::
STATE_TCLEAN
)
);
$user
->
name
=
"John Locke"
;
$user
->
name
=
"John Locke"
;
$this
->
assertTrue
(
$user
->
name
,
"John Locke"
);
$this
->
assertTrue
(
$user
->
name
,
"John Locke"
);
...
@@ -244,36 +249,35 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
...
@@ -244,36 +249,35 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$e
->
message
,
"changed message"
);
$this
->
assertEqual
(
$e
->
message
,
"changed message"
);
$this
->
assertEqual
(
$e
->
Description
[
0
]
->
description
,
"1st changed description"
);
$this
->
assertEqual
(
$e
->
Description
[
0
]
->
description
,
"1st changed description"
);
$this
->
assertEqual
(
$e
->
Description
[
1
]
->
description
,
"2nd changed description"
);
$this
->
assertEqual
(
$e
->
Description
[
1
]
->
description
,
"2nd changed description"
);
}
}
public
function
testInsert
()
{
public
function
testInsert
()
{
$this
->
new
->
name
=
"John Locke"
;
$user
=
new
User
();
$this
->
new
->
save
();
$user
->
name
=
"John Locke"
;
$user
->
save
();
$this
->
assertTrue
(
$
this
->
new
->
getModified
()
==
array
());
$this
->
assertTrue
(
$
user
->
getModified
()
==
array
());
$this
->
assertTrue
(
$
this
->
new
->
getState
()
==
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertTrue
(
$
user
->
getState
()
==
Doctrine_Record
::
STATE_CLEAN
);
$debug
=
$this
->
listener
->
getMessages
();
$debug
=
$this
->
listener
->
getMessages
();
$p
=
array_pop
(
$debug
);
$p
=
array_pop
(
$debug
);
$this
->
assertTrue
(
$p
->
getObject
()
instanceof
Doctrine_Session
);
$this
->
assertTrue
(
$p
->
getObject
()
instanceof
Doctrine_Session
);
$this
->
assertTrue
(
$p
->
getCode
()
==
Doctrine_Debugger
::
EVENT_COMMIT
);
$this
->
assertTrue
(
$p
->
getCode
()
==
Doctrine_Debugger
::
EVENT_COMMIT
);
$
this
->
new
->
delete
();
$
user
->
delete
();
$this
->
assertTrue
(
$
this
->
new
->
getState
()
==
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assertTrue
(
$
user
->
getState
()
==
Doctrine_Record
::
STATE_TCLEAN
);
}
}
public
function
testUpdate
()
{
public
function
testUpdate
()
{
$this
->
old
->
set
(
"name"
,
"Jack Daniels"
,
true
);
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
4
);
$user
->
set
(
"name"
,
"Jack Daniels"
,
true
);
$
this
->
old
->
save
(
true
);
$
user
->
save
(
);
//print $this->old->name;
//print $this->old->name;
$this
->
assertEqual
(
$
this
->
old
->
getModified
(),
array
());
$this
->
assertEqual
(
$
user
->
getModified
(),
array
());
$this
->
assertEqual
(
$
this
->
old
->
name
,
"Jack Daniels"
);
$this
->
assertEqual
(
$
user
->
name
,
"Jack Daniels"
);
$debug
=
$this
->
listener
->
getMessages
();
$debug
=
$this
->
listener
->
getMessages
();
$p
=
array_pop
(
$debug
);
$p
=
array_pop
(
$debug
);
...
@@ -291,7 +295,8 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
...
@@ -291,7 +295,8 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
}
}
public
function
testCopy
()
{
public
function
testCopy
()
{
$new
=
$this
->
old
->
copy
();
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
4
);
$new
=
$user
->
copy
();
$this
->
assertTrue
(
$new
instanceof
Doctrine_Record
);
$this
->
assertTrue
(
$new
instanceof
Doctrine_Record
);
$this
->
assertTrue
(
$new
->
getState
()
==
Doctrine_Record
::
STATE_TDIRTY
);
$this
->
assertTrue
(
$new
->
getState
()
==
Doctrine_Record
::
STATE_TDIRTY
);
}
}
...
@@ -522,27 +527,31 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
...
@@ -522,27 +527,31 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
}
}
public
function
testCount
()
{
public
function
testCount
()
{
$this
->
assertTrue
(
is_integer
(
$this
->
old
->
count
()));
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
4
);
$this
->
assertTrue
(
is_integer
(
$user
->
count
()));
}
}
public
function
testGetReference
()
{
public
function
testGetReference
()
{
$this
->
assertTrue
(
$this
->
old
->
Email
instanceof
Doctrine_Record
);
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
4
);
$this
->
assertTrue
(
$this
->
old
->
Phonenumber
instanceof
Doctrine_Collection
);
$this
->
assertTrue
(
$this
->
old
->
Group
instanceof
Doctrine_Collection
);
$this
->
assertTrue
(
$this
->
old
->
Phonenumber
->
count
()
==
1
);
$this
->
assertTrue
(
$user
->
Email
instanceof
Doctrine_Record
);
$this
->
assertTrue
(
$user
->
Phonenumber
instanceof
Doctrine_Collection
);
$this
->
assertTrue
(
$user
->
Group
instanceof
Doctrine_Collection
);
$this
->
assertTrue
(
$user
->
Phonenumber
->
count
()
==
1
);
}
}
public
function
testSerialize
()
{
public
function
testSerialize
()
{
$
old
=
$this
->
old
;
$
user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
4
)
;
$
old
=
serialize
(
$old
);
$
str
=
serialize
(
$user
);
$this
->
assertEqual
(
unserialize
(
$
old
)
->
getID
(),
$this
->
old
->
getID
());
$this
->
assertEqual
(
unserialize
(
$
str
)
->
getID
(),
$user
->
getID
());
}
}
public
function
testGetIterator
()
{
public
function
testGetIterator
()
{
$this
->
assertTrue
(
$this
->
old
->
getIterator
()
instanceof
ArrayIterator
);
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
4
);
$this
->
assertTrue
(
$user
->
getIterator
()
instanceof
ArrayIterator
);
}
}
}
}
?>
?>
tests/SessionTestCase.class.php
View file @
7778d2b0
...
@@ -17,8 +17,8 @@ class Doctrine_SessionTestCase extends Doctrine_UnitTestCase {
...
@@ -17,8 +17,8 @@ class Doctrine_SessionTestCase extends Doctrine_UnitTestCase {
}
}
public
function
testFlush
()
{
public
function
testFlush
()
{
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
4
);
$this
->
assertTrue
(
is_numeric
(
$
this
->
old
->
Phonenumber
[
0
]
->
entity_id
));
$this
->
assertTrue
(
is_numeric
(
$
user
->
Phonenumber
[
0
]
->
entity_id
));
$user
=
$this
->
session
->
create
(
"Email"
);
$user
=
$this
->
session
->
create
(
"Email"
);
$user
=
$this
->
session
->
create
(
"User"
);
$user
=
$this
->
session
->
create
(
"User"
);
...
...
tests/UnitTestCase.class.php
View file @
7778d2b0
...
@@ -14,7 +14,6 @@ class Doctrine_UnitTestCase extends UnitTestCase {
...
@@ -14,7 +14,6 @@ class Doctrine_UnitTestCase extends UnitTestCase {
protected
$manager
;
protected
$manager
;
protected
$session
;
protected
$session
;
protected
$objTable
;
protected
$objTable
;
protected
$repository
;
protected
$new
;
protected
$new
;
protected
$old
;
protected
$old
;
protected
$dbh
;
protected
$dbh
;
...
@@ -33,7 +32,6 @@ class Doctrine_UnitTestCase extends UnitTestCase {
...
@@ -33,7 +32,6 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_FETCHMODE
,
Doctrine
::
FETCH_IMMEDIATE
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_FETCHMODE
,
Doctrine
::
FETCH_IMMEDIATE
);
$this
->
tables
=
array
(
"entity"
,
"email"
,
"phonenumber"
,
"groupuser"
,
"album"
,
"song"
,
"element"
,
"error"
,
"description"
,
"address"
,
"account"
,
"task"
,
"resource"
,
"assignment"
);
$this
->
tables
=
array
(
"entity"
,
"email"
,
"phonenumber"
,
"groupuser"
,
"album"
,
"song"
,
"element"
,
"error"
,
"description"
,
"address"
,
"account"
,
"task"
,
"resource"
,
"assignment"
);
$tables
=
$this
->
tables
;
...
@@ -50,23 +48,22 @@ class Doctrine_UnitTestCase extends UnitTestCase {
...
@@ -50,23 +48,22 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_LISTENER
,
$this
->
listener
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_LISTENER
,
$this
->
listener
);
}
}
foreach
(
$tables
as
$name
)
{
$this
->
prepareTables
();
$this
->
prepareData
();
}
public
function
prepareTables
()
{
foreach
(
$this
->
tables
as
$name
)
{
$this
->
dbh
->
query
(
"DROP TABLE IF EXISTS
$name
"
);
$this
->
dbh
->
query
(
"DROP TABLE IF EXISTS
$name
"
);
}
}
foreach
(
$tables
as
$name
)
{
foreach
(
$t
his
->
t
ables
as
$name
)
{
$name
=
ucwords
(
$name
);
$name
=
ucwords
(
$name
);
$table
=
$this
->
session
->
getTable
(
$name
);
$table
=
$this
->
session
->
getTable
(
$name
);
$table
->
getCache
()
->
deleteAll
();
$table
->
getCache
()
->
deleteAll
();
$table
->
clear
();
}
}
$this
->
objTable
=
$this
->
session
->
getTable
(
"User"
);
$this
->
objTable
=
$this
->
session
->
getTable
(
"User"
);
$this
->
repository
=
$this
->
objTable
->
getRepository
();
//$this->cache = $this->objTable->getCache();
$this
->
prepareData
();
}
}
public
function
prepareData
()
{
public
function
prepareData
()
{
$groups
=
new
Doctrine_Collection
(
$this
->
session
->
getTable
(
"Group"
));
$groups
=
new
Doctrine_Collection
(
$this
->
session
->
getTable
(
"Group"
));
...
@@ -137,9 +134,10 @@ class Doctrine_UnitTestCase extends UnitTestCase {
...
@@ -137,9 +134,10 @@ class Doctrine_UnitTestCase extends UnitTestCase {
public
function
setUp
()
{
public
function
setUp
()
{
if
(
!
$this
->
init
)
$this
->
init
();
if
(
!
$this
->
init
)
$this
->
init
();
if
(
isset
(
$this
->
objTable
))
$this
->
objTable
->
clear
();
$this
->
init
=
true
;
$this
->
init
=
true
;
$this
->
new
=
$this
->
objTable
->
create
();
$this
->
old
=
$this
->
objTable
->
find
(
4
);
}
}
}
}
?>
?>
tests/ValidatorTestCase.class.php
View file @
7778d2b0
<?php
<?php
class
Doctrine_ValidatorTestCase
extends
Doctrine_UnitTestCase
{
class
Doctrine_ValidatorTestCase
extends
Doctrine_UnitTestCase
{
public
function
testValidate
()
{
public
function
testValidate
()
{
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
4
);
$set
=
array
(
"password"
=>
"this is an example of too long password"
,
$set
=
array
(
"password"
=>
"this is an example of too long password"
,
"loginname"
=>
"this is an example of too long loginname"
,
"loginname"
=>
"this is an example of too long loginname"
,
"name"
=>
"valid name"
,
"name"
=>
"valid name"
,
"created"
=>
"invalid"
);
"created"
=>
"invalid"
);
$
this
->
old
->
setArray
(
$set
);
$
user
->
setArray
(
$set
);
$email
=
$
this
->
old
->
Email
;
$email
=
$
user
->
Email
;
$email
->
address
=
"zYne@invalid"
;
$email
->
address
=
"zYne@invalid"
;
$this
->
assertTrue
(
$
this
->
old
->
getModified
()
==
$set
);
$this
->
assertTrue
(
$
user
->
getModified
()
==
$set
);
$validator
=
new
Doctrine_Validator
();
$validator
=
new
Doctrine_Validator
();
$validator
->
validateRecord
(
$
this
->
old
);
$validator
->
validateRecord
(
$
user
);
$validator
->
validateRecord
(
$email
);
$validator
->
validateRecord
(
$email
);
$stack
=
$validator
->
getErrorStack
();
$stack
=
$validator
->
getErrorStack
();
...
@@ -31,6 +33,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
...
@@ -31,6 +33,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$stack
[
"Email"
][
1
][
"address"
],
Doctrine_Validator
::
ERR_UNIQUE
);
$this
->
assertEqual
(
$stack
[
"Email"
][
1
][
"address"
],
Doctrine_Validator
::
ERR_UNIQUE
);
}
}
public
function
testIsValidEmail
()
{
public
function
testIsValidEmail
()
{
$validator
=
new
Doctrine_Validator_Email
();
$validator
=
new
Doctrine_Validator_Email
();
...
@@ -47,10 +50,10 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
...
@@ -47,10 +50,10 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
}
}
public
function
testSave
()
{
public
function
testSave
()
{
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
true
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
true
);
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
4
);
try
{
try
{
$
this
->
old
->
name
=
"this is an example of too long name not very good example but an example nevertheless"
;
$
user
->
name
=
"this is an example of too long name not very good example but an example nevertheless"
;
$
this
->
old
->
save
();
$
user
->
save
();
}
catch
(
Doctrine_Validator_Exception
$e
)
{
}
catch
(
Doctrine_Validator_Exception
$e
)
{
$this
->
assertEqual
(
$e
->
getErrorStack
(),
array
(
"User"
=>
array
(
array
(
"name"
=>
0
))));
$this
->
assertEqual
(
$e
->
getErrorStack
(),
array
(
"User"
=>
array
(
array
(
"name"
=>
0
))));
}
}
...
@@ -66,6 +69,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
...
@@ -66,6 +69,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
is_array
(
$a
));
$this
->
assertTrue
(
is_array
(
$a
));
$this
->
assertEqual
(
$a
[
"Email"
][
0
][
"address"
],
Doctrine_Validator
::
ERR_VALID
);
$this
->
assertEqual
(
$a
[
"Email"
][
0
][
"address"
],
Doctrine_Validator
::
ERR_VALID
);
$this
->
assertEqual
(
$a
[
"User"
][
0
][
"name"
],
Doctrine_Validator
::
ERR_LENGTH
);
$this
->
assertEqual
(
$a
[
"User"
][
0
][
"name"
],
Doctrine_Validator
::
ERR_LENGTH
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
false
);
}
}
}
}
...
...
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