mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 21:57:16 +02:00
Implemented tests for DimensionHelper
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Helper\Dimension;
|
||||
use App\Helper\DimensionHelper;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -34,8 +33,9 @@ trait MembersAttribut
|
||||
*/
|
||||
public function getMembersIncludingChildren(?int $dimension = null, Collection $members = null): Collection
|
||||
{
|
||||
$dimensionHelper = new Dimension(__FUNCTION__, MembersAttributInterface::class, $this, 'members');
|
||||
return $dimensionHelper->getDimensions($dimension,$members);
|
||||
$dimensionHelper = new DimensionHelper(__FUNCTION__, MembersAttributInterface::class, $this, 'members');
|
||||
|
||||
return $dimensionHelper->getDimensions($dimension, $members);
|
||||
}
|
||||
|
||||
private function continueIncludeMembersLoop(?int $dimension): bool
|
||||
|
@@ -3,7 +3,6 @@
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\GroupSourceInterface;
|
||||
use App\Entity\Source\Collection\MemberCollectionSourceInterface;
|
||||
|
||||
/**
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
@@ -9,15 +10,14 @@ trait SourceCollectionAttribut
|
||||
/**
|
||||
* @param Collection|SourceInterface[] $collection
|
||||
*/
|
||||
public function setCollection(Collection $collection):void{
|
||||
|
||||
public function setCollection(Collection $collection): void
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Collection|SourceInterface[]
|
||||
*/
|
||||
public function getCollection():Collection{
|
||||
|
||||
public function getCollection(): Collection
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
@@ -9,10 +10,10 @@ interface SourceCollectionAttributInterface
|
||||
/**
|
||||
* @param Collection|SourceInterface[] $collection
|
||||
*/
|
||||
public function setCollection(Collection $collection):void;
|
||||
|
||||
public function setCollection(Collection $collection): void;
|
||||
|
||||
/**
|
||||
* @return Collection|SourceInterface[]
|
||||
*/
|
||||
public function getCollection():Collection;
|
||||
}
|
||||
public function getCollection(): Collection;
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation\Exclude;
|
||||
use App\Entity\AbstractEntity;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Attribut\GroupSourcesAttribut;
|
||||
use App\Entity\Meta\RelationInterface;
|
||||
use App\Entity\Attribut\RelationAttribut;
|
||||
use App\Entity\Meta\Relation;
|
||||
|
@@ -1,9 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Source\Collection;
|
||||
|
||||
use App\Entity\Source\AbstractSource;
|
||||
|
||||
/**
|
||||
* @todo Implement inhiering classes!
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
class AbstractCollectionSource extends AbstractSource implements CollectionSourceInterface
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Source\Collection;
|
||||
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
interface CollectionSourceInterface extends SourceInterface
|
||||
{}
|
||||
|
||||
{
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Attribut\MembersAttribut;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @ORM\Table(name="source_group")
|
||||
|
@@ -7,6 +7,6 @@ use App\Entity\Attribut\MembersAttributInterface;
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface MemberCollectionSourceInterface extends MembersAttributInterface,CollectionSourceInterface
|
||||
interface MemberCollectionSourceInterface extends MembersAttributInterface, CollectionSourceInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Source\Collection\Queue;
|
||||
|
||||
use App\Entity\Attribut\MembersAttributInterface;
|
||||
@@ -7,11 +8,12 @@ use App\Entity\Source\SourceInterface;
|
||||
|
||||
/**
|
||||
* @todo Implement integration test for two user accessing queue! Check if log works!
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface QueueSourceInterface extends CollectionSourceInterface, MembersAttributInterface
|
||||
{
|
||||
public function getPointerPosition():int;
|
||||
|
||||
public function getNextElement():SourceInterface;
|
||||
}
|
||||
public function getPointerPosition(): int;
|
||||
|
||||
public function getNextElement(): SourceInterface;
|
||||
}
|
||||
|
@@ -1,60 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helper;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* Helps to get all Elements till a special dimension
|
||||
* Helps to get all Elements till a special dimension.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement tests for all functions
|
||||
*/
|
||||
final class Dimension implements DimensionInterface
|
||||
final class DimensionHelper implements DimensionHelperInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $attribut;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $method;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $interface;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $object;
|
||||
|
||||
|
||||
/**
|
||||
* @var int|null the actual dimension to which the class points
|
||||
*/
|
||||
private $dimension = null;
|
||||
|
||||
|
||||
/**
|
||||
* @param string $method which uses the dimension helper
|
||||
* @param string $method which uses the dimension helper
|
||||
* @param string $interface which is implemented in all classes which have dimensions
|
||||
* @param object $object which calls the dimension helper
|
||||
* @param string $attribut which represents dimensions
|
||||
* @param object $object which calls the dimension helper
|
||||
* @param string $attribut which represents dimensions
|
||||
*/
|
||||
public function __construct(string $method,string $interface, object $object,string $attribut) {
|
||||
$this->method = $method;
|
||||
$this->interface = $interface;
|
||||
$this->object = $object;
|
||||
$this->attribut = $attribut;
|
||||
public function __construct(string $method, string $interface, object $object, string $attribut)
|
||||
{
|
||||
$this->method = $method;
|
||||
$this->interface = $interface;
|
||||
$this->object = $object;
|
||||
$this->attribut = $attribut;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $dimension The dimensions start with 1 for the elements of the actuall dimension and NULL for all elements
|
||||
* @param Collection $elements A elements collection, to which new elements should be add
|
||||
* @param Collection $elements A elements collection, to which new elements should be add
|
||||
*
|
||||
* @return Collection Returns all elements till the defined dimension
|
||||
*/
|
||||
@@ -62,7 +63,7 @@ final class Dimension implements DimensionInterface
|
||||
{
|
||||
$this->setDimension($dimension);
|
||||
$elements = $elements ?? new ArrayCollection();
|
||||
foreach ($this->object->{$this->attributGetterName()}()->toArray() as $element) {
|
||||
foreach ($this->object->{$this->attributGetterName()}()->toArray() as $element) {
|
||||
if (!$elements->contains($element)) {
|
||||
$elements->add($element);
|
||||
if ($this->continueLoop() && $element instanceof $this->interface) {
|
||||
@@ -70,28 +71,32 @@ final class Dimension implements DimensionInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
private function setDimension(?int $dimension):void{
|
||||
|
||||
private function setDimension(?int $dimension): void
|
||||
{
|
||||
$this->dimension = is_int($dimension) ? $dimension - 1 : null;
|
||||
}
|
||||
|
||||
private function attributGetterName():string{
|
||||
|
||||
private function attributGetterName(): string
|
||||
{
|
||||
return 'get'.ucfirst($this->attribut);
|
||||
}
|
||||
|
||||
private function includeInfiniteDimensions():bool{
|
||||
|
||||
private function includeInfiniteDimensions(): bool
|
||||
{
|
||||
return is_null($this->dimension);
|
||||
}
|
||||
|
||||
private function isNotLastDimension():bool{
|
||||
|
||||
private function isNotLastDimension(): bool
|
||||
{
|
||||
return $this->dimension > 0;
|
||||
}
|
||||
|
||||
|
||||
private function continueLoop(): bool
|
||||
{
|
||||
return $this->includeInfiniteDimensions() || $this->isNotLastDimension();
|
||||
return $this->includeInfiniteDimensions() || $this->isNotLastDimension();
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helper;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
interface DimensionInterface
|
||||
interface DimensionHelperInterface
|
||||
{
|
||||
public function getDimensions(?int $dimension = null, Collection $elements = null): Collection;
|
||||
}
|
||||
|
Reference in New Issue
Block a user