mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Implemented tests for DimensionHelper
This commit is contained in:
parent
0cd09258e7
commit
fdeaa390d3
@ -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 getPointerPosition(): int;
|
||||
|
||||
public function getNextElement():SourceInterface;
|
||||
public function getNextElement(): SourceInterface;
|
||||
}
|
@ -1,18 +1,20 @@
|
||||
<?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;
|
||||
@ -23,13 +25,11 @@ final class Dimension implements DimensionInterface
|
||||
private $method;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $interface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $object;
|
||||
@ -45,7 +45,8 @@ final class Dimension implements DimensionInterface
|
||||
* @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) {
|
||||
public function __construct(string $method, string $interface, object $object, string $attribut)
|
||||
{
|
||||
$this->method = $method;
|
||||
$this->interface = $interface;
|
||||
$this->object = $object;
|
||||
@ -70,22 +71,27 @@ 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;
|
||||
}
|
||||
|
||||
@ -94,4 +100,3 @@ final class Dimension implements DimensionInterface
|
||||
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;
|
||||
}
|
||||
|
@ -17,12 +17,30 @@ abstract class AbstractTestCase extends TestCase
|
||||
*
|
||||
* @return mixed method return
|
||||
*/
|
||||
public function invokeMethod(&$object, $methodName, array $parameters = [])
|
||||
public function invokeMethod(object &$object, string $methodName, array $parameters = [])
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($object));
|
||||
$reflection = $this->getReflectionClassByObject($object);
|
||||
$method = $reflection->getMethod($methodName);
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invokeArgs($object, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $object
|
||||
* @param string $property
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setProperty(object &$object, string $property, $value): void
|
||||
{
|
||||
$reflectionClass = $this->getReflectionClassByObject($object);
|
||||
$reflectionProperty = $reflectionClass->getProperty($property);
|
||||
$reflectionProperty->setAccessible(true);
|
||||
$reflectionProperty->setValue($object, $value);
|
||||
}
|
||||
|
||||
private function getReflectionClassByObject(object &$object): \ReflectionClass
|
||||
{
|
||||
return new \ReflectionClass(get_class($object));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Entity\Attribut;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -8,27 +9,27 @@ use App\Entity\Attribut\IdAttributInterface;
|
||||
class IdAttributTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var IdAttributInterface
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
public function setUp():void{
|
||||
$this->id = new class implements IdAttributInterface{
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->id = new class() implements IdAttributInterface {
|
||||
use IdAttribut;
|
||||
};
|
||||
}
|
||||
|
||||
public function testConstruct():void{
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->id->getId();
|
||||
}
|
||||
|
||||
public function testAccessors():void{
|
||||
public function testAccessors(): void
|
||||
{
|
||||
$id = 1234;
|
||||
$this->assertNull($this->id->setId($id));
|
||||
$this->assertEquals($id, $this->id->getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ namespace App\Tests\Unit\Entity\Attribut;
|
||||
use App\Entity\Attribut\MembersAttribut;
|
||||
use App\Entity\Attribut\MembersAttributInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
use App\Tests\AbstractTestCase;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
@ -21,8 +20,9 @@ class MembersAttributTest extends AbstractTestCase
|
||||
$this->membersAttribut = $this->getMembersAttributClassMock();
|
||||
}
|
||||
|
||||
private function getMembersAttributClassMock():MembersAttributInterface{
|
||||
return new class implements MembersAttributInterface{
|
||||
private function getMembersAttributClassMock(): MembersAttributInterface
|
||||
{
|
||||
return new class() implements MembersAttributInterface {
|
||||
use MembersAttribut;
|
||||
};
|
||||
}
|
||||
@ -34,20 +34,6 @@ class MembersAttributTest extends AbstractTestCase
|
||||
$this->membersAttribut->getMembersIncludingChildren();
|
||||
}
|
||||
|
||||
private function getContinueIncludeMemberLoopResult($dimension): bool
|
||||
{
|
||||
return $this->invokeMethod($this->membersAttribut, 'continueIncludeMembersLoop', [$dimension]);
|
||||
}
|
||||
|
||||
public function testContinueIncludeMemberLoop()
|
||||
{
|
||||
$this->assertTrue($this->getContinueIncludeMemberLoopResult(null));
|
||||
$this->assertTrue($this->getContinueIncludeMemberLoopResult(2));
|
||||
$this->assertTrue($this->getContinueIncludeMemberLoopResult(1));
|
||||
$this->assertFalse($this->getContinueIncludeMemberLoopResult(0));
|
||||
$this->assertFalse($this->getContinueIncludeMemberLoopResult(-1));
|
||||
}
|
||||
|
||||
public function testMembersAccessors()
|
||||
{
|
||||
$source1 = $this->createMock(SourceInterface::class);
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Entity\Attribut;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -10,26 +11,27 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
class MembershipsAttributTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var MembershipsAttributInterface
|
||||
*/
|
||||
protected $memberships;
|
||||
|
||||
public function setUp():void{
|
||||
$this->memberships = new class implements MembershipsAttributInterface{
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->memberships = new class() implements MembershipsAttributInterface {
|
||||
use MembershipsAttribut;
|
||||
};
|
||||
}
|
||||
|
||||
public function testConstructor():void {
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->memberships->getMemberships();
|
||||
}
|
||||
|
||||
public function testAccessors():void {
|
||||
public function testAccessors(): void
|
||||
{
|
||||
$membership = $this->createMock(MemberCollectionSourceInterface::class);
|
||||
$this->assertNull($this->memberships->setMemberships(new ArrayCollection([$membership])));
|
||||
$this->assertEquals($this->memberships->getMemberships()->get(0), $membership);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Entity\Source\Collection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -9,14 +10,11 @@ use App\Entity\Source\Collection\MemberCollectionSourceInterface;
|
||||
use App\Entity\Source\Collection\MemberCollectionSource;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class MemberCollectionSourceTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var MemberCollectionSourceInterface
|
||||
*/
|
||||
protected $groupSource;
|
||||
@ -33,9 +31,10 @@ class MemberCollectionSourceTest extends TestCase
|
||||
|
||||
public function testMembers()
|
||||
{
|
||||
$member = new class() extends AbstractSource {};
|
||||
$member = new class() extends AbstractSource {
|
||||
};
|
||||
$this->groupSource->setMembers(new ArrayCollection([
|
||||
$member
|
||||
$member,
|
||||
]));
|
||||
$this->assertEquals($member, $this->groupSource->getMembers()
|
||||
->get(0));
|
||||
|
64
application/tests/Unit/HelperTest.php
Normal file
64
application/tests/Unit/HelperTest.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Unit\Helper;
|
||||
|
||||
use App\Tests\AbstractTestCase;
|
||||
use App\Helper\DimensionHelper;
|
||||
use App\Helper\DimensionHelperInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
class HelperTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var DimensionHelperInterface
|
||||
*/
|
||||
protected $dimensionMock;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->dimensionMock = new class() implements DimensionHelperInterface {
|
||||
/**
|
||||
* @var ArrayCollection
|
||||
*/
|
||||
public $dimensionElements;
|
||||
|
||||
/**
|
||||
* @var DimensionHelper
|
||||
*/
|
||||
public $dimensionHelper;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dimensionElements = new ArrayCollection();
|
||||
$this->dimensionHelper = new DimensionHelper('getDimensions', DimensionHelperInterface::class, $this, 'dimensionElements');
|
||||
}
|
||||
|
||||
public function getDimensionElements(): Collection
|
||||
{
|
||||
return $this->dimensionElements;
|
||||
}
|
||||
|
||||
public function getDimensions(?int $dimension = null, Collection $elements = null): Collection
|
||||
{
|
||||
return $this->dimensionHelper->getDimensions($dimension, $elements);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private function getContinueLoopResult($dimension): bool
|
||||
{
|
||||
$this->setProperty($this->dimensionMock->dimensionHelper, 'dimension', $dimension);
|
||||
|
||||
return $this->invokeMethod($this->dimensionMock->dimensionHelper, 'continueLoop');
|
||||
}
|
||||
|
||||
public function testContinueLoop(): void
|
||||
{
|
||||
$this->assertTrue($this->getContinueLoopResult(null));
|
||||
$this->assertTrue($this->getContinueLoopResult(2));
|
||||
$this->assertTrue($this->getContinueLoopResult(1));
|
||||
$this->assertFalse($this->getContinueLoopResult(0));
|
||||
$this->assertFalse($this->getContinueLoopResult(-1));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user