partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 57f4e5549f36b8cd007d7160e8ca6c50373f3de2
parent b6861e0a5cb359bdb07c1034f8849525452f6f3d
Author: Felicitus <felicitus@felicitus.de>
Date:   Wed, 22 Sep 2010 05:18:27 +0200

Updated doctrine2-nestedset
Diffstat:
M3rdparty/doctrine2-nestedset/lib/DoctrineExtensions/NestedSet/Manager.php | 18++++++++++++++++--
M3rdparty/doctrine2-nestedset/lib/DoctrineExtensions/NestedSet/NodeWrapper.php | 5+++++
M3rdparty/doctrine2-nestedset/tests/DoctrineExtensions/NestedSet/Tests/ManagerTest.php | 34++++++++++++++++++++++++++++++++++
M3rdparty/doctrine2-nestedset/tests/DoctrineExtensions/NestedSet/Tests/NodeWrapperTest.php | 10++++++++++
4 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/3rdparty/doctrine2-nestedset/lib/DoctrineExtensions/NestedSet/Manager.php b/3rdparty/doctrine2-nestedset/lib/DoctrineExtensions/NestedSet/Manager.php @@ -287,8 +287,8 @@ class Manager throw new \InvalidArgumentException('Can\'t wrap a NodeWrapper node'); } - $oid = spl_object_hash($node); - if(!isset($this->wrappers[$oid])) + $oid = spl_object_hash($node); + if(!isset($this->wrappers[$oid]) || $this->wrappers[$oid]->getNode() !== $node) { $this->wrappers[$oid] = new NodeWrapper($node, $this); } @@ -297,6 +297,13 @@ class Manager } + /** + * Resets the manager. Clears NodeWrapper caches. + */ + public function reset() + { + $this->wrappers = array(); + } /** @@ -519,6 +526,13 @@ class Manager } // @codeCoverageIgnoreEnd + // We are rebuilding the tree, so we invalidate all NodeWrappers + // in case they have cached children/metadata/etc. + foreach($wrappers as $wrapper) + { + $wrapper->invalidate(); + } + $config = $this->getConfiguration(); $rootNode = $wrappers[0]; diff --git a/3rdparty/doctrine2-nestedset/lib/DoctrineExtensions/NestedSet/NodeWrapper.php b/3rdparty/doctrine2-nestedset/lib/DoctrineExtensions/NestedSet/NodeWrapper.php @@ -172,6 +172,11 @@ class NodeWrapper implements Node */ public function getDescendants($depth = null) { + if(!$this->hasChildren()) + { + return array(); + } + if($this->descendants === null) { $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder(); diff --git a/3rdparty/doctrine2-nestedset/tests/DoctrineExtensions/NestedSet/Tests/ManagerTest.php b/3rdparty/doctrine2-nestedset/tests/DoctrineExtensions/NestedSet/Tests/ManagerTest.php @@ -307,6 +307,24 @@ class ManagerTest extends DatabaseTest /** + * @covers DoctrineExtensions\NestedSet\Manager::fetchTree + * @covers DoctrineExtensions\NestedSet\Manager::fetchTreeAsArray + * @covers DoctrineExtensions\NestedSet\Manager::buildTree + */ + public function testFetchTreeDuplicate() + { + $this->loadData(); + $nodes = $this->nodes; + + $root1 = $this->nsm->fetchTree(1); + $this->assertEquals(2, count($root1->getChildren()), '1st root has correct number of children'); + + $root2 = $this->nsm->fetchTree(1); + $this->assertEquals(2, count($root2->getChildren()), '1st root has correct number of children after 2nd fetchTree()'); + } + + + /** * @covers DoctrineExtensions\NestedSet\Manager::createRoot */ public function testCreateRoot() @@ -372,6 +390,22 @@ class ManagerTest extends DatabaseTest /** + * @covers DoctrineExtensions\NestedSet\Manager::reset + */ + public function testReset() + { + $node = new NodeMock(1, '1'); + $wrapper1 = $this->nsm->wrapNode($node); + $wrapper2 = $this->nsm->wrapNode($node); + $this->assertSame($wrapper1, $wrapper2, '->wrapNode() returns cached NodeWrapper instance'); + + $this->nsm->reset(); + $wrapper3 = $this->nsm->wrapNode($node); + $this->assertNotSame($wrapper1, $wrapper3, '->reset() clears NodeWrapper cache'); + } + + + /** * @covers DoctrineExtensions\NestedSet\Manager::getEntityManager */ public function testGetEntityManager() diff --git a/3rdparty/doctrine2-nestedset/tests/DoctrineExtensions/NestedSet/Tests/NodeWrapperTest.php b/3rdparty/doctrine2-nestedset/tests/DoctrineExtensions/NestedSet/Tests/NodeWrapperTest.php @@ -325,6 +325,16 @@ class NodeWrapperTest extends DatabaseTest /** + * @covers DoctrineExtensions\NestedSet\NodeWrapper::getDescendants + */ + public function testGetDescendants_None() + { + $d = $this->wrappers[2]->getDescendants(); + $this->assertEmpty($d, '->getDescendants() works with no children'); + } + + + /** * @covers DoctrineExtensions\NestedSet\NodeWrapper::getPrevSibling */ public function testGetPrevSibling_UnloadedTree()