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
f92773fa
Commit
f92773fa
authored
May 06, 2008
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added another hydration test.
parent
ab65ad5b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
182 additions
and
2 deletions
+182
-2
Record.php
lib/Doctrine/Record.php
+1
-1
ClassMetadataTestCase.php
tests/Orm/ClassMetadataTestCase.php
+18
-0
BasicHydrationTest.php
tests/Orm/Hydration/BasicHydrationTest.php
+150
-1
CmsArticle.php
tests/models/cms/CmsArticle.php
+11
-0
CmsUser.php
tests/models/cms/CmsUser.php
+2
-0
No files found.
lib/Doctrine/Record.php
View file @
f92773fa
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
* @link www.phpdoctrine.org
* @link www.phpdoctrine.org
* @since 1.0
* @since 1.0
* @version $Revision$
* @version $Revision$
* @todo Rename to "Entity". Split up into "Entity" and "Active
Record
(extends Entity)"???
* @todo Rename to "Entity". Split up into "Entity" and "Active
Entity
(extends Entity)"???
* @todo Remove as many methods as possible.
* @todo Remove as many methods as possible.
*/
*/
abstract
class
Doctrine_Record
extends
Doctrine_Access
implements
Countable
,
IteratorAggregate
,
Serializable
abstract
class
Doctrine_Record
extends
Doctrine_Access
implements
Countable
,
IteratorAggregate
,
Serializable
...
...
tests/Orm/ClassMetadataTestCase.php
0 → 100644
View file @
f92773fa
<?php
require_once
'lib/DoctrineTestInit.php'
;
class
Orm_ClassMetadataTestCase
extends
Doctrine_OrmTestCase
{
protected
function
setUp
()
{
;
}
protected
function
tearDown
()
{
;
}
public
function
testTransientEntityIsManaged
()
{
;
}
}
\ No newline at end of file
tests/Orm/Hydration/BasicHydrationTest.php
View file @
f92773fa
...
@@ -358,7 +358,156 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase
...
@@ -358,7 +358,156 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase
}
}
/**
* select u.id, u.status, p.phonenumber, upper(u.name) nameUpper, a.id, a.topic
* from User u
* join u.phonenumbers p
* join u.articles a
* =
* select u.id, u.status, p.phonenumber, upper(u.name) as u__0, a.id, a.topic
* from USERS u
* inner join PHONENUMBERS p ON u.id = p.user_id
* inner join ARTICLES a ON u.id = a.user_id
*
* @dataProvider hydrationModeProvider
*/
public
function
testNewHydrationMixedQueryMultipleFetchJoin
(
$hydrationMode
)
{
// Faked query components
$queryComponents
=
array
(
'u'
=>
array
(
'table'
=>
$this
->
sharedFixture
[
'connection'
]
->
getClassMetadata
(
'CmsUser'
),
'mapper'
=>
$this
->
sharedFixture
[
'connection'
]
->
getMapper
(
'CmsUser'
),
'parent'
=>
null
,
'relation'
=>
null
,
'map'
=>
null
,
'agg'
=>
array
(
'0'
=>
'nameUpper'
)
),
'p'
=>
array
(
'table'
=>
$this
->
sharedFixture
[
'connection'
]
->
getClassMetadata
(
'CmsPhonenumber'
),
'mapper'
=>
$this
->
sharedFixture
[
'connection'
]
->
getMapper
(
'CmsPhonenumber'
),
'parent'
=>
'u'
,
'relation'
=>
$this
->
sharedFixture
[
'connection'
]
->
getClassMetadata
(
'CmsUser'
)
->
getRelation
(
'phonenumbers'
),
'map'
=>
null
),
'a'
=>
array
(
'table'
=>
$this
->
sharedFixture
[
'connection'
]
->
getClassMetadata
(
'CmsArticle'
),
'mapper'
=>
$this
->
sharedFixture
[
'connection'
]
->
getMapper
(
'CmsArticle'
),
'parent'
=>
'u'
,
'relation'
=>
$this
->
sharedFixture
[
'connection'
]
->
getClassMetadata
(
'CmsUser'
)
->
getRelation
(
'articles'
),
'map'
=>
null
),
);
// Faked table alias map
$tableAliasMap
=
array
(
'u'
=>
'u'
,
'p'
=>
'p'
,
'a'
=>
'a'
);
// Faked result set
$resultSet
=
array
(
//row1
array
(
'u__id'
=>
'1'
,
'u__status'
=>
'developer'
,
'u__0'
=>
'ROMANB'
,
'p__phonenumber'
=>
'42'
,
'a__id'
=>
'1'
,
'a__topic'
=>
'Getting things done!'
),
array
(
'u__id'
=>
'1'
,
'u__status'
=>
'developer'
,
'u__0'
=>
'ROMANB'
,
'p__phonenumber'
=>
'43'
,
'a__id'
=>
'1'
,
'a__topic'
=>
'Getting things done!'
),
array
(
'u__id'
=>
'1'
,
'u__status'
=>
'developer'
,
'u__0'
=>
'ROMANB'
,
'p__phonenumber'
=>
'42'
,
'a__id'
=>
'2'
,
'a__topic'
=>
'ZendCon'
),
array
(
'u__id'
=>
'1'
,
'u__status'
=>
'developer'
,
'u__0'
=>
'ROMANB'
,
'p__phonenumber'
=>
'43'
,
'a__id'
=>
'2'
,
'a__topic'
=>
'ZendCon'
),
array
(
'u__id'
=>
'2'
,
'u__status'
=>
'developer'
,
'u__0'
=>
'JWAGE'
,
'p__phonenumber'
=>
'91'
,
'a__id'
=>
'3'
,
'a__topic'
=>
'LINQ'
),
array
(
'u__id'
=>
'2'
,
'u__status'
=>
'developer'
,
'u__0'
=>
'JWAGE'
,
'p__phonenumber'
=>
'91'
,
'a__id'
=>
'4'
,
'a__topic'
=>
'PHP6'
),
);
$stmt
=
new
Doctrine_HydratorMockStatement
(
$resultSet
);
$hydrator
=
new
Doctrine_HydratorNew
();
$hydrator
->
setQueryComponents
(
$queryComponents
);
$hydrator
->
setResultMixed
(
true
);
$result
=
$hydrator
->
hydrateResultSet
(
$stmt
,
$tableAliasMap
,
$hydrationMode
);
if
(
$hydrationMode
==
Doctrine
::
HYDRATE_ARRAY
)
{
//var_dump($result);
}
$this
->
assertEquals
(
2
,
count
(
$result
));
$this
->
assertTrue
(
is_array
(
$result
));
$this
->
assertTrue
(
is_array
(
$result
[
0
]));
$this
->
assertTrue
(
is_array
(
$result
[
1
]));
// first user => 2 phonenumbers, 2 articles
$this
->
assertEquals
(
2
,
count
(
$result
[
0
][
0
][
'phonenumbers'
]));
$this
->
assertEquals
(
2
,
count
(
$result
[
0
][
0
][
'articles'
]));
$this
->
assertEquals
(
'ROMANB'
,
$result
[
0
][
'nameUpper'
]);
// second user => 1 phonenumber, 2 articles
$this
->
assertEquals
(
1
,
count
(
$result
[
1
][
0
][
'phonenumbers'
]));
$this
->
assertEquals
(
2
,
count
(
$result
[
1
][
0
][
'articles'
]));
$this
->
assertEquals
(
'JWAGE'
,
$result
[
1
][
'nameUpper'
]);
$this
->
assertEquals
(
42
,
$result
[
0
][
0
][
'phonenumbers'
][
0
][
'phonenumber'
]);
$this
->
assertEquals
(
43
,
$result
[
0
][
0
][
'phonenumbers'
][
1
][
'phonenumber'
]);
$this
->
assertEquals
(
91
,
$result
[
1
][
0
][
'phonenumbers'
][
0
][
'phonenumber'
]);
$this
->
assertEquals
(
'Getting things done!'
,
$result
[
0
][
0
][
'articles'
][
0
][
'topic'
]);
$this
->
assertEquals
(
'ZendCon'
,
$result
[
0
][
0
][
'articles'
][
1
][
'topic'
]);
$this
->
assertEquals
(
'LINQ'
,
$result
[
1
][
0
][
'articles'
][
0
][
'topic'
]);
$this
->
assertEquals
(
'PHP6'
,
$result
[
1
][
0
][
'articles'
][
1
][
'topic'
]);
if
(
$hydrationMode
==
Doctrine
::
HYDRATE_RECORD
)
{
$this
->
assertTrue
(
$result
[
0
][
0
]
instanceof
Doctrine_Record
);
$this
->
assertTrue
(
$result
[
0
][
0
][
'phonenumbers'
]
instanceof
Doctrine_Collection
);
$this
->
assertTrue
(
$result
[
0
][
0
][
'phonenumbers'
][
0
]
instanceof
Doctrine_Record
);
$this
->
assertTrue
(
$result
[
0
][
0
][
'phonenumbers'
][
1
]
instanceof
Doctrine_Record
);
$this
->
assertTrue
(
$result
[
0
][
0
][
'articles'
]
instanceof
Doctrine_Collection
);
$this
->
assertTrue
(
$result
[
0
][
0
][
'articles'
][
0
]
instanceof
Doctrine_Record
);
$this
->
assertTrue
(
$result
[
0
][
0
][
'articles'
][
1
]
instanceof
Doctrine_Record
);
$this
->
assertTrue
(
$result
[
1
][
0
]
instanceof
Doctrine_Record
);
$this
->
assertTrue
(
$result
[
1
][
0
][
'phonenumbers'
]
instanceof
Doctrine_Collection
);
$this
->
assertTrue
(
$result
[
1
][
0
][
'phonenumbers'
][
0
]
instanceof
Doctrine_Record
);
$this
->
assertTrue
(
$result
[
1
][
0
][
'articles'
][
0
]
instanceof
Doctrine_Record
);
$this
->
assertTrue
(
$result
[
1
][
0
][
'articles'
][
1
]
instanceof
Doctrine_Record
);
}
}
...
...
tests/models/cms/CmsArticle.php
0 → 100644
View file @
f92773fa
<?php
class
CmsArticle
extends
Doctrine_Record
{
public
static
function
initMetadata
(
$class
)
{
$class
->
mapColumn
(
'id'
,
'integer'
,
4
,
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
));
$class
->
mapColumn
(
'topic'
,
'string'
,
255
);
$class
->
mapColumn
(
'text'
,
'string'
);
$class
->
mapColumn
(
'user_id'
,
'integer'
,
4
);
}
}
tests/models/cms/CmsUser.php
View file @
f92773fa
...
@@ -9,5 +9,7 @@ class CmsUser extends Doctrine_Record
...
@@ -9,5 +9,7 @@ class CmsUser extends Doctrine_Record
$class
->
hasMany
(
'CmsPhonenumber as phonenumbers'
,
array
(
$class
->
hasMany
(
'CmsPhonenumber as phonenumbers'
,
array
(
'local'
=>
'id'
,
'foreign'
=>
'user_id'
));
'local'
=>
'id'
,
'foreign'
=>
'user_id'
));
$class
->
hasMany
(
'CmsArticle as articles'
,
array
(
'local'
=>
'id'
,
'foreign'
=>
'user_id'
));
}
}
}
}
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