Skip to content

Commit

Permalink
Merge branch 'UML-3394-combined-lpa-manager' of github.com:ministryof…
Browse files Browse the repository at this point in the history
…justice/opg-use-an-lpa into UML-3394-combined-lpa-manager
  • Loading branch information
nickdavis2001 committed Dec 17, 2024
2 parents b9e4a9f + 524ca92 commit 87da09d
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 409 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;
use InvalidArgumentException;
use Rector\Configuration\Option;

#[Attribute(Attribute::TARGET_PARAMETER)]
class CastToLifeSustainingTreatment implements PropertyCaster
Expand All @@ -24,6 +25,10 @@ public function cast(mixed $value, ObjectMapper $hydrator): mixed
};
}

if ($value instanceof LifeSustainingTreatment) {
return $value->value;
}

return LifeSustainingTreatment::from($value)->value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

declare(strict_types=1);

namespace CommonTest\Entity\Sirius;
namespace CommonTest\Entity;

use Common\Entity\Sirius\SiriusLpa;
use Common\Entity\Sirius\SiriusLpaAttorney;
use Common\Entity\Sirius\SiriusLpaDonor;
use Common\Entity\Sirius\SiriusLpaTrustCorporations;
use Common\Entity\CombinedLpa;
use Common\Entity\Person;
use Common\Enum\HowAttorneysMakeDecisions;
use Common\Enum\WhenTheLpaCanBeUsed;
use Common\Service\Lpa\Factory\LpaDataFormatter;
Expand All @@ -17,7 +15,7 @@
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

class CanHydrateSiriusToCombinedFormatTest extends TestCase
class CanHydrateCombinedLpaTest extends TestCase
{
use ProphecyTrait;

Expand All @@ -28,108 +26,114 @@ public function setUp(): void
$this->lpaDataFormatter = new LpaDataFormatter();
}

