diff --git a/application/src/Domain/SourceManagement/TreeSourceService.php b/application/src/Domain/SourceManagement/TreeSourceService.php index c207170..28d5ee8 100644 --- a/application/src/Domain/SourceManagement/TreeSourceService.php +++ b/application/src/Domain/SourceManagement/TreeSourceService.php @@ -1,5 +1,4 @@ contains($branch)) { - $allBranches->add($branch); - foreach ((new self($branch))->getBranches() as $branchBranch) { + foreach ((new self($branch))->getBranches() as $branchBranch) { + if (!$allBranches->contains($branchBranch)) { $allBranches->add($branchBranch); + if($branchBranch instanceof TreeCollectionSourceInterface){ + $this->itterateOverBranch($branchBranch, $allBranches); + } } } } @@ -102,7 +106,7 @@ final class TreeSourceService extends AbstractSourceService implements TreeSourc $leaves = new ArrayCollection(); foreach ($this->getAllBranches()->toArray() as $branch) { foreach ((new self($branch))->getLeaves() as $leave) { - if (!$leaves->contains($leave)) { + if (! $leaves->contains($leave)) { $leaves->add($leave); } } diff --git a/application/tests/Unit/Domain/TreeSourceServiceTest.php b/application/tests/Unit/Domain/TreeSourceServiceTest.php index 2efc6e9..23d122d 100644 --- a/application/tests/Unit/Domain/TreeSourceServiceTest.php +++ b/application/tests/Unit/Domain/TreeSourceServiceTest.php @@ -22,8 +22,12 @@ class TreeSourceServiceTest extends TestCase $tree2 = new TreeCollectionSource(); $tree3 = new TreeCollectionSource(); $tree4 = new TreeCollectionSource(); + $tree5 = new TreeCollectionSource(); $leave1 = $this->createMock(SourceInterface::class); $leave2 = $this->createMock(SourceInterface::class); + $leave3 = $this->createMock(SourceInterface::class); + $leave4 = $this->createMock(SourceInterface::class); + $tree2->setCollection(new ArrayCollection([$leave3,$leave4,$tree5])); $collection = new ArrayCollection([$tree2,$tree3,$leave1,$leave2,$tree4]); $tree1->setCollection($collection); $this->treeService = new TreeSourceService($tree1); @@ -36,5 +40,13 @@ class TreeSourceServiceTest extends TestCase public function testGetBranches():void{ $this->assertEquals(3, $this->treeService->getBranches()->count()); } + + public function testGetAllBranches():void{ + $this->assertEquals(4, $this->treeService->getAllBranches()->count()); + } + + public function testGetAllLeaves():void{ + $this->assertEquals(4, $this->treeService->getAllLeaves()->count()); + } }