2018-11-18 10:50:18 +01:00
|
|
|
<?php
|
2018-11-18 11:41:24 +01:00
|
|
|
|
2019-05-30 17:04:46 +02:00
|
|
|
namespace Tests\Unit\Domain\Source;
|
2018-11-18 10:50:18 +01:00
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Entity\Source\Complex\Collection\TreeCollectionSource;
|
|
|
|
use Infinito\Entity\Source\SourceInterface;
|
2018-11-18 10:50:18 +01:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2019-05-30 17:04:46 +02:00
|
|
|
use Infinito\Domain\Source\TreeSourceInformationInterface;
|
|
|
|
use Infinito\Domain\Source\TreeSourceInformation;
|
2018-11-18 10:50:18 +01:00
|
|
|
|
2019-01-19 22:52:49 +01:00
|
|
|
class TreeSourceInformationTest extends TestCase
|
2018-11-18 10:50:18 +01:00
|
|
|
{
|
|
|
|
/**
|
2019-01-19 22:52:49 +01:00
|
|
|
* @var TreeSourceInformationInterface
|
2018-11-18 10:50:18 +01:00
|
|
|
*/
|
|
|
|
protected $treeService;
|
2018-11-18 11:41:24 +01:00
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
2018-11-18 10:50:18 +01:00
|
|
|
$tree1 = new TreeCollectionSource();
|
|
|
|
$tree2 = new TreeCollectionSource();
|
|
|
|
$tree3 = new TreeCollectionSource();
|
2018-11-18 10:53:48 +01:00
|
|
|
$tree4 = new TreeCollectionSource();
|
2018-11-18 11:47:26 +01:00
|
|
|
$tree5 = new TreeCollectionSource(new ArrayCollection([$tree2]));
|
2018-11-18 10:50:18 +01:00
|
|
|
$leave1 = $this->createMock(SourceInterface::class);
|
|
|
|
$leave2 = $this->createMock(SourceInterface::class);
|
2018-11-18 11:13:36 +01:00
|
|
|
$leave3 = $this->createMock(SourceInterface::class);
|
|
|
|
$leave4 = $this->createMock(SourceInterface::class);
|
2018-11-18 11:34:38 +01:00
|
|
|
$leave5 = $this->createMock(SourceInterface::class);
|
2018-11-18 11:41:24 +01:00
|
|
|
$tree2->setCollection(new ArrayCollection([$leave3, $leave4, $tree5, $leave5]));
|
|
|
|
$collection = new ArrayCollection([$tree2, $tree3, $leave1, $leave2, $tree4, $tree1]);
|
2018-11-18 10:50:18 +01:00
|
|
|
$tree1->setCollection($collection);
|
2019-01-19 22:52:49 +01:00
|
|
|
$this->treeService = new TreeSourceInformation($tree1);
|
2018-11-18 10:50:18 +01:00
|
|
|
}
|
2018-11-18 11:41:24 +01:00
|
|
|
|
|
|
|
public function testGetLeaves(): void
|
|
|
|
{
|
2018-11-18 10:50:18 +01:00
|
|
|
$this->assertEquals(2, $this->treeService->getLeaves()->count());
|
|
|
|
}
|
2018-11-18 11:41:24 +01:00
|
|
|
|
|
|
|
public function testGetBranches(): void
|
|
|
|
{
|
2018-11-18 11:39:06 +01:00
|
|
|
$this->assertEquals(4, $this->treeService->getBranches()->count());
|
2018-11-18 10:53:48 +01:00
|
|
|
}
|
2018-11-18 11:41:24 +01:00
|
|
|
|
|
|
|
public function testGetAllBranches(): void
|
|
|
|
{
|
2018-11-18 11:39:06 +01:00
|
|
|
$this->assertEquals(5, $this->treeService->getAllBranches()->count());
|
2018-11-18 11:13:36 +01:00
|
|
|
}
|
2018-11-18 11:41:24 +01:00
|
|
|
|
|
|
|
public function testGetAllLeaves(): void
|
|
|
|
{
|
2018-11-18 11:34:38 +01:00
|
|
|
$this->assertEquals(5, $this->treeService->getAllLeaves()->count());
|
2018-11-18 11:13:36 +01:00
|
|
|
}
|
2018-11-18 10:50:18 +01:00
|
|
|
}
|