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
ececdadf
Commit
ececdadf
authored
Jan 03, 2007
by
david
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a test for a self-referential tree structure using only one table
parent
08d638ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
0 deletions
+73
-0
TreeStructureTestCase.php
tests/TreeStructureTestCase.php
+72
-0
run.php
tests/run.php
+1
-0
No files found.
tests/TreeStructureTestCase.php
0 → 100644
View file @
ececdadf
<?php
class
TreeLeaf
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'parent_id'
,
'integer'
);
$this
->
hasOne
(
'TreeLeaf as Parent'
,
'TreeLeaf.parent_id'
,
'id'
);
$this
->
hasMany
(
'TreeLeaf as Children'
,
'TreeLeaf.parent_id'
);
}
}
class
Doctrine_TreeStructure_TestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareTables
()
{
}
/* we don't need the standard tables here */
public
function
prepareData
()
{
}
/* we don't need the standard data here */
public
function
testSelfReferentialRelationship
()
{
$component
=
new
TreeLeaf
();
try
{
$rel
=
$component
->
getTable
()
->
getRelation
(
'Parent'
);
$rel
=
$component
->
getTable
()
->
getRelation
(
'Children'
);
$this
->
pass
();
}
catch
(
Doctrine_Exception
$e
)
{
$this
->
fail
();
}
}
public
function
testTreeLeafRelationships
()
{
/* structure:
*
* o1
* -> o2
* -> o3
*
* o4
*
* thus it would be expected that o1 has 2 children and o4 is a
* leaf with no parents or children.
*/
$o1
=
new
TreeLeaf
();
$o1
->
Parent
=
null
;
$o1
->
save
();
$o2
=
new
TreeLeaf
();
$o2
->
Parent
=
$o1
;
$o2
->
save
();
$o3
=
new
TreeLeaf
();
$o3
->
Parent
=
$o1
;
$o3
->
save
();
$o1
->
refresh
();
$o4
=
new
TreeLeaf
();
$o4
->
save
();
$this
->
assertFalse
(
isset
(
$o1
->
Parent
));
$this
->
assertTrue
(
count
(
$o1
->
Children
)
==
2
);
$this
->
assertTrue
(
count
(
$o1
->
get
(
'Children'
))
==
2
);
$this
->
assertTrue
(
isset
(
$o2
->
Parent
));
$this
->
assertTrue
(
$o2
->
Parent
==
$o1
);
$this
->
assertTrue
(
count
(
$o4
->
Children
)
==
0
);
$this
->
assertFalse
(
isset
(
$o4
->
Parent
));
}
}
tests/run.php
View file @
ececdadf
...
...
@@ -136,6 +136,7 @@ $test->addTestCase(new Doctrine_Collection_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_TreeStructure_TestCase
());
// Datatypes
...
...
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