From 6540e1dd95d6750f0a814d9abdd1c896fdced808 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Wed, 31 Oct 2018 12:15:49 +0100 Subject: [PATCH] Implemented test and logic for AbstractOperation --- .../Source/Operation/AbstractOperation.php | 12 +++- .../Entity/Source/Operation/AndOperation.php | 2 +- .../Operation/Attribut/OperandsAttribut.php | 29 +++++++++ .../Attribut/OperandsAttributInterface.php | 18 ++++++ .../Source/Operation/OperationInterface.php | 10 +++ .../Operation/AbstractOperationTest.php | 64 +++++++++++++++++++ 6 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 application/src/Entity/Source/Operation/Attribut/OperandsAttribut.php create mode 100644 application/src/Entity/Source/Operation/Attribut/OperandsAttributInterface.php create mode 100644 application/src/Entity/Source/Operation/OperationInterface.php create mode 100644 application/tests/unit/Entity/Source/Operation/AbstractOperationTest.php diff --git a/application/src/Entity/Source/Operation/AbstractOperation.php b/application/src/Entity/Source/Operation/AbstractOperation.php index 97f4fb9..f57c4fe 100644 --- a/application/src/Entity/Source/Operation/AbstractOperation.php +++ b/application/src/Entity/Source/Operation/AbstractOperation.php @@ -3,11 +3,11 @@ namespace App\Entity\Source\Operation; use App\Logic\Result\ResultInterface; -use App\Logic\Operation\OperationInterface; use App\Logic\Operation\OperandInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use App\Entity\Source\AbstractSource; +use App\Entity\Source\Operation\Attribut\OperandsAttribut; /** * @author kevinfrantz @@ -17,8 +17,10 @@ use App\Entity\Source\AbstractSource; * @ORM\DiscriminatorColumn(name="discr", type="string") * @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! * @@ -31,6 +33,12 @@ abstract class AbstractOperation extends AbstractSource implements OperationInte */ protected $operands; + public function __construct() + { + parent::__construct(); + $this->operands = new ArrayCollection(); + } + public function getResult(): ResultInterface { return $this->result; diff --git a/application/src/Entity/Source/Operation/AndOperation.php b/application/src/Entity/Source/Operation/AndOperation.php index f80747a..c1c2c6a 100644 --- a/application/src/Entity/Source/Operation/AndOperation.php +++ b/application/src/Entity/Source/Operation/AndOperation.php @@ -11,7 +11,7 @@ use Doctrine\ORM\Mapping as ORM; * @ORM\Table(name="source_operation_and") * @ORM\Entity() */ -class AndOperation extends AbstractOperation +final class AndOperation extends AbstractOperation { public function process(): void { diff --git a/application/src/Entity/Source/Operation/Attribut/OperandsAttribut.php b/application/src/Entity/Source/Operation/Attribut/OperandsAttribut.php new file mode 100644 index 0000000..4706323 --- /dev/null +++ b/application/src/Entity/Source/Operation/Attribut/OperandsAttribut.php @@ -0,0 +1,29 @@ +operands = $operands; + } + + /** + * @return Collection + */ + public function getOperands(): Collection + { + return $this->operands; + } +} diff --git a/application/src/Entity/Source/Operation/Attribut/OperandsAttributInterface.php b/application/src/Entity/Source/Operation/Attribut/OperandsAttributInterface.php new file mode 100644 index 0000000..c513bf6 --- /dev/null +++ b/application/src/Entity/Source/Operation/Attribut/OperandsAttributInterface.php @@ -0,0 +1,18 @@ +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()); + } +}