Solved unit tests

This commit is contained in:
Kevin Frantz 2018-11-15 20:30:34 +01:00
parent de66375ee0
commit 7be76cac0d
14 changed files with 41 additions and 59 deletions

View File

@ -2,7 +2,7 @@
namespace App\Entity\Attribut; namespace App\Entity\Attribut;
use App\Entity\Source\Data\NameSourceInterface; use App\Entity\Source\Data\Name\NameSourceInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz

View File

@ -2,7 +2,7 @@
namespace App\Entity\Attribut; namespace App\Entity\Attribut;
use App\Entity\Source\Data\NameSourceInterface; use App\Entity\Source\Data\Name\NameSourceInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz

View File

@ -2,7 +2,7 @@
namespace App\Entity\Attribut; namespace App\Entity\Attribut;
use App\Entity\Source\Data\PersonIdentitySourceInterface; use App\Entity\Source\Combination\PersonIdentitySourceInterface;
trait PersonIdentitySourceAttribut trait PersonIdentitySourceAttribut
{ {

View File

@ -2,7 +2,7 @@
namespace App\Entity\Attribut; namespace App\Entity\Attribut;
use App\Entity\Source\Data\PersonIdentitySourceInterface; use App\Entity\Source\Combination\PersonIdentitySourceInterface;
interface PersonIdentitySourceAttributInterface interface PersonIdentitySourceAttributInterface
{ {

View File

@ -1,10 +1,9 @@
<?php <?php
namespace App\Entity\Source\Data; namespace App\Entity\Source\Combination;
use App\Entity\Attribut\FullPersonNameSourceAttribut; use App\Entity\Attribut\FullPersonNameSourceAttribut;
use App\Entity\Source\Combination\FullPersonNameSourceInterface; use App\Entity\Source\Data\AbstractDataSource;
use App\Entity\Source\Combination\FullPersonNameSource;
class PersonIdentitySource extends AbstractDataSource implements PersonIdentitySourceInterface class PersonIdentitySource extends AbstractDataSource implements PersonIdentitySourceInterface
{ {

View File

@ -1,9 +1,9 @@
<?php <?php
namespace App\Entity\Source\Data; namespace App\Entity\Source\Combination;
use App\Entity\Attribut\FullPersonNameSourceAttributInterface; use App\Entity\Attribut\FullPersonNameSourceAttributInterface;
interface PersonIdentitySourceInterface extends DataSourceInterface, FullPersonNameSourceAttributInterface interface PersonIdentitySourceInterface extends CombinationSourceInterface, FullPersonNameSourceAttributInterface
{ {
} }

View File

@ -24,8 +24,16 @@ class UserSource extends AbstractCombinationSource implements UserSourceInterfac
*/ */
protected $user; protected $user;
/**
* @todo Implement ORM mapping for database!
*
* @var PersonIdentitySourceInterface
*/
protected $personIdentitySource;
public function __construct() public function __construct()
{ {
$this->personIdentitySource = new PersonIdentitySource();
parent::__construct(); parent::__construct();
} }
} }

View File

@ -5,7 +5,7 @@ namespace tests\unit\Entity\Attribut;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\NameSourceAttributInterface; use App\Entity\Attribut\NameSourceAttributInterface;
use App\Entity\Attribut\NameSourceAttribut; use App\Entity\Attribut\NameSourceAttribut;
use App\Entity\Source\Data\NameSourceInterface; use App\Entity\Source\Data\Name\NameSourceInterface;
class NameSourceAttributTest extends TestCase class NameSourceAttributTest extends TestCase
{ {

View File

@ -5,7 +5,7 @@ namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\PersonIdentitySourceAttributInterface; use App\Entity\Attribut\PersonIdentitySourceAttributInterface;
use App\Entity\Attribut\PersonIdentitySourceAttribut; use App\Entity\Attribut\PersonIdentitySourceAttribut;
use App\Entity\Source\Data\PersonIdentitySourceInterface; use App\Entity\Source\Combination\PersonIdentitySourceInterface;
/** /**
* @todo Implement abstract test class for entity attributs * @todo Implement abstract test class for entity attributs
@ -29,13 +29,13 @@ class PersonIdentitySourceAttributTest extends TestCase
public function testConstructor(): void public function testConstructor(): void
{ {
$this->expectException(\TypeError::class); $this->expectException(\TypeError::class);
$this->identity->getIdentitySource(); $this->identity->getPersonIdentitySource();
} }
public function testAccessors(): void public function testAccessors(): void
{ {
$identity = $this->createMock(PersonIdentitySourceInterface::class); $identity = $this->createMock(PersonIdentitySourceInterface::class);
$this->assertNull($this->identity->setIdentitySource($identity)); $this->assertNull($this->identity->setPersonIdentitySource($identity));
$this->assertEquals($collection, $this->identity->getIdentitySource()); $this->assertEquals($identity, $this->identity->getPersonIdentitySource());
} }
} }

View File

@ -3,8 +3,8 @@
namespace tests\unit\Entity\Source\Combination; namespace tests\unit\Entity\Source\Combination;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Entity\Source\Data\PersonIdentitySourceInterface; use App\Entity\Source\Combination\PersonIdentitySourceInterface;
use App\Entity\Source\Data\PersonIdentitySource; use App\Entity\Source\Combination\PersonIdentitySource;
use App\Entity\Source\Combination\FullPersonNameSourceInterface; use App\Entity\Source\Combination\FullPersonNameSourceInterface;
class PersonIdentitySourceTest extends TestCase class PersonIdentitySourceTest extends TestCase
@ -12,15 +12,22 @@ class PersonIdentitySourceTest extends TestCase
/** /**
* @var PersonIdentitySourceInterface * @var PersonIdentitySourceInterface
*/ */
public $identitySource; protected $identity;
public function setUp(): void public function setUp(): void
{ {
$this->userSource = new PersonIdentitySource(); $this->identity = new PersonIdentitySource();
} }
public function testConstructor(): void public function testConstructor(): void
{ {
$this->assertInstanceOf(FullPersonNameSourceInterface::class, $this->identitySource->getFullPersonNameSource()); $this->assertInstanceOf(FullPersonNameSourceInterface::class, $this->identity->getFullPersonNameSource());
}
public function testFullName(): void
{
$name = $this->createMock(FullPersonNameSourceInterface::class);
$this->assertNull($this->identity->setFullPersonNameSource($name));
$this->assertEquals($name, $this->identity->getFullPersonNameSource());
} }
} }

View File

@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase;
use App\Entity\Source\Combination\UserSourceInterface; use App\Entity\Source\Combination\UserSourceInterface;
use App\Entity\Source\Combination\UserSource; use App\Entity\Source\Combination\UserSource;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use App\Entity\Source\Data\PersonIdentitySourceInterface; use App\Entity\Source\Combination\PersonIdentitySourceInterface;
class UserSourceTest extends TestCase class UserSourceTest extends TestCase
{ {
@ -23,7 +23,7 @@ class UserSourceTest extends TestCase
public function testConstructor(): void public function testConstructor(): void
{ {
$this->assertInstanceOf(Collection::class, $this->userSource->getMemberships()); $this->assertInstanceOf(Collection::class, $this->userSource->getMemberships());
$this->assertInstanceOf(PersonIdentitySourceInterface::class, $this->userSource->getIdentitySource()); $this->assertInstanceOf(PersonIdentitySourceInterface::class, $this->userSource->getPersonIdentitySource());
$this->expectException(\TypeError::class); $this->expectException(\TypeError::class);
$this->userSource->getUser(); $this->userSource->getUser();
} }

View File

@ -3,13 +3,13 @@
namespace tests\unit\Entity\Source\Data; namespace tests\unit\Entity\Source\Data;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Entity\Source\Data\NameSourceInterface; use App\Entity\Source\Data\Name\NameSourceInterface;
use App\Entity\Source\Data\NameSource; use App\Entity\Source\Data\Name\AbstractNameSource;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
class NameSourceTest extends TestCase class AbstractNameSourceTest extends TestCase
{ {
/** /**
* @var NameSourceInterface * @var NameSourceInterface
@ -18,7 +18,8 @@ class NameSourceTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->nameSource = new NameSource(); $this->nameSource = new class() extends AbstractNameSource {
};
} }
public function testConstructor(): void public function testConstructor(): void

View File

@ -1,33 +0,0 @@
<?php
namespace tests\unit\Entity\Source\Data;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\Data\PersonIdentitySourceInterface;
use App\Entity\Source\Data\PersonIdentitySource;
use App\Entity\Source\Combination\FullPersonNameSourceInterface;
class PersonIdentitySourceTest extends TestCase
{
/**
* @var PersonIdentitySourceInterface
*/
protected $identity;
public function setUp(): void
{
$this->identity = new PersonIdentitySource();
}
public function testConstructor(): void
{
$this->assertInstanceOf(FullPersonNameSourceInterface::class, $this->identity->getName());
}
public function testFullName(): void
{
$name = $this->createMock(FullPersonNameSourceInterface::class);
$this->assertNull($this->identity->setName($name));
$this->assertEquals($name, $this->identity->getName());
}
}

View File

@ -4,7 +4,7 @@ namespace tests\unit\Entity;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Entity\User; use App\Entity\User;
use App\Entity\Source\Data\UserSource; use App\Entity\Source\Combination\UserSource;
use App\Entity\UserInterface; use App\Entity\UserInterface;
/** /**