Wrote tests for dimension helper method and optimized dimension helper

This commit is contained in:
Kevin Frantz
2018-11-03 15:14:04 +01:00
parent a66e2c3b46
commit 556c919f1f
3 changed files with 99 additions and 13 deletions

View File

@@ -4,7 +4,7 @@ namespace App\Entity\Method;
use Doctrine\Common\Collections\Collection;
use App\Helper\DimensionHelper;
use App\Entity\Attribut\MembersAttributInterface;
use App\Helper\DimensionHelperInterface;
/**
* @todo Create test for trait!
@@ -15,7 +15,7 @@ trait CollectionDimensionHelperMethod
{
public function getDimensions(?int $dimension = null, Collection $elements = null): Collection
{
$dimensionHelper = new DimensionHelper(__FUNCTION__, MembersAttributInterface::class, $this, 'collection');
$dimensionHelper = new DimensionHelper(__FUNCTION__, DimensionHelperInterface::class, $this, 'collection');
return $dimensionHelper->getDimensions($dimension, $elements);
}

View File

@@ -40,10 +40,14 @@ final class DimensionHelper implements DimensionHelperInterface
private $dimension = null;
/**
* @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 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
*/
public function __construct(string $method, string $interface, object $object, string $attribut)
{
@@ -54,8 +58,10 @@ final class DimensionHelper implements DimensionHelperInterface
}
/**
* @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 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
*
* @return Collection Returns all elements till the defined dimension
*/
@@ -63,11 +69,14 @@ final class DimensionHelper implements DimensionHelperInterface
{
$this->setDimension($dimension);
$elements = $elements ?? new ArrayCollection();
foreach ($this->object->{$this->attributGetterName()}()->toArray() as $element) {
if (!$elements->contains($element)) {
$elements->add($element);
if ($this->continueLoop() && $element instanceof $this->interface) {
$element->{$this->method}($this->dimension, $elements);
if ($this->dimension >= 0) {
foreach ($this->object->{$this->attributGetterName()}()
->toArray() as $element) {
if (!$elements->contains($element)) {
$elements->add($element);
if ($this->continueLoop() && $element instanceof $this->interface) {
$element->{$this->method}($this->dimension, $elements);
}
}
}
}