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
a20ceff3
Commit
a20ceff3
authored
Oct 05, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests and implementation for hydrate hooks
parent
2c7ced23
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
48 deletions
+68
-48
Event.php
lib/Doctrine/Event.php
+17
-1
Hydrate.php
lib/Doctrine/Hydrate.php
+18
-3
HydrateTestCase.php
tests/HydrateTestCase.php
+32
-43
run.php
tests/run.php
+1
-1
No files found.
lib/Doctrine/Event.php
View file @
a20ceff3
...
...
@@ -52,6 +52,8 @@ class Doctrine_Event
const
SAVEPOINT_ROLLBACK
=
35
;
const
SAVEPOINT_COMMIT
=
36
;
const
HYDRATE
=
40
;
/*
* RECORD EVENT CODES
*/
...
...
@@ -155,7 +157,7 @@ class Doctrine_Event
case
self
::
SAVEPOINT_ROLLBACK
:
return
'rollback savepoint'
;
case
self
::
SAVEPOINT_COMMIT
:
return
'commit
S
savepoint'
;
return
'commit savepoint'
;
case
self
::
RECORD_DELETE
:
return
'delete record'
;
...
...
@@ -222,6 +224,20 @@ class Doctrine_Event
return
$this
;
}
/**
* setOption
* sets the value of an option by reference
*
* @param string $option the name of the option
* @param mixed $value the value of the given option
* @return Doctrine_Event this object
*/
public
function
set
(
$option
,
&
$value
)
{
$this
->
_options
[
$option
]
=&
$value
;
return
$this
;
}
/**
* start
* starts the internal timer of this event
...
...
lib/Doctrine/Hydrate.php
View file @
a20ceff3
...
...
@@ -777,8 +777,10 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
*/
public
function
execute
(
$params
=
array
(),
$hydrationMode
=
null
)
{
$params
=
array_merge
(
$this
->
_params
[
'set'
],
$this
->
_params
[
'where'
],
$this
->
_params
[
'having'
],
$params
);
$params
=
array_merge
(
$this
->
_params
[
'set'
],
$this
->
_params
[
'where'
],
$this
->
_params
[
'having'
],
$params
);
if
(
$this
->
_cache
)
{
$cacheDriver
=
$this
->
getCacheDriver
();
...
...
@@ -984,6 +986,8 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
return
$array
;
}
$event
=
new
Doctrine_Event
(
Doctrine_Event
::
HYDRATE
,
null
);
while
(
$data
=
$stmt
->
fetch
(
Doctrine
::
FETCH_ASSOC
))
{
$currData
=
array
();
$identifiable
=
array
();
...
...
@@ -1028,12 +1032,17 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
// dealing with root component
$table
=
$this
->
_aliasMap
[
$rootAlias
][
'table'
];
$componentName
=
$table
->
getComponentName
();
$event
->
set
(
'data'
,
$currData
[
$rootAlias
]);
$table
->
getListener
()
->
preHydrate
(
$event
);
$element
=
$driver
->
getElement
(
$currData
[
$rootAlias
],
$componentName
);
$oneToOne
=
false
;
$index
=
$driver
->
search
(
$element
,
$array
);
if
(
$index
===
false
)
{
if
(
$index
===
false
)
{
$event
->
set
(
'data'
,
$element
);
$table
->
getListener
()
->
postHydrate
(
$event
);
if
(
isset
(
$this
->
_aliasMap
[
$rootAlias
][
'map'
]))
{
$key
=
$this
->
_aliasMap
[
$rootAlias
][
'map'
];
...
...
@@ -1058,6 +1067,9 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
$map
=
$this
->
_aliasMap
[
$alias
];
$table
=
$this
->
_aliasMap
[
$alias
][
'table'
];
$componentName
=
$table
->
getComponentName
();
$event
->
set
(
'data'
,
$data
);
$table
->
getListener
()
->
preHydrate
(
$event
);
$element
=
$driver
->
getElement
(
$data
,
$componentName
);
$parent
=
$map
[
'parent'
];
...
...
@@ -1079,6 +1091,9 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
$index
=
$driver
->
search
(
$element
,
$prev
[
$parent
][
$componentAlias
]);
if
(
$index
===
false
)
{
$event
->
set
(
'data'
,
$element
);
$table
->
getListener
()
->
postHydrate
(
$event
);
if
(
isset
(
$map
[
'map'
]))
{
$key
=
$map
[
'map'
];
if
(
isset
(
$prev
[
$parent
][
$componentAlias
][
$key
]))
{
...
...
tests/HydrateTestCase.php
View file @
a20ceff3
...
...
@@ -54,54 +54,40 @@ class Doctrine_Hydrate_TestCase extends Doctrine_UnitTestCase
'p'
=>
array
(
'id'
=>
null
,
'phonenumber'
=>
null
,
'user_id'
=>
null
)
)
);
public
function
prepareData
()
{
}
public
function
test
ExecuteForEmptyAliasMapThrowsException
()
public
function
test
HydrateHooks
()
{
$h
=
new
Doctrine_Hydrate_Mock
();
try
{
$h
->
execute
();
$this
->
fail
(
'Should throw exception'
);
}
catch
(
Doctrine_Hydrate_Exception
$e
)
{
$this
->
pass
();
}
$user
=
new
User
();
$user
->
getTable
()
->
addListener
(
new
HydrationListener
);
$user
->
name
=
'zYne'
;
$user
->
save
();
$this
->
conn
->
clear
();
$user
=
Doctrine_Query
::
create
()
->
from
(
'User u'
)
->
fetchOne
();
$this
->
assertEqual
(
$user
->
name
,
'ZYNE'
);
$this
->
assertEqual
(
$user
->
password
,
'DEFAULT PASS'
);
}
public
function
testExecuteForEmptyTableAliasMapThrowsException
()
}
class
HydrationListener
extends
Doctrine_EventListener
{
public
function
preHydrate
(
Doctrine_Event
$event
)
{
$h
=
new
Doctrine_Hydrate_Mock
();
$h
->
setData
(
$this
->
testData1
);
$h
->
setAliasMap
(
array
(
'u'
=>
array
(
'table'
=>
$this
->
conn
->
getTable
(
'User'
))));
try
{
$h
->
execute
();
$this
->
fail
(
'Should throw exception'
);
}
catch
(
Doctrine_Hydrate_Exception
$e
)
{
$this
->
pass
();
}
$data
=
$event
->
data
;
$data
[
'password'
]
=
'default pass'
;
$event
->
data
=
$data
;
}
/**
public function testHydrate()
public
function
postHydrate
(
Doctrine_Event
$event
)
{
$h = new Doctrine_Hydrate_Mock();
$h->setData($this->testData1);
$h->setAliasMap(array('u' => array('table' => $this->conn->getTable('User')),
'p' => array('table' => $this->conn->getTable('Phonenumber'),
'parent' => 'u',
'relation' => $this->conn->getTable('User')->getRelation('Phonenumber')))
);
$h->setTableAliases(array('e' => 'u', 'p' => 'p'));
$coll = $h->execute();
$this->assertTrue($coll instanceof Doctrine_Collection2, 'instance of Doctrine_Collection expected');
$this->assertEqual($coll->count(), 4);
$count = count($this->dbh);
$this->assertEqual($coll[0]->Phonenumber->count(), 1);
$this->assertEqual($coll[1]->Phonenumber->count(), 2);
$this->assertEqual($coll[2]->Phonenumber->count(), 1);
$this->assertEqual($coll[3]->Phonenumber->count(), 0);
$this->assertEqual(count($this->dbh), $count);
foreach
(
$event
->
data
as
$key
=>
$value
)
{
$event
->
data
[
$key
]
=
strtoupper
(
$value
);
}
}
*/
}
class
Doctrine_Hydrate_Mock
extends
Doctrine_Hydrate
{
...
...
@@ -111,8 +97,11 @@ class Doctrine_Hydrate_Mock extends Doctrine_Hydrate
{
$this
->
data
=
$data
;
}
public
function
_fetch
(
$params
=
array
(),
$return
=
Doctrine
::
FETCH_RECORD
)
public
function
getQuery
()
{
}
public
function
execute
(
$params
=
array
(),
$hydrationMode
=
null
)
{
return
$this
->
data
;
}
...
...
tests/run.php
View file @
a20ceff3
...
...
@@ -197,7 +197,7 @@ $core->addTestCase(new Doctrine_Hydrate_FetchMode_TestCase());
$core
->
addTestCase
(
new
Doctrine_Tokenizer_TestCase
());
//$core->addTestCase(new Doctrine_Collection_Offset_TestCase());
//$core->addTestCase(new Doctrine_BatchIterator_TestCase());
//
$core->addTestCase(new Doctrine_Hydrate_TestCase());
$core
->
addTestCase
(
new
Doctrine_Hydrate_TestCase
());
$test
->
addTestCase
(
$core
);
// Relation handling
...
...
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