public function expectedSiriusLpa(): SiriusLpa
public function expectedSiriusLpa(): CombinedLpa
{
$donor = new SiriusLpaDonor(
$donor = new Person(
addressLine1 : '81 Front Street',
addressLine2 : 'LACEBY',
addressLine3 : '',
country : '',
county : '',
dob : new DateTimeImmutable('1948-11-01'),
email : '[email protected]',
firstname : 'Rachel',
firstnames : null,
linked : [
[
'id' => 7,
'uId' => '700000000799',
],
],
name : null,
otherNames : null,
otherNames : 'Ezra',
postcode : 'DN37 5SH',
surname : 'Sanderson',
systemStatus : null,
town : '',
type : 'Primary',
uId : '700000000799'
);

$attorneys = [
new SiriusLpaAttorney(
new Person(
addressLine1 : '9 high street',
addressLine2 : '',
addressLine3 : '',
country : '',
county : '',
dob : new DateTimeImmutable('1990-05-04'),
email : '',
firstname : 'jean',
firstnames : null,
name : null,
otherNames : null,
postcode : 'DN37 5SH',
surname : 'sanderson',
systemStatus : '1',
town : '',
type : 'Primary',
uId : '700000000815'
),
new SiriusLpaAttorney(
new Person(
addressLine1 : '',
addressLine2 : '',
addressLine3 : '',
country : '',
county : '',
dob : new DateTimeImmutable('1975-10-05'),
email : 'XXXXX',
firstname : 'Ann',
firstnames : null,
name : null,
otherNames : null,
postcode : '',
surname : 'Summers',
systemStatus : '1',
town : '',
type : 'Primary',
uId : '7000-0000-0849'
),
];

$trustCorporations = [
new SiriusLpaTrustCorporations(
new Person(
addressLine1 : 'Street 1',
addressLine2 : 'Street 2',
addressLine3 : 'Street 3',
country : 'GB',
county : 'County',
dob : null,
email : null,
firstname : 'trust',
firstnames : null,
name : 'trust corporation',
otherNames : null,
postcode : 'ABC 123',
surname : 'test',
systemStatus : '1',
town : 'Town',
type : 'Primary',
uId : '7000-0015-1998',
),
];

return EntityTestHelper::makeSiriusLpa(
$replacementAttorneys = [
new Person(
addressLine1 : 'Address Line 1',
addressLine2 : 'Address Line 2',
addressLine3 : 'Address Line 3',
country : 'Country',
county : 'County',
dob : new DateTimeImmutable('2000-01-31'),
email : '[email protected]',
firstnames : 'Firstnames',
name : 'Name',
otherNames : 'Other names',
postcode : 'Postcode',
surname : 'Surname',
systemStatus : '1',
town : 'Town',
uId : '7000-0000-0849',
),
];

return EntityTestHelper::makeCombinedLpa(
attorneys: $attorneys,
channel: null,
donor: $donor,
howAttorneysMakeDecisions: HowAttorneysMakeDecisions::JOINTLY_AND_SEVERALLY,
howAttorneysMakeDecisions: null,
lpaDonorSignatureDate: new DateTimeImmutable('2012-12-12'),
lpaIsCleansed: true,
onlineLpaId: 'A33718377316',
receiptDate: new DateTimeImmutable('2014-09-26'),
registrationDate: new DateTimeImmutable('2019-10-10'),
replacementAttorneys: [],
replacementAttorneys: $replacementAttorneys,
trustCorporations: $trustCorporations,
uId: '700000000047',
whenTheLpaCanBeUsed: WhenTheLpaCanBeUsed::WHEN_HAS_CAPACITY,
Expand All @@ -139,7 +143,7 @@ public function expectedSiriusLpa(): SiriusLpa
#[Test]
public function can_hydrate_sirius_lpa_to_modernise_format(): void
{
$lpa = json_decode(file_get_contents(__DIR__ . '../../../../../test/fixtures/test_lpa.json'), true);
$lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/combined_lpa.json'), true);

$expectedSiriusLpa = $this->expectedSiriusLpa();

Expand Down

This file was deleted.

19 changes: 15 additions & 4 deletions service-front/app/test/CommonTest/Entity/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ public function setUp(): void
#[Test]
public function can_test_getters()
{
$lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/test_lpa.json'), true);
$lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/combined_lpa.json'), true);
$combinedLpa = ($this->lpaDataFormatter)($lpa);

$expectedSalutation = '';
$expectedFirstname = 'Rachel';
$expectedMiddlename = '';
$expectedSurname = 'Sanderson';
$expectedDob = new DateTimeImmutable('1948-11-01');
$expectedCompanyName = 'trust corporation';
$expectedUid = '700000000799';

$this->assertEquals($expectedSalutation, $combinedLpa->getDonor()->getSalutation());
$this->assertEquals($expectedFirstname, $combinedLpa->getDonor()->getFirstname());
$this->assertEquals($expectedMiddlename, $combinedLpa->getDonor()->getMiddlenames());
$this->assertEquals($expectedSurname, $combinedLpa->getDonor()->getSurname());
$this->assertEquals($expectedDob, $combinedLpa->getDonor()->getDob());
Expand All @@ -50,6 +48,19 @@ public function can_test_getters()
#[Test]
public function wraps_address_in_array_for_compatability()
{
$person = EntityTestHelper::MakePerson();

$addresses = [
(new Address())
->setAddressLine1($person->getAddressLine1())
->setAddressLine2($person->getAddressLine2())
->setAddressLine3($person->getAddressLine3())
->setTown($person->getTown())
->setPostcode($person->getPostcode())
->setCounty($person->getCounty())
->setCountry($person->getCountry()),
];

$this->assertEquals(
[
(new Address())
Expand All @@ -61,7 +72,7 @@ public function wraps_address_in_array_for_compatability()
->setCounty('County')
->setCountry('Country'),
],
EntityTestHelper::MakePerson()->getAddresses()
$addresses
);
}
}
Loading

0 comments on commit 87da09d

Please sign in to comment.