mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Solved branch test
This commit is contained in:
parent
c5adb81d5d
commit
00c6ba1f9d
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Domain\SourceManagement;
|
namespace App\Domain\SourceManagement;
|
||||||
|
|
||||||
use App\Entity\Source\Collection\TreeCollectionSourceInterface;
|
use App\Entity\Source\Collection\TreeCollectionSourceInterface;
|
||||||
@ -12,12 +11,14 @@ use App\Entity\Source\SourceInterface;
|
|||||||
* Allows to iterate over a tree.
|
* Allows to iterate over a tree.
|
||||||
*
|
*
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*
|
*
|
||||||
* @todo Maybe lazy loading would be helpfull for performance
|
* @todo Maybe lazy loading would be helpfull for performance
|
||||||
*/
|
*/
|
||||||
final class TreeSourceService extends AbstractSourceService implements TreeSourceServiceInterface
|
final class TreeSourceService extends AbstractSourceService implements TreeSourceServiceInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @var TreeCollectionSourceInterface
|
* @var TreeCollectionSourceInterface
|
||||||
*/
|
*/
|
||||||
private $source;
|
private $source;
|
||||||
@ -66,6 +67,7 @@ final class TreeSourceService extends AbstractSourceService implements TreeSourc
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @todo Remove the optional parameter and put the logic in a private funtion.
|
* @todo Remove the optional parameter and put the logic in a private funtion.
|
||||||
* @todo Remove the getAllBranches use inside the function.
|
* @todo Remove the getAllBranches use inside the function.
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@ -84,10 +86,12 @@ final class TreeSourceService extends AbstractSourceService implements TreeSourc
|
|||||||
|
|
||||||
private function itterateOverBranch(TreeCollectionSourceInterface $branch, ArrayCollection $allBranches): void
|
private function itterateOverBranch(TreeCollectionSourceInterface $branch, ArrayCollection $allBranches): void
|
||||||
{
|
{
|
||||||
if (!$allBranches->contains($branch)) {
|
foreach ((new self($branch))->getBranches() as $branchBranch) {
|
||||||
$allBranches->add($branch);
|
if (!$allBranches->contains($branchBranch)) {
|
||||||
foreach ((new self($branch))->getBranches() as $branchBranch) {
|
|
||||||
$allBranches->add($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();
|
$leaves = new ArrayCollection();
|
||||||
foreach ($this->getAllBranches()->toArray() as $branch) {
|
foreach ($this->getAllBranches()->toArray() as $branch) {
|
||||||
foreach ((new self($branch))->getLeaves() as $leave) {
|
foreach ((new self($branch))->getLeaves() as $leave) {
|
||||||
if (!$leaves->contains($leave)) {
|
if (! $leaves->contains($leave)) {
|
||||||
$leaves->add($leave);
|
$leaves->add($leave);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,12 @@ class TreeSourceServiceTest extends TestCase
|
|||||||
$tree2 = new TreeCollectionSource();
|
$tree2 = new TreeCollectionSource();
|
||||||
$tree3 = new TreeCollectionSource();
|
$tree3 = new TreeCollectionSource();
|
||||||
$tree4 = new TreeCollectionSource();
|
$tree4 = new TreeCollectionSource();
|
||||||
|
$tree5 = new TreeCollectionSource();
|
||||||
$leave1 = $this->createMock(SourceInterface::class);
|
$leave1 = $this->createMock(SourceInterface::class);
|
||||||
$leave2 = $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]);
|
$collection = new ArrayCollection([$tree2,$tree3,$leave1,$leave2,$tree4]);
|
||||||
$tree1->setCollection($collection);
|
$tree1->setCollection($collection);
|
||||||
$this->treeService = new TreeSourceService($tree1);
|
$this->treeService = new TreeSourceService($tree1);
|
||||||
@ -36,5 +40,13 @@ class TreeSourceServiceTest extends TestCase
|
|||||||
public function testGetBranches():void{
|
public function testGetBranches():void{
|
||||||
$this->assertEquals(3, $this->treeService->getBranches()->count());
|
$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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user