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
a2046460
Commit
a2046460
authored
Feb 17, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Relation model rewrite, draft 2
parent
94e5ce73
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
188 additions
and
111 deletions
+188
-111
Connection.php
lib/Doctrine/Connection.php
+10
-6
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+5
-5
Export.php
lib/Doctrine/Export.php
+5
-3
Record.php
lib/Doctrine/Record.php
+8
-9
Relation.php
lib/Doctrine/Relation.php
+29
-10
Association.php
lib/Doctrine/Relation/Association.php
+5
-5
ForeignKey.php
lib/Doctrine/Relation/ForeignKey.php
+6
-6
LocalKey.php
lib/Doctrine/Relation/LocalKey.php
+3
-3
Table.php
lib/Doctrine/Table.php
+37
-20
Validator.php
lib/Doctrine/Validator.php
+1
-0
BatchIteratorTestCase.php
tests/BatchIteratorTestCase.php
+1
-2
ConnectionTestCase.php
tests/ConnectionTestCase.php
+2
-1
EventListenerTestCase.php
tests/EventListenerTestCase.php
+1
-0
FilterTestCase.php
tests/FilterTestCase.php
+0
-14
RecordTestCase.php
tests/RecordTestCase.php
+36
-6
UnitTestCase.php
tests/UnitTestCase.php
+12
-5
ValidatorTestCase.php
tests/ValidatorTestCase.php
+3
-1
run.php
tests/run.php
+24
-15
No files found.
lib/Doctrine/Connection.php
View file @
a2046460
...
...
@@ -684,7 +684,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
}
catch
(
Doctrine_Adapter_Exception
$e
)
{
}
catch
(
PDOException
$e
)
{
}
print
Doctrine_Lib
::
formatSql
(
$query
);
$this
->
rethrowException
(
$e
);
}
/**
...
...
@@ -742,18 +742,22 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param string $name component name
* @return object Doctrine_Table
*/
public
function
getTable
(
$name
)
public
function
getTable
(
$name
,
$allowExport
=
true
)
{
if
(
isset
(
$this
->
tables
[
$name
]))
{
return
$this
->
tables
[
$name
];
}
$class
=
$name
.
"Table"
;
$class
=
$name
.
'Table'
;
if
(
class_exists
(
$class
)
&&
in_array
(
"Doctrine_Table"
,
class_parents
(
$class
)))
{
return
new
$class
(
$name
,
$this
);
if
(
class_exists
(
$class
)
&&
in_array
(
'Doctrine_Table'
,
class_parents
(
$class
)))
{
$table
=
new
$class
(
$name
,
$this
,
$allowExport
);
}
else
{
return
new
Doctrine_Table
(
$name
,
$this
);
$table
=
new
Doctrine_Table
(
$name
,
$this
,
$allowExport
);
}
$this
->
tables
[
$name
]
=
$table
;
return
$table
;
}
/**
* returns an array of all initialized tables
...
...
lib/Doctrine/Connection/UnitOfWork.php
View file @
a2046460
...
...
@@ -47,13 +47,13 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
{
$tree
=
array
();
foreach
(
$tables
as
$k
=>
$table
)
{
$k
=
$k
.
$table
;
if
(
!
(
$table
instanceof
Doctrine_Table
))
{
$table
=
$this
->
conn
->
getTable
(
$table
);
}
$nm
=
$table
->
getComponentName
();
$index
=
array_search
(
$nm
,
$tree
);
$index
=
array_search
(
$nm
,
$tree
);
if
(
$index
===
false
)
{
$tree
[]
=
$nm
;
...
...
@@ -110,17 +110,17 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
if
(
$index2
!==
false
)
unset
(
$tree
[
$index2
]);
array_splice
(
$tree
,
$index
,
0
,
$name
);
array_splice
(
$tree
,
$index
,
0
,
$name
);
$index
++
;
$index3
=
array_search
(
$n
,
$tree
);
$index3
=
array_search
(
$n
,
$tree
);
if
(
$index3
!==
false
)
{
if
(
$index3
>=
$index
)
continue
;
unset
(
$tree
[
$index
]);
array_splice
(
$tree
,
$index3
,
0
,
$n
);
array_splice
(
$tree
,
$index3
,
0
,
$n
);
$index
=
$index2
;
}
else
{
$tree
[]
=
$n
;
...
...
lib/Doctrine/Export.php
View file @
a2046460
...
...
@@ -583,14 +583,15 @@ class Doctrine_Export extends Doctrine_Connection_Module
*/
public
function
getIndexFieldDeclarationList
(
array
$fields
)
{
$ret
=
array
();
foreach
(
$fields
as
$field
=>
$definition
)
{
if
(
is_array
(
$definition
))
{
$
fields
[]
=
$this
->
conn
->
quoteIdentifier
(
$field
);
$
ret
[]
=
$this
->
conn
->
quoteIdentifier
(
$field
);
}
else
{
$
fields
[]
=
$definition
;
$
ret
[]
=
$this
->
conn
->
quoteIdentifier
(
$definition
)
;
}
}
return
implode
(
', '
,
$
fields
);
return
implode
(
', '
,
$
ret
);
}
/**
* getForeignKeyDeclaration
...
...
@@ -686,6 +687,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
$sql
.=
'CONSTRAINT '
.
$definition
[
'name'
]
.
' '
;
}
$sql
.=
'FOREIGN KEY '
;
if
(
!
isset
(
$definition
[
'local'
]))
{
throw
new
Doctrine_Export_Exception
(
'Local reference field missing from definition.'
);
}
...
...
lib/Doctrine/Record.php
View file @
a2046460
...
...
@@ -776,7 +776,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this
->
loadReference
(
$name
);
}
}
catch
(
Doctrine_Table_Exception
$e
)
{
print
$e
;
throw
new
Doctrine_Record_Exception
(
"Unknown property / related component '
$name
'."
);
}
...
...
@@ -1378,9 +1377,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param string $fkField
* @return void
*/
final
public
function
ownsOne
(
$componentName
,
$foreignKey
,
$
localKey
=
null
)
final
public
function
ownsOne
(
$componentName
,
$foreignKey
,
$
options
=
null
)
{
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
ONE_COMPOSITE
,
$
localKey
);
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
ONE_COMPOSITE
,
$
options
);
}
/**
* binds One-to-Many composite relation
...
...
@@ -1389,9 +1388,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param string $fkField
* @return void
*/
final
public
function
ownsMany
(
$componentName
,
$foreignKey
,
$
localKey
=
null
)
final
public
function
ownsMany
(
$componentName
,
$foreignKey
,
$
options
=
null
)
{
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
MANY_COMPOSITE
,
$
localKey
);
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
MANY_COMPOSITE
,
$
options
);
}
/**
* binds One-to-One aggregate relation
...
...
@@ -1400,9 +1399,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param string $fkField
* @return void
*/
final
public
function
hasOne
(
$componentName
,
$foreignKey
,
$
localKey
=
null
)
final
public
function
hasOne
(
$componentName
,
$foreignKey
,
$
options
=
null
)
{
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
ONE_AGGREGATE
,
$
localKey
);
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
ONE_AGGREGATE
,
$
options
);
}
/**
* binds One-to-Many aggregate relation
...
...
@@ -1411,9 +1410,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param string $fkField
* @return void
*/
final
public
function
hasMany
(
$componentName
,
$foreignKey
,
$
localKey
=
null
)
final
public
function
hasMany
(
$componentName
,
$foreignKey
,
$
options
=
null
)
{
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
MANY_AGGREGATE
,
$
localKey
);
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
MANY_AGGREGATE
,
$
options
);
}
/**
* hasColumn
...
...
lib/Doctrine/Relation.php
View file @
a2046460
...
...
@@ -56,16 +56,22 @@ abstract class Doctrine_Relation
const
ONE
=
0
;
const
MANY
=
1
;
protected
$definition
=
array
(
'alias'
=>
true
,
'foreign'
=>
true
,
'local'
=>
true
,
'table'
=>
true
,
protected
$definition
=
array
(
'alias'
=>
true
,
'foreign'
=>
true
,
'local'
=>
true
,
'class'
=>
true
,
'type'
=>
true
,
'name'
=>
false
,
'assocTable'
=>
false
,
'onDelete'
=>
false
,
'onUpdate'
=>
false
,
'deferred'
=>
false
,
);
/**
* constructor
*
* @param array $definition an associative array with the following structure:
* name
related class
name
* name
foreign key constraint
name
*
* local the local field(s)
*
...
...
@@ -106,13 +112,26 @@ abstract class Doctrine_Relation
*/
public
function
__construct
(
array
$definition
)
{
foreach
(
array_keys
(
$this
->
definition
)
as
$key
)
{
if
(
!
isset
(
$definition
[
$key
]))
{
$def
=
array
();
foreach
(
$this
->
definition
as
$key
=>
$val
)
{
if
(
!
isset
(
$definition
[
$key
])
&&
$val
)
{
throw
new
Doctrine_Exception
(
$key
.
' is required!'
);
}
if
(
isset
(
$definition
[
$key
]))
{
$def
[
$key
]
=
$definition
[
$key
];
}
}
$this
->
definition
=
$definition
;
$this
->
definition
=
$def
;
}
/**
* toArray
*
* @return array
*/
public
function
toArray
()
{
return
$this
->
definition
;
}
/**
* getAlias
...
...
@@ -143,7 +162,7 @@ abstract class Doctrine_Relation
*/
final
public
function
getTable
()
{
return
$this
->
definition
[
'table'
]
;
return
Doctrine_Manager
::
connection
()
->
getTable
(
$this
->
definition
[
'class'
])
;
}
/**
* getLocal
...
...
@@ -196,7 +215,7 @@ abstract class Doctrine_Relation
*/
public
function
getRelationDql
(
$count
)
{
$component
=
$this
->
definition
[
'table'
]
->
getComponentName
();
$component
=
$this
->
getTable
()
->
getComponentName
();
$dql
=
'FROM '
.
$component
.
' WHERE '
.
$component
.
'.'
.
$this
->
definition
[
'foreign'
]
...
...
lib/Doctrine/Relation/Association.php
View file @
a2046460
...
...
@@ -97,14 +97,14 @@ class Doctrine_Relation_Association extends Doctrine_Relation
' IN ('
.
substr
(
str_repeat
(
"?, "
,
$count
),
0
,
-
2
)
.
')'
;
$dql
=
'FROM '
.
$this
->
definition
[
'table'
]
->
getComponentName
();
$dql
=
'FROM '
.
$this
->
getTable
()
->
getComponentName
();
$dql
.=
'.'
.
$component
;
$dql
.=
' WHERE '
.
$this
->
definition
[
'table'
]
->
getComponentName
()
.
'.'
.
$this
->
definition
[
'table'
]
->
getIdentifier
()
.
' IN ('
.
$sub
.
')'
;
$dql
.=
' WHERE '
.
$this
->
getTable
()
->
getComponentName
()
.
'.'
.
$this
->
getTable
()
->
getIdentifier
()
.
' IN ('
.
$sub
.
')'
;
break
;
case
"collection"
:
$sub
=
substr
(
str_repeat
(
"?, "
,
$count
),
0
,
-
2
);
$dql
=
'FROM '
.
$component
.
'.'
.
$this
->
definition
[
'table'
]
->
getComponentName
();
$dql
=
'FROM '
.
$component
.
'.'
.
$this
->
getTable
()
->
getComponentName
();
$dql
.=
' WHERE '
.
$component
.
'.'
.
$this
->
definition
[
'local'
]
.
' IN ('
.
$sub
.
')'
;
break
;
}
...
...
@@ -123,7 +123,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation
{
$id
=
$record
->
getIncremented
();
if
(
empty
(
$id
))
{
$coll
=
new
Doctrine_Collection
(
$this
->
definition
[
'table'
]
);
$coll
=
new
Doctrine_Collection
(
$this
->
getTable
()
);
}
else
{
$coll
=
Doctrine_Query
::
create
()
->
parseQuery
(
$this
->
getRelationDql
(
1
))
->
execute
(
array
(
$id
));
}
...
...
lib/Doctrine/Relation/ForeignKey.php
View file @
a2046460
...
...
@@ -80,13 +80,13 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
if
(
$this
->
isOneToOne
())
{
if
(
empty
(
$id
))
{
$related
=
$this
->
definition
[
'table'
]
->
create
();
$related
=
$this
->
getTable
()
->
create
();
}
else
{
$dql
=
'FROM '
.
$this
->
definition
[
'table'
]
->
getComponentName
()
.
' WHERE '
.
$this
->
definition
[
'table'
]
->
getComponentName
()
$dql
=
'FROM '
.
$this
->
getTable
()
->
getComponentName
()
.
' WHERE '
.
$this
->
getTable
()
->
getComponentName
()
.
'.'
.
$this
->
definition
[
'foreign'
]
.
' = ?'
;
$coll
=
$this
->
definition
[
'table'
]
->
getConnection
()
->
query
(
$dql
,
array
(
$id
));
$coll
=
$this
->
getTable
()
->
getConnection
()
->
query
(
$dql
,
array
(
$id
));
$related
=
$coll
[
0
];
}
...
...
@@ -95,10 +95,10 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
}
else
{
if
(
empty
(
$id
))
{
$related
=
new
Doctrine_Collection
(
$this
->
definition
[
'table'
]
);
$related
=
new
Doctrine_Collection
(
$this
->
getTable
()
);
}
else
{
$query
=
$this
->
getRelationDql
(
1
);
$related
=
$this
->
definition
[
'table'
]
->
getConnection
()
->
query
(
$query
,
array
(
$id
));
$related
=
$this
->
getTable
()
->
getConnection
()
->
query
(
$query
,
array
(
$id
));
}
$related
->
setReference
(
$record
,
$this
);
}
...
...
lib/Doctrine/Relation/LocalKey.php
View file @
a2046460
...
...
@@ -61,10 +61,10 @@ class Doctrine_Relation_LocalKey extends Doctrine_Relation
$id
=
$record
->
get
(
$this
->
definition
[
'local'
]);
if
(
empty
(
$id
))
{
$related
=
$this
->
definition
[
'table'
]
->
create
();
$related
=
$this
->
getTable
()
->
create
();
}
else
{
if
(
!
(
$related
=
$this
->
definition
[
'table'
]
->
find
(
$id
)))
{
$related
=
$this
->
definition
[
'table'
]
->
create
();
if
(
!
(
$related
=
$this
->
getTable
()
->
find
(
$id
)))
{
$related
=
$this
->
getTable
()
->
create
();
}
}
...
...
lib/Doctrine/Table.php
View file @
a2046460
...
...
@@ -172,7 +172,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* @throws Doctrine_Table_Exception if there is already an instance of this table
* @return void
*/
public
function
__construct
(
$name
,
Doctrine_Connection
$conn
)
public
function
__construct
(
$name
,
Doctrine_Connection
$conn
,
$allowExport
)
{
$this
->
conn
=
$conn
;
...
...
@@ -303,8 +303,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$record
->
setUp
();
// if tree, set up tree
if
(
$this
->
isTree
())
if
(
$this
->
isTree
())
{
$this
->
getTree
()
->
setUp
();
}
// save parents
array_pop
(
$names
);
...
...
@@ -312,10 +313,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$this
->
query
=
'SELECT '
.
implode
(
', '
,
array_keys
(
$this
->
columns
))
.
' FROM '
.
$this
->
getTableName
();
// check if an instance of this table is already initialized
if
(
!
$this
->
conn
->
addTable
(
$this
))
{
throw
new
Doctrine_Table_Exception
();
}
$this
->
repository
=
new
Doctrine_Table_Repository
(
$this
);
}
/**
...
...
@@ -360,6 +358,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$primary
[]
=
$name
;
}
}
/**
foreach ($this->getRelations() as $name => $relation) {
$fk = $relation->toArray();
$fk['foreignTable'] = $relation->getTable()->getTableName();
$options['foreignKeys'][] = $fk;
} */
$options
[
'primary'
]
=
$primary
;
$this
->
conn
->
export
->
createTable
(
$this
->
options
[
'tableName'
],
$columns
,
array_merge
(
$this
->
options
,
$options
));
...
...
@@ -675,15 +681,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
public
function
getBoundForName
(
$name
,
$component
)
{
foreach
(
$this
->
bound
as
$k
=>
$bound
)
{
$e
=
explode
(
'.'
,
$bound
[
'field'
]);
if
(
$bound
[
'
name
'
]
==
$name
&&
$e
[
0
]
==
$component
)
{
if
(
$bound
[
'
class
'
]
==
$name
&&
$e
[
0
]
==
$component
)
{
return
$this
->
bound
[
$k
];
}
}
throw
new
Doctrine_Table_Exception
(
'Unknown bound '
.
$name
);
throw
new
Doctrine_Table_Exception
(
'Unknown bound '
.
$name
);
}
/**
* returns the alias for given component name
...
...
@@ -751,7 +756,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* @param string $field
* @return void
*/
public
function
bind
(
$name
,
$field
,
$type
,
$
local
=
null
,
$options
=
array
()
)
public
function
bind
(
$name
,
$field
,
$type
,
$
options
=
null
)
{
if
(
isset
(
$this
->
relations
[
$name
]))
{
unset
(
$this
->
relations
[
$name
]);
...
...
@@ -775,10 +780,18 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$this
->
bound
[
$alias
]
=
array
(
'field'
=>
$field
,
'type'
=>
$type
,
'local'
=>
$local
,
'name'
=>
$name
,
'options'
=>
$options
,
'class'
=>
$name
,
'alias'
=>
$alias
);
if
(
$options
!==
null
)
{
$opt
=
array
();
if
(
is_string
(
$options
))
{
$opt
[
'local'
]
=
$options
;
}
else
{
$opt
=
(
array
)
$options
;
}
$this
->
bound
[
$alias
]
=
array_merge
(
$this
->
bound
[
$alias
],
$opt
);
}
}
/**
* @return Doctrine_Connection
...
...
@@ -829,7 +842,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
list
(
$component
,
$definition
[
'foreign'
])
=
explode
(
'.'
,
$definition
[
'field'
]);
unset
(
$definition
[
'field'
]);
$definition
[
'table'
]
=
$this
->
conn
->
getTable
(
$definition
[
'
name'
]
);
$definition
[
'table'
]
=
$this
->
conn
->
getTable
(
$definition
[
'
class'
],
false
);
if
(
$component
==
$this
->
options
[
'name'
]
||
in_array
(
$component
,
$this
->
options
[
'parents'
]))
{
...
...
@@ -850,14 +863,16 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if
(
!
isset
(
$definition
[
'local'
]))
{
$tmp
=
$definition
[
'table'
]
->
getIdentifier
();
$definition
[
'local'
]
=
$tmp
;
}
$definition
[
'local'
]
=
$tmp
;
//$definition['foreign'] = $tmp;
//$definition['foreign'] = $tmp;
$relation
=
new
Doctrine_Relation_ForeignKey
(
$definition
);
}
}
elseif
(
$component
==
$definition
[
'
name
'
]
||
}
elseif
(
$component
==
$definition
[
'
class
'
]
||
(
$component
==
$definition
[
'alias'
]))
{
// && ($name == $this->options['name'] || in_array($name,$this->parents))
if
(
!
isset
(
$defintion
[
'local'
]))
{
...
...
@@ -874,7 +889,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
throw
new
Doctrine_Table_Exception
(
"Only aggregate relations are allowed for many-to-many relations"
);
}
$classes
=
array_merge
(
$this
->
parents
,
array
(
$this
->
options
[
'name'
]));
$classes
=
array_merge
(
$this
->
options
[
'parents'
]
,
array
(
$this
->
options
[
'name'
]));
foreach
(
array_reverse
(
$classes
)
as
$class
)
{
try
{
...
...
@@ -895,7 +910,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if
(
$e2
[
0
]
!=
$component
)
{
throw
new
Doctrine_Table_Exception
(
$e2
[
0
]
.
' doesn\'t match '
.
$component
);
}
$associationTable
=
$this
->
conn
->
getTable
(
$e2
[
0
]);
$associationTable
=
$this
->
conn
->
getTable
(
$e2
[
0
]
,
false
);
if
(
count
(
$fields
)
>
1
)
{
// SELF-REFERENCING THROUGH JOIN TABLE
...
...
@@ -904,6 +919,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$def
[
'local'
]
=
$this
->
identifier
;
$def
[
'foreign'
]
=
$fields
[
0
];
$def
[
'alias'
]
=
$e2
[
0
];
$def
[
'class'
]
=
$e2
[
0
];
$def
[
'type'
]
=
Doctrine_Relation
::
MANY_COMPOSITE
;
$this
->
relations
[
$e2
[
0
]]
=
new
Doctrine_Relation_ForeignKey
(
$def
);
...
...
@@ -933,6 +949,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$def
[
'foreign'
]
=
$e2
[
1
];
$def
[
'local'
]
=
$definition
[
'local'
];
$def
[
'alias'
]
=
$e2
[
0
];
$def
[
'class'
]
=
$e2
[
0
];
$def
[
'type'
]
=
Doctrine_Relation
::
MANY_COMPOSITE
;
$this
->
relations
[
$e2
[
0
]]
=
new
Doctrine_Relation_ForeignKey
(
$def
);
...
...
@@ -966,7 +983,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
final
public
function
getRelations
()
{
$a
=
array
();
foreach
(
$this
->
bound
as
$k
=>
$v
)
{
foreach
(
$this
->
bound
as
$k
=>
$v
)
{
$this
->
getRelation
(
$k
);
}
...
...
lib/Doctrine/Validator.php
View file @
a2046460
...
...
@@ -109,6 +109,7 @@ class Doctrine_Validator
if
(
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_AUTO_LENGTH_VLD
))
{
if
(
!
$this
->
validateLength
(
$column
,
$key
,
$value
))
{
$errorStack
->
add
(
$key
,
'length'
);
continue
;
}
}
...
...
tests/BatchIteratorTestCase.php
View file @
a2046460
...
...
@@ -31,9 +31,8 @@
* @version $Revision$
*/
class
Doctrine_BatchIterator_TestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareTables
()
{
$this
->
tables
=
array
(
"Entity"
,
"User"
,
"Group"
,
"Address"
,
"Phonenumber"
);
$this
->
tables
=
array
(
"Entity"
,
"User"
,
"Group"
,
"Address"
,
"Email"
,
"Phonenumber"
);
parent
::
prepareTables
();
}
...
...
tests/ConnectionTestCase.php
View file @
a2046460
...
...
@@ -31,6 +31,7 @@
* @version $Revision$
*/
class
Doctrine_Connection_TestCase
extends
Doctrine_UnitTestCase
{
public
function
testUnknownModule
()
{
try
{
$this
->
connection
->
unknown
;
...
...
@@ -46,7 +47,7 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
$this
->
connection
->
transaction
instanceof
Doctrine_Transaction
);
$this
->
assertTrue
(
$this
->
connection
->
export
instanceof
Doctrine_Export
);
}
public
function
testFetchAll
()
{
public
function
testFetchAll
()
{
$this
->
conn
->
exec
(
'DROP TABLE entity'
);
$this
->
conn
->
exec
(
'CREATE TABLE entity (id INT, name TEXT)'
);
...
...
tests/EventListenerTestCase.php
View file @
a2046460
...
...
@@ -208,5 +208,6 @@ class Doctrine_EventListener_TestCase extends Doctrine_UnitTestCase {
$this
->
tables
=
array
(
'EventListenerTest'
);
parent
::
prepareTables
();
}
}
?>
tests/FilterTestCase.php
deleted
100644 → 0
View file @
94e5ce73
<?php
require_once
(
"UnitTestCase.php"
);
class
Doctrine_Filter_TestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareData
()
{
}
public
function
prepareTables
()
{
$this
->
tables
=
array
(
"FilterTest"
,
"FilterTest2"
);
}
public
function
testOperations
()
{
$t
=
new
FilterTest
;
}
}
?>
tests/RecordTestCase.php
View file @
a2046460
<?php
require_once
(
"UnitTestCase.php"
);
/*
* $Id$
*
* 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.com>.
*/
/**
* Doctrine_Record_TestCase
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class
Doctrine_Record_TestCase
extends
Doctrine_UnitTestCase
{
/**
public function prepareTables() {
$this->tables[] = "enumTest";
$this->tables[] = "fieldNameTest";
$this->tables[] = "GzipTest";
parent::prepareTables();
}
*/
public
function
testIssetForPrimaryKey
()
{
$this
->
assertTrue
(
isset
(
$this
->
users
[
0
]
->
id
));
$this
->
assertTrue
(
isset
(
$this
->
users
[
0
][
'id'
]));
...
...
@@ -21,9 +50,10 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$this
->
assertFalse
(
isset
(
$user
[
'id'
]));
$this
->
assertFalse
(
$user
->
contains
(
'id'
));
}
/**
public function testUnknownColumn() {
}
}
public function testNotNullConstraint() {
$null = new NotNullTest();
...
...
@@ -935,6 +965,6 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$user = $this->connection->getTable("User")->find(4);
$this->assertTrue($user->getIterator() instanceof ArrayIterator);
}
*/
}
?>
tests/UnitTestCase.php
View file @
a2046460
...
...
@@ -85,6 +85,8 @@ class Doctrine_UnitTestCase extends UnitTestCase {
try
{
$this
->
conn
=
$this
->
connection
=
$this
->
manager
->
getConnection
(
$this
->
driverName
);
$this
->
manager
->
setCurrentConnection
(
$this
->
driverName
);
$this
->
connection
->
evictTables
();
$this
->
dbh
=
$this
->
adapter
=
$this
->
connection
->
getDbh
();
$this
->
listener
=
$this
->
manager
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
);
...
...
@@ -110,7 +112,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this
->
listener
=
new
Doctrine_EventListener_Debugger
();
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_LISTENER
,
$this
->
listener
);
}
if
(
$this
->
driverName
!==
'main'
)
{
if
(
$this
->
driverName
!==
'main'
)
{
$this
->
export
=
$this
->
connection
->
export
;
$this
->
transaction
=
$this
->
connection
->
transaction
;
$this
->
dataDict
=
$this
->
connection
->
dataDict
;
...
...
@@ -121,9 +123,11 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this
->
unitOfWork
=
$this
->
connection
->
unitOfWork
;
$this
->
connection
->
setListener
(
new
Doctrine_EventListener
());
$this
->
query
=
new
Doctrine_Query
(
$this
->
connection
);
$this
->
prepareTables
();
$this
->
prepareData
();
if
(
$this
->
driverName
===
'main'
)
{
$this
->
prepareTables
();
$this
->
prepareData
();
}
$this
->
valueHolder
=
new
Doctrine_ValueHolder
(
$this
->
connection
->
getTable
(
'User'
));
}
...
...
@@ -208,9 +212,12 @@ class Doctrine_UnitTestCase extends UnitTestCase {
}
public
function
assertDeclarationType
(
$type
,
$type2
)
{
$dec
=
$this
->
getDeclaration
(
$type
);
if
(
!
is_array
(
$type2
))
if
(
!
is_array
(
$type2
))
{
$type2
=
array
(
$type2
);
$this
->
assertEqual
(
$dec
[
0
],
$type2
);
}
$this
->
assertEqual
(
$dec
[
'type'
],
$type2
);
}
public
function
getDeclaration
(
$type
)
{
return
$this
->
dataDict
->
getPortableDeclaration
(
array
(
'type'
=>
$type
,
'name'
=>
'colname'
,
'length'
=>
1
,
'fixed'
=>
true
));
...
...
tests/ValidatorTestCase.php
View file @
a2046460
...
...
@@ -197,6 +197,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
*/
public
function
testSave
()
{
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
true
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_AUTO_LENGTH_VLD
,
true
);
$user
=
$this
->
connection
->
getTable
(
"User"
)
->
find
(
4
);
try
{
$user
->
name
=
"this is an example of too long name not very good example but an example nevertheless"
;
...
...
@@ -212,7 +213,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
try
{
$user
=
$this
->
connection
->
create
(
"User"
);
$user
->
Email
->
address
=
"jackdaniels@drinkmore.info..."
;
$user
->
name
=
"this is an example of too long user name not very good example but an example nevertheles"
;
$user
->
name
=
"this is an example of too long user name not very good example but an example nevertheles
s
"
;
$user
->
save
();
$this
->
fail
();
}
catch
(
Doctrine_Validator_Exception
$e
)
{
...
...
@@ -228,6 +229,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
in_array
(
'email'
,
$emailStack
[
'address'
]));
$this
->
assertTrue
(
in_array
(
'length'
,
$userStack
[
'name'
]));
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
false
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_AUTO_LENGTH_VLD
,
false
);
}
/**
...
...
tests/run.php
View file @
a2046460
...
...
@@ -47,8 +47,9 @@ spl_autoload_register('autoload');
require_once
dirname
(
__FILE__
)
.
'/../models/location.php'
;
require_once
(
'classes.php'
);
require_once
(
'simpletest/unit_tester.php'
);
require_once
(
'simpletest/reporter.php'
);
require_once
dirname
(
__FILE__
)
.
'/../vendor/simpletest/unit_tester.php'
;
require_once
dirname
(
__FILE__
)
.
'/../vendor/simpletest/reporter.php'
;
require_once
(
'UnitTestCase.php'
);
require_once
(
'DriverTestCase.php'
);
...
...
@@ -60,7 +61,6 @@ $test = new GroupTest('Doctrine Framework Unit Tests');
// DATABASE ABSTRACTION tests
// Connection drivers (not yet fully tested)
...
...
@@ -102,8 +102,8 @@ $test->addTestCase(new Doctrine_Sequence_Pgsql_TestCase());
$test
->
addTestCase
(
new
Doctrine_Sequence_Oracle_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Sequence_Sqlite_TestCase
());
// Export module (not yet fully tested)
$test
->
addTestCase
(
new
Doctrine_Export_TestCase
());
//$test->addTestCase(new Doctrine_Export_Reporter_TestCase());
$test
->
addTestCase
(
new
Doctrine_Export_Firebird_TestCase
());
...
...
@@ -114,6 +114,7 @@ $test->addTestCase(new Doctrine_Export_Pgsql_TestCase());
$test
->
addTestCase
(
new
Doctrine_Export_Oracle_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Export_Sqlite_TestCase
());
// Import module (not yet fully tested)
//$test->addTestCase(new Doctrine_Import_TestCase());
$test
->
addTestCase
(
new
Doctrine_Import_Firebird_TestCase
());
...
...
@@ -139,6 +140,7 @@ $test->addTestCase(new Doctrine_Expression_Sqlite_TestCase());
$test
->
addTestCase
(
new
Doctrine_Access_TestCase
());
//$test->addTestCase(new Doctrine_Configurable_TestCase());
$test
->
addTestCase
(
new
Doctrine_Manager_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Connection_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Table_TestCase
());
...
...
@@ -147,15 +149,14 @@ $test->addTestCase(new Doctrine_UnitOfWork_TestCase());
$test
->
addTestCase
(
new
Doctrine_Connection_Transaction_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Collection_TestCase
());
// Relation handling
$test
->
addTestCase
(
new
Doctrine_TreeStructure_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Relation_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Relation_Access_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Relation_ManyToMany_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Relation_OneToOne_TestCase
());
$test
->
addTestCase
(
new
Doctrine_TreeStructure_TestCase
());
// Datatypes
$test
->
addTestCase
(
new
Doctrine_Enum_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Boolean_TestCase
());
...
...
@@ -164,9 +165,10 @@ $test->addTestCase(new Doctrine_Boolean_TestCase());
// Utility components
$test
->
addTestCase
(
new
Doctrine_Hook_TestCase
());
$test
->
addTestCase
(
new
Doctrine_PessimisticLocking_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Validator_TestCase
());
$test
->
addTestCase
(
new
Doctrine_RawSql_TestCase
());
$test
->
addTestCase
(
new
Doctrine_View_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Validator_TestCase
());
// Db component
...
...
@@ -174,27 +176,31 @@ $test->addTestCase(new Doctrine_Db_TestCase());
$test
->
addTestCase
(
new
Doctrine_Db_Profiler_TestCase
());
// Eventlisteners
$test
->
addTestCase
(
new
Doctrine_EventListener_TestCase
());
$test
->
addTestCase
(
new
Doctrine_EventListener_Chain_TestCase
());
// Record
$test
->
addTestCase
(
new
Doctrine_Record_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Record_State_TestCase
());
//$test->addTestCase(new Doctrine_Record_Filter_TestCase());
// Eventlisteners
$test
->
addTestCase
(
new
Doctrine_EventListener_TestCase
());
$test
->
addTestCase
(
new
Doctrine_EventListener_Chain_TestCase
());
// Old test cases (should be removed)
$test
->
addTestCase
(
new
Doctrine_SchemaTestCase
());
$test
->
addTestCase
(
new
Doctrine_BatchIterator_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Condition_TestCase
());
$test
->
addTestCase
(
new
Doctrine_CustomPrimaryKey_TestCase
());
$test
->
addTestCase
(
new
Doctrine_CustomResultSetOrderTestCase
());
$test
->
addTestCase
(
new
Doctrine_Filter_TestCase
());
//$test->addTestCase(new Doctrine_Collection_Offset_TestCase());
// Query tests
$test
->
addTestCase
(
new
Doctrine_Query_MultiJoin_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_ReferenceModel_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Condition_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_ComponentAlias_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_TestCase
());
...
...
@@ -208,11 +214,14 @@ $test->addTestCase(new Doctrine_Query_AggregateValue_TestCase());
$test
->
addTestCase
(
new
Doctrine_Query_Select_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Expression_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Having_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Join_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_From_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_JoinCondition_TestCase
());
$test
->
addTestCase
(
new
Doctrine_ColumnAlias_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Subquery_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Join_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Orderby_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Cache_TestCase
());
...
...
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