From 0d0fa68094c17d623ed24d0311f4881db852ac7e Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 18 Nov 2018 11:34:38 +0100 Subject: [PATCH] Solved Unit tests --- .../src/Domain/SourceManagement/TreeSourceService.php | 7 +++---- application/tests/Unit/Domain/TreeSourceServiceTest.php | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/application/src/Domain/SourceManagement/TreeSourceService.php b/application/src/Domain/SourceManagement/TreeSourceService.php index 28d5ee8..8b2460e 100644 --- a/application/src/Domain/SourceManagement/TreeSourceService.php +++ b/application/src/Domain/SourceManagement/TreeSourceService.php @@ -103,15 +103,14 @@ final class TreeSourceService extends AbstractSourceService implements TreeSourc public function getAllLeaves(): Collection { - $leaves = new ArrayCollection(); - foreach ($this->getAllBranches()->toArray() as $branch) { - foreach ((new self($branch))->getLeaves() as $leave) { + $leaves = new ArrayCollection($this->getLeaves()->toArray()); + foreach ($this->getAllBranches() as $branch) { + foreach ((new self($branch))->getAllLeaves() as $leave) { if (! $leaves->contains($leave)) { $leaves->add($leave); } } } - return $leaves; } } diff --git a/application/tests/Unit/Domain/TreeSourceServiceTest.php b/application/tests/Unit/Domain/TreeSourceServiceTest.php index 23d122d..c79f08f 100644 --- a/application/tests/Unit/Domain/TreeSourceServiceTest.php +++ b/application/tests/Unit/Domain/TreeSourceServiceTest.php @@ -27,7 +27,8 @@ class TreeSourceServiceTest extends TestCase $leave2 = $this->createMock(SourceInterface::class); $leave3 = $this->createMock(SourceInterface::class); $leave4 = $this->createMock(SourceInterface::class); - $tree2->setCollection(new ArrayCollection([$leave3,$leave4,$tree5])); + $leave5 = $this->createMock(SourceInterface::class); + $tree2->setCollection(new ArrayCollection([$leave3,$leave4,$tree5,$leave5])); $collection = new ArrayCollection([$tree2,$tree3,$leave1,$leave2,$tree4]); $tree1->setCollection($collection); $this->treeService = new TreeSourceService($tree1); @@ -46,7 +47,7 @@ class TreeSourceServiceTest extends TestCase } public function testGetAllLeaves():void{ - $this->assertEquals(4, $this->treeService->getAllLeaves()->count()); + $this->assertEquals(5, $this->treeService->getAllLeaves()->count()); } }