2018-10-31 13:24:49 +01:00
|
|
|
<?php
|
|
|
|
|
2018-10-31 16:15:39 +01:00
|
|
|
namespace tests\unit\Entity\Source\Operation;
|
2018-10-31 13:24:49 +01:00
|
|
|
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Entity\Source\Operation\AndOperation;
|
2020-04-02 21:13:35 +02:00
|
|
|
use Infinito\Entity\Source\Operation\OperationInterface;
|
2019-04-15 01:37:17 +02:00
|
|
|
use Infinito\Exception\Attribut\UndefinedAttributException;
|
2020-04-02 21:13:35 +02:00
|
|
|
use Infinito\Logic\Operation\OperandInterface;
|
|
|
|
use Infinito\Logic\Result\Result;
|
|
|
|
use Infinito\Logic\Result\ResultInterface;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2018-10-31 13:24:49 +01:00
|
|
|
|
|
|
|
class AndOperationTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var OperationInterface
|
|
|
|
*/
|
|
|
|
protected $operation;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$this->operation = new AndOperation();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConstructor(): void
|
|
|
|
{
|
2019-04-15 01:37:17 +02:00
|
|
|
$this->expectException(UndefinedAttributException::class);
|
2018-10-31 13:24:49 +01:00
|
|
|
$this->operation->process();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testProcess(): void
|
|
|
|
{
|
|
|
|
//Test True
|
|
|
|
$operand1 = new class() implements OperandInterface {
|
|
|
|
public function getResult(): ResultInterface
|
|
|
|
{
|
|
|
|
$result = new Result();
|
|
|
|
$result->setAll(true);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$operand2 = new class() implements OperandInterface {
|
|
|
|
public function getResult(): ResultInterface
|
|
|
|
{
|
|
|
|
$result = new Result();
|
|
|
|
$result->setAll(true);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$operands = new ArrayCollection([$operand1, $operand2]);
|
|
|
|
$this->operation->setOperands($operands);
|
|
|
|
$this->operation->process();
|
|
|
|
$this->assertEquals(true, $this->operation->getResult()->getBool());
|
|
|
|
|
|
|
|
//Test False
|
|
|
|
$operand3 = new class() implements OperandInterface {
|
|
|
|
public function getResult(): ResultInterface
|
|
|
|
{
|
|
|
|
$result = new Result();
|
|
|
|
$result->setAll(false);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$this->operation->getOperands()->add($operand3);
|
|
|
|
$this->operation->process();
|
|
|
|
$this->assertEquals(false, $this->operation->getResult()->getBool());
|
|
|
|
}
|
|
|
|
}
|