Continued the integration of person identity

This commit is contained in:
Kevin Frantz 2018-11-10 12:30:59 +01:00
parent 7a6a5e1bcf
commit c1b073eba8
21 changed files with 206 additions and 52 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\Source\Combination\FullPersonNameSourceInterface;
trait FullPersonNameSourceAttribut
{
/**
* @var FullPersonNameSourceInterface
*/
protected $fullPersonNameSource;
public function getFullPersonNameSource(): FullPersonNameSourceInterface
{
return $this->fullPersonNameSource;
}
public function setFullPersonNameSource(FullPersonNameSourceInterface $fullname): void
{
$this->fullPersonNameSource = $fullname;
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\Source\Combination\FullPersonNameSourceInterface;
interface FullPersonNameSourceAttributInterface
{
public function getFullPersonNameSource(): FullPersonNameSourceInterface;
public function setFullPersonNameSource(FullPersonNameSourceInterface $fullname): void;
}

View File

@ -0,0 +1,23 @@
<?php
namespace Entity\Attribut;
use App\Entity\Source\Data\PersonIdentitySourceInterface;
trait PersonIdentityAttribut
{
/**
* @var PersonIdentitySourceInterface
*/
protected $personIdentitySource;
public function getPersonIdentitySource(): PersonIdentitySourceInterface
{
return $this->personIdentitySource;
}
public function setPersonIdentitySource(PersonIdentitySourceInterface $identity): void
{
$this->personIdentitySource = $identity;
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\Source\Data\PersonIdentitySourceInterface;
interface PersonIdentitySourceAttributInterface
{
public function getPersonIdentitySource(): PersonIdentitySourceInterface;
public function setPersonIdentitySource(PersonIdentitySourceInterface $identity): void;
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity\Source\Combination;
use App\Entity\Source\AbstractSource;

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity\Source\Combination;
use App\Entity\Source\Data\DataSourceInterface;
@ -6,4 +7,3 @@ use App\Entity\Source\Data\DataSourceInterface;
interface CombinationSourceInterface extends DataSourceInterface
{
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity\Source\Combination;
use App\Entity\Source\Data\Name\FirstNameSourceInterface;
@ -6,8 +7,8 @@ use App\Entity\Source\Data\Name\SurnameSourceInterface;
/**
* @todo Maybe a middle name would be helpfull in the future ;)
* @author kevinfrantz
*
* @author kevinfrantz
*/
interface FullPersonNameSourceInterface extends CombinationSourceInterface
{

View File

@ -1,8 +0,0 @@
<?php
namespace App\Entity\Source\Data;
class IdentitySource extends AbstractDataSource implements IdentityInterface
{
}

View File

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

View File

@ -0,0 +1,16 @@
<?php
namespace App\Entity\Source\Data;
class PesonIdentitySource extends AbstractDataSource implements PersonIdentitySourceInterface
{
/**
* @Assert\Type(type="App\Entity\Source\NameSource")
* @Assert\Valid()
* @ORM\OneToOne(targetEntity="NameSource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="name_id", referencedColumnName="id")
*
* @var NameSourceInterface
*/
protected $nameSource;
}

View File

@ -3,10 +3,9 @@
namespace App\Entity\Source\Data;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Attribut\UserAttribut;
use App\Entity\Attribut\NameSourceAttribut;
use App\Entity\UserInterface;
use Entity\Attribut\PersonIdentityAttribut;
/**
* @author kevinfrantz
@ -15,7 +14,7 @@ use App\Entity\UserInterface;
*/
class UserSource extends AbstractDataSource implements UserSourceInterface
{
use UserAttribut,NameSourceAttribut;
use UserAttribut,PersonIdentityAttribut;
/**
* @ORM\OneToOne(targetEntity="App\Entity\User",cascade={"persist", "remove"})
@ -25,19 +24,8 @@ class UserSource extends AbstractDataSource implements UserSourceInterface
*/
protected $user;
/**
* @Assert\Type(type="App\Entity\Source\NameSource")
* @Assert\Valid()
* @ORM\OneToOne(targetEntity="NameSource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="name_id", referencedColumnName="id")
*
* @var NameSourceInterface
*/
protected $nameSource;
public function __construct()
{
$this->nameSource = new NameSource();
parent::__construct();
}
}

View File

@ -3,11 +3,11 @@
namespace App\Entity\Source\Data;
use App\Entity\Attribut\UserAttributInterface;
use App\Entity\Attribut\NameSourceAttributInterface;
use App\Entity\Attribut\PersonIdentitySourceAttributInterface;
/**
* @author kevinfrantz
*/
interface UserSourceInterface extends DataSourceInterface, UserAttributInterface, NameSourceAttributInterface
interface UserSourceInterface extends DataSourceInterface, UserAttributInterface, PersonIdentitySourceAttributInterface
{
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity\Source\Data\Name;
use App\Entity\Source\Data\AbstractDataSource;
@ -6,4 +7,3 @@ use App\Entity\Source\Data\AbstractDataSource;
class AbstractNameSource extends AbstractDataSource implements NameSourceInterface
{
}

View File

@ -1,7 +1,7 @@
<?php
namespace App\Entity\Source\Data\Name;
interface FirstNameSourceInterface extends NameSourceInterface
{
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity\Source\Data\Name;
use App\Entity\Source\Data\DataSourceInterface;

View File

@ -19,6 +19,7 @@ final class NicknameSource extends AbstractNameSource implements NicknameSourceI
* @todo Implement an extra assert Layer!
* @ORM\Column(type="string",length=255)
* @Assert\NotBlank()
*
* @var string
*/
protected $name;

View File

@ -1,7 +1,7 @@
<?php
namespace App\Entity\Source\Data\Name;
interface SurnameSourceInterface extends NameSourceInterface
{
}

View File

@ -0,0 +1,39 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\Combination\FullPersonNameSourceInterface;
use App\Entity\Attribut\FullPersonNameSourceAttributInterface;
use App\Entity\Attribut\FullPersonNameSourceAttribut;
/**
* @author kevinfrantz
*/
class FullPersonNameSourceAttributTest extends TestCase
{
/**
* @var FullPersonNameSourceAttributInterface
*/
protected $fullname;
public function setUp(): void
{
$this->fullname = new class() implements FullPersonNameSourceAttributInterface {
use FullPersonNameSourceAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->fullname->getFullPersonNameSource();
}
public function testAccessors(): void
{
$fullname = $this->createMock(FullPersonNameSourceInterface::class);
$this->assertNull($this->fullname->setFullPersonNameSource($fullname));
$this->assertEquals($collection, $this->fullname->getFullPersonNameSource());
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\PersonIdentitySourceAttributInterface;
use Entity\Attribut\PersonIdentityAttribut;
use App\Entity\Source\Data\PersonIdentitySourceInterface;
/**
* @todo Implement abstract test class for entity attributs
*
* @author kevinfrantz
*/
class PersonIdentitySourceAttributTest extends TestCase
{
/**
* @var PersonIdentitySourceAttributInterface
*/
protected $identity;
public function setUp(): void
{
$this->identity = new class() implements PersonIdentitySourceAttributInterface {
use PersonIdentityAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->identity->getIdentitySource();
}
public function testAccessors(): void
{
$identity = $this->createMock(PersonIdentitySourceInterface::class);
$this->assertNull($this->identity->setIdentitySource($identity));
$this->assertEquals($collection, $this->identity->getIdentitySource());
}
}

View File

@ -1,12 +1,12 @@
<?php
namespace tests\unit\Entity\Source\Data;
namespace tests\unit\Entity\Source\Combination;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\Data\UserSourceInterface;
use App\Entity\Source\Data\UserSource;
use Doctrine\Common\Collections\Collection;
use App\Entity\Source\Data\NameSourceInterface;
use App\Entity\Source\Data\PersonIdentitySourceInterface;
class UserSourceTest extends TestCase
{
@ -23,7 +23,7 @@ class UserSourceTest extends TestCase
public function testConstructor(): void
{
$this->assertInstanceOf(Collection::class, $this->userSource->getMemberships());
$this->assertInstanceOf(NameSourceInterface::class, $this->userSource->getNameSource());
$this->assertInstanceOf(PersonIdentitySourceInterface::class, $this->userSource->getIdentitySource());
$this->expectException(\TypeError::class);
$this->userSource->getUser();
}

View File

@ -1,4 +1,5 @@
<?php
namespace tests\unit\Entity\Source\Data;
use PHPUnit\Framework\TestCase;
@ -13,18 +14,20 @@ class IdentitySourceTest extends TestCase
*/
protected $identity;
public function setUp():void{
public function setUp(): void
{
$this->identity = new IdentitySource();
}
public function testConstructor():void{
public function testConstructor(): void
{
$this->assertInstanceOf(FullPersonNameSourceInterface::class, $this->identity->getName());
}
public function testName():void{
public function testName(): void
{
$name = $this->createMock(FullPersonNameSourceInterface::class);
$this->assertNull($this->identity->setName($name));
$this->assertEquals($name, $this->identity->getName());
}
}