mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Implemented test and logic for AbstractOperation
This commit is contained in:
parent
f576587f32
commit
6540e1dd95
@ -3,11 +3,11 @@
|
|||||||
namespace App\Entity\Source\Operation;
|
namespace App\Entity\Source\Operation;
|
||||||
|
|
||||||
use App\Logic\Result\ResultInterface;
|
use App\Logic\Result\ResultInterface;
|
||||||
use App\Logic\Operation\OperationInterface;
|
|
||||||
use App\Logic\Operation\OperandInterface;
|
use App\Logic\Operation\OperandInterface;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use App\Entity\Source\AbstractSource;
|
use App\Entity\Source\AbstractSource;
|
||||||
|
use App\Entity\Source\Operation\Attribut\OperandsAttribut;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -17,8 +17,10 @@ use App\Entity\Source\AbstractSource;
|
|||||||
* @ORM\DiscriminatorColumn(name="discr", type="string")
|
* @ORM\DiscriminatorColumn(name="discr", type="string")
|
||||||
* @ORM\DiscriminatorMap({"and" = "AndOperation"})
|
* @ORM\DiscriminatorMap({"and" = "AndOperation"})
|
||||||
*/
|
*/
|
||||||
abstract class AbstractOperation extends AbstractSource implements OperationInterface
|
abstract class AbstractOperation extends AbstractSource implements OperandInterface
|
||||||
{
|
{
|
||||||
|
use OperandsAttribut;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The result MUST NOT be saved via Doctrine!
|
* The result MUST NOT be saved via Doctrine!
|
||||||
*
|
*
|
||||||
@ -31,6 +33,12 @@ abstract class AbstractOperation extends AbstractSource implements OperationInte
|
|||||||
*/
|
*/
|
||||||
protected $operands;
|
protected $operands;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->operands = new ArrayCollection();
|
||||||
|
}
|
||||||
|
|
||||||
public function getResult(): ResultInterface
|
public function getResult(): ResultInterface
|
||||||
{
|
{
|
||||||
return $this->result;
|
return $this->result;
|
||||||
|
@ -11,7 +11,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
* @ORM\Table(name="source_operation_and")
|
* @ORM\Table(name="source_operation_and")
|
||||||
* @ORM\Entity()
|
* @ORM\Entity()
|
||||||
*/
|
*/
|
||||||
class AndOperation extends AbstractOperation
|
final class AndOperation extends AbstractOperation
|
||||||
{
|
{
|
||||||
public function process(): void
|
public function process(): void
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity\Source\Operation\Attribut;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
|
||||||
|
trait OperandsAttribut
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Collection
|
||||||
|
*/
|
||||||
|
protected $operands;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $collection
|
||||||
|
*/
|
||||||
|
public function setOperands(Collection $operands): void
|
||||||
|
{
|
||||||
|
$this->operands = $operands;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getOperands(): Collection
|
||||||
|
{
|
||||||
|
return $this->operands;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity\Source\Operation\Attribut;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
|
||||||
|
interface OperandsAttributInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Collection $collection
|
||||||
|
*/
|
||||||
|
public function setOperands(Collection $operands): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getOperands(): Collection;
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity\Source\Operation;
|
||||||
|
|
||||||
|
use App\Entity\Source\Operation\Attribut\OperandsAttributInterface;
|
||||||
|
use App\Logic\Operation\OperationInterface as OperationInterfaceOrigine;
|
||||||
|
|
||||||
|
interface OperationInterface extends OperandsAttributInterface, OperationInterfaceOrigine
|
||||||
|
{
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity\Source\Operand;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use App\Entity\Source\Operation\AbstractOperation;
|
||||||
|
use App\Entity\Source\Operation\OperationInterface;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use App\Logic\Operation\OperandInterface;
|
||||||
|
use App\Logic\Result\ResultInterface;
|
||||||
|
use App\Logic\Result\Result;
|
||||||
|
|
||||||
|
class AbstractOperationTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OperationInterface
|
||||||
|
*/
|
||||||
|
protected $operation;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$this->operation = new class() extends AbstractOperation {
|
||||||
|
public function getResult(): ResultInterface
|
||||||
|
{
|
||||||
|
return new Result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(): void
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConstructor(): void
|
||||||
|
{
|
||||||
|
$this->assertInstanceOf(Collection::class, $this->operation->getOperands());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOperands(): void
|
||||||
|
{
|
||||||
|
$operand = new class() implements OperandInterface {
|
||||||
|
public function getResult(): ResultInterface
|
||||||
|
{
|
||||||
|
return new Result();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$operands = new ArrayCollection();
|
||||||
|
$operands->add($operand);
|
||||||
|
$this->operation->setOperands($operands);
|
||||||
|
$this->assertEquals($operand, $this->operation->getOperands()->get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testResult()
|
||||||
|
{
|
||||||
|
$this->assertInstanceOf(ResultInterface::class, $this->operation->getResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProcess(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(null, $this->operation->process());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user