2018-10-31 12:15:49 +01:00
|
|
|
<?php
|
|
|
|
|
2018-10-31 16:15:39 +01:00
|
|
|
namespace tests\unit\Entity\Source\Operand;
|
2018-10-31 12:15:49 +01:00
|
|
|
|
|
|
|
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;
|
2018-10-31 13:24:49 +01:00
|
|
|
use App\Exception\NotProcessedException;
|
2018-10-31 12:15:49 +01:00
|
|
|
|
|
|
|
class AbstractOperationTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var OperationInterface
|
|
|
|
*/
|
|
|
|
protected $operation;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$this->operation = new class() extends AbstractOperation {
|
|
|
|
public function process(): void
|
|
|
|
{
|
2018-10-31 13:24:49 +01:00
|
|
|
$this->result = new Result();
|
2018-10-31 12:15:49 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2018-10-31 13:29:52 +01:00
|
|
|
$this->assertNull($this->operation->setOperands($operands));
|
2018-10-31 13:24:49 +01:00
|
|
|
$this->assertEquals($operand, $this->operation->getOperands()
|
|
|
|
->get(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNotProcessedException(): void
|
|
|
|
{
|
|
|
|
$this->expectException(NotProcessedException::class);
|
|
|
|
$this->operation->getResult();
|
2018-10-31 12:15:49 +01:00
|
|
|
}
|
|
|
|
|
2018-10-31 13:24:49 +01:00
|
|
|
public function testResult(): void
|
2018-10-31 12:15:49 +01:00
|
|
|
{
|
2018-10-31 13:24:49 +01:00
|
|
|
$this->setUp();
|
|
|
|
$this->operation->process();
|
2018-10-31 12:15:49 +01:00
|
|
|
$this->assertInstanceOf(ResultInterface::class, $this->operation->getResult());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testProcess(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(null, $this->operation->process());
|
|
|
|
}
|
|
|
|
}
|