General optimation of tests and namespaces

This commit is contained in:
Kevin Frantz
2018-10-31 19:15:07 +01:00
parent a798262150
commit d427eeb458
15 changed files with 57 additions and 24 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace tests\unit\Entity\Source;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface;
use App\Entity\Meta\LawInterface;
use App\Entity\Meta\RelationInterface;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\AbstractSource;
/**
* @author kevinfrantz
*/
class AbstractSourceTest extends TestCase
{
const ID = 123;
/**
* @var SourceInterface
*/
protected $source;
public function setUp()
{
$this->source = new class() extends \App\Entity\Source\AbstractSource {
};
$this->source->setId(self::ID);
}
public function testId()
{
$this->assertEquals($this->source->getId(), self::ID);
}
public function testLaw()
{
$this->assertInstanceOf(LawInterface::class, $this->source->getLaw());
}
public function testRelation()
{
$this->assertInstanceOf(RelationInterface::class, $this->source->getRelation());
}
public function testGroups()
{
$this->assertInstanceOf(Collection::class, $this->source->getGroupSources());
$group = new class() extends AbstractSource {
};
$groups = new ArrayCollection([$group]);
$this->source->setGroupSources($groups);
$this->assertEquals($group, $this->source->getGroupSources()->get(0));
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace tests\unit\Entity\Source;
use App\Entity\Source\GroupSourceInterface;
use App\Entity\Source\GroupSource;
use PHPUnit\Framework\TestCase;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\AbstractSource;
/**
* @author kevinfrantz
*/
class GroupSourceTest extends TestCase
{
/**
* @var GroupSourceInterface
*/
protected $groupSource;
public function setUp(): void
{
$this->groupSource = new GroupSource();
}
public function testMembers()
{
$this->assertInstanceOf(Collection::class, $this->groupSource->getMembers());
$member = new class() extends AbstractSource {
};
$this->groupSource->setMembers(new ArrayCollection([$member]));
$this->assertEquals($member, $this->groupSource->getMembers()->get(0));
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace tests\unit\Entity\Source;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\NameSourceInterface;
use App\Entity\Source\NameSource;
/**
* @author kevinfrantz
*/
class NameSourceTest extends TestCase
{
/**
* @var NameSourceInterface
*/
protected $nameSource;
public function setUp(): void
{
$this->nameSource = new NameSource();
}
public function testName(): void
{
$this->assertEquals('', $this->nameSource->getName());
$name = 'Hello World!';
$this->nameSource->setName($name);
$this->assertEquals($name, $this->nameSource->getName());
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace tests\unit\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;
use App\Exception\NotProcessedException;
class AbstractOperationTest extends TestCase
{
/**
* @var OperationInterface
*/
protected $operation;
public function setUp(): void
{
$this->operation = new class() extends AbstractOperation {
public function process(): void
{
$this->result = new Result();
}
};
}
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->assertNull($this->operation->setOperands($operands));
$this->assertEquals($operand, $this->operation->getOperands()
->get(0));
}
public function testNotProcessedException(): void
{
$this->expectException(NotProcessedException::class);
$this->operation->getResult();
}
public function testResult(): void
{
$this->setUp();
$this->operation->process();
$this->assertInstanceOf(ResultInterface::class, $this->operation->getResult());
}
public function testProcess(): void
{
$this->assertEquals(null, $this->operation->process());
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace tests\unit\Entity\Source\Operation;
use PHPUnit\Framework\TestCase;
use App\Exception\NotDefinedException;
use App\Logic\Result\Result;
use App\Logic\Operation\OperandInterface;
use App\Logic\Result\ResultInterface;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\Operation\OperationInterface;
use App\Entity\Source\Operation\AndOperation;
class AndOperationTest extends TestCase
{
/**
* @var OperationInterface
*/
protected $operation;
public function setUp(): void
{
$this->operation = new AndOperation();
}
public function testConstructor(): void
{
$this->expectException(NotDefinedException::class);
$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());
}
}