This repository has been archived by the owner on Apr 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
461 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Opg\Common\Model\Entity; | ||
|
||
use JMS\Serializer\Serializer; | ||
use Opg\Core\Model\Entity\LegalEntity\LegalEntity; | ||
|
||
/** | ||
* Interface FactoryInterface | ||
* @package Opg\Common\Model\Entity | ||
*/ | ||
interface FactoryInterface | ||
{ | ||
/** | ||
* @param array $data | ||
* @param Serializer $serializer | ||
* @return LegalEntity | ||
* @throws \Exception | ||
*/ | ||
public static function create(array $data, Serializer $serializer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Opg\Core\Model\Entity\CaseItem; | ||
|
||
use JMS\Serializer\Serializer; | ||
use Opg\Common\Model\Entity\FactoryInterface; | ||
use Opg\Core\Model\Entity\LegalEntity\LegalEntity; | ||
|
||
/** | ||
* Class CaseItemFactory | ||
* @package Opg\Core\Model\Entity\CaseItem | ||
*/ | ||
class CaseItemFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @param array $data | ||
* @param Serializer $serializer | ||
* @return LegalEntity | ||
* @throws \Exception | ||
*/ | ||
public static function create(array $data, Serializer $serializer) | ||
{ | ||
$caseType = null; | ||
$data['caseType'] = (isset($data['caseType'])) ? $data['caseType'] : 'Lpa'; | ||
|
||
if (!empty($data['caseType'])) { | ||
switch ($data['caseType']) { | ||
case "Epa" : | ||
$caseType = "Opg\\Core\\Model\\Entity\\CaseItem\\PowerOfAttorney\\Epa"; | ||
break; | ||
case "Order" : | ||
$caseType = "Opg\\Core\\Model\\Entity\\CaseItem\\Deputyship\\Order"; | ||
break; | ||
default: | ||
$caseType = "Opg\\Core\\Model\\Entity\\CaseItem\\PowerOfAttorney\\Lpa"; | ||
break; | ||
} | ||
} else { | ||
throw new \Exception('Cannot build unknown case type.'); | ||
} | ||
|
||
try { | ||
/** @var CaseItem $case */ | ||
$case = $serializer->deserialize( | ||
json_encode($data), | ||
$caseType, | ||
'json' | ||
); | ||
} catch (\Exception $e) { | ||
throw $e; | ||
} | ||
|
||
return $case; | ||
} | ||
} |
267 changes: 267 additions & 0 deletions
267
tests/OpgTest/Core/Model/Entity/CaseActor/PersonFactoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
<?php | ||
|
||
namespace OpgTest\Core\Model\Entity\CaseActor; | ||
|
||
|
||
use JMS\Serializer\Serializer; | ||
use Opg\Core\Model\Entity\CaseActor\Attorney; | ||
use Opg\Core\Model\Entity\CaseActor\CertificateProvider; | ||
use Opg\Core\Model\Entity\CaseActor\Client; | ||
use Opg\Core\Model\Entity\CaseActor\Correspondent; | ||
use Opg\Core\Model\Entity\CaseActor\Deputy; | ||
use Opg\Core\Model\Entity\CaseActor\Donor; | ||
use Opg\Core\Model\Entity\CaseActor\FeePayer; | ||
use Opg\Core\Model\Entity\CaseActor\NonCaseContact; | ||
use Opg\Core\Model\Entity\CaseActor\NotifiedAttorney; | ||
use Opg\Core\Model\Entity\CaseActor\NotifiedPerson; | ||
use Opg\Core\Model\Entity\CaseActor\NotifiedRelative; | ||
use Opg\Core\Model\Entity\CaseActor\PersonFactory; | ||
use Opg\Core\Model\Entity\CaseActor\PersonNotifyDonor; | ||
use Opg\Core\Model\Entity\CaseActor\ReplacementAttorney; | ||
use Opg\Core\Model\Entity\CaseActor\TrustCorporation; | ||
|
||
class PersonFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var \Mockery\MockInterface */ | ||
protected $serializer; | ||
|
||
public function setUp() | ||
{ | ||
$this->serializer = \Mockery::mock("JMS\Serializer\Serializer"); | ||
} | ||
|
||
/** | ||
* @expectedException \Exception | ||
*/ | ||
public function testEmptyTypeThrowsException() | ||
{ | ||
$data = array('personType' => '', 'id' => 1); | ||
PersonFactory::create($data, $this->serializer); | ||
} | ||
|
||
/** | ||
* @expectedException \Exception | ||
*/ | ||
public function testUnknownIdReturnsNull() | ||
{ | ||
$data = array('personType' => 'Donor', 'id' => -1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andThrow(new \Exception()); | ||
|
||
PersonFactory::create($data, $this->serializer); | ||
} | ||
|
||
public function testUnknownTypeReturnsNonCaseContact() | ||
{ | ||
$data = array('personType' => 'Doctor', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new NonCaseContact())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof NonCaseContact); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testNoPersonTypeReturnsDonor() | ||
{ | ||
$data = array('id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new Donor())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof Donor); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testAttorney() | ||
{ | ||
$data = array('personType' => 'Attorney', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new Attorney())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof Attorney); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testReplacementAttorney() | ||
{ | ||
$data = array('personType' => 'ReplacementAttorney', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new ReplacementAttorney())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof ReplacementAttorney); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testTrustCorporation() | ||
{ | ||
$data = array('personType' => 'TrustCorporation', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new TrustCorporation())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof TrustCorporation); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testCertificateProvider() | ||
{ | ||
$data = array('personType' => 'CertificateProvider', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new CertificateProvider())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof CertificateProvider); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testNotifiedPerson() | ||
{ | ||
$data = array('personType' => 'NotifiedPerson', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new NotifiedPerson())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof NotifiedPerson); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testCorrespondent() | ||
{ | ||
$data = array('personType' => 'Correspondent', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new Correspondent())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof Correspondent); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testNotifiedRelative() | ||
{ | ||
$data = array('personType' => 'NotifiedRelative', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new NotifiedRelative())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof NotifiedRelative); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testNotifiedAttorney() | ||
{ | ||
$data = array('personType' => 'NotifiedAttorney', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new NotifiedAttorney())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof NotifiedAttorney); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testPersonNotifyDonor() | ||
{ | ||
$data = array('personType' => 'PersonNotifyDonor', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new PersonNotifyDonor())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof PersonNotifyDonor); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testClient() | ||
{ | ||
$data = array('personType' => 'Client', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new Client())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof Client); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testDeputy() | ||
{ | ||
$data = array('personType' => 'Deputy', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new Deputy())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof Deputy); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
public function testFeePayer() | ||
{ | ||
$data = array('personType' => 'FeePayer', 'id' => 1); | ||
|
||
$this->serializer | ||
->shouldReceive('deserialize') | ||
->withAnyArgs() | ||
->andReturn((new FeePayer())->setId($data['id'])); | ||
|
||
$person = PersonFactory::create($data, $this->serializer); | ||
|
||
$this->assertTrue($person instanceof FeePayer); | ||
$this->assertEquals($data['id'], $person->getId()); | ||
} | ||
|
||
} |
Oops, something went wrong.