Skip to content

Commit

Permalink
UML-3620 added a new test - CombinedLpaHasActorTraitTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
allenannom committed Oct 9, 2024
1 parent c21f94f commit 57cbe20
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ public function hasActor(string $uid): ?LpaActor

private function isADonor(string $uid): ?LpaActor
{
foreach ($this->getDonor()['linked'] as $value) {
if ((string) $value['id'] === $uid || $value['uId'] === $uid) {
$linkedDonors = $this->getDonor()->linked ?? $this->getDonor()['linked'];

foreach ($linkedDonors as $linkedDonor) {
$linkedDonorId = $linkedDonor->id ?? $linkedDonor['id'];
$linkedDonorUid = $linkedDonor->uId ?? $linkedDonor['uId'];

if ((string) $linkedDonorId === $uid || $linkedDonorUid === $uid) {
return new LpaActor($this->getDonor(), ActorType::DONOR);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
<?php

declare(strict_types=1);

namespace AppTest\Service\Lpa\ResolveActor;

use App\Entity\Sirius\SiriusLpa;
use App\Enum\LifeSustainingTreatment;
use App\Enum\LpaType;
use App\Service\Lpa\ResolveActor\ActorType;
use App\Service\Lpa\ResolveActor\HasActorInterface;
use App\Service\Lpa\ResolveActor\LpaActor;
use App\Service\Lpa\ResolveActor\SiriusHasActorTrait;
use App\Service\Lpa\SiriusPerson;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class CombinedLpaHasActorTraitTest extends TestCase
{
private HasActorInterface $mock;

public function setUp(): void
{
$this->mock = new SiriusLpa(
$applicationHasGuidance = false,
$applicationHasRestrictions = false,
$applicationType = 'Classic',
$attorneyActDecisions = null,
$attorneys = [
[
'addressLine1' => '9 high street',
'addressLine2' => '',
'addressLine3' => '',
'country' => '',
'county' => '',
'dob' => null,
'email' => '',
'firstname' => 'A',
'firstnames' => null,
'name' => null,
'otherNames' => null,
'postcode' => 'DN37 5SH',
'surname' => 'B',
'systemStatus' => '1',
'town' => '',
'type' => 'Primary',
'uId' => '345678901',
],
[
'addressLine1' => '',
'addressLine2' => '',
'addressLine3' => '',
'country' => '',
'county' => '',
'dob' => null,
'email' => 'XXXXX',
'firstname' => 'B',
'firstnames' => null,
'name' => null,
'otherNames' => null,
'postcode' => '',
'surname' => 'C',
'systemStatus' => '1',
'town' => '',
'type' => 'Primary',
'uId' => '456789012',
],
[
'addressLine1' => '',
'addressLine2' => '',
'addressLine3' => '',
'country' => '',
'county' => '',
'dob' => null,
'email' => 'XXXXX',
'firstname' => 'C',
'firstnames' => null,
'name' => null,
'otherNames' => null,
'postcode' => '',
'surname' => 'D',
'systemStatus' => '1',
'town' => '',
'type' => 'Primary',
'uId' => '567890123',
],
],
$caseSubtype = LpaType::fromShortName('personal-welfare'),
$channel = null,
$dispatchDate = null,
$donor = (object)[
'addressLine1' => '81 Front Street',
'addressLine2' => 'LACEBY',
'addressLine3' => '',
'country' => '',
'county' => '',
'dob' => null,
'email' => '[email protected]',
'firstname' => 'Rachel',
'firstnames' => null,
'name' => null,
'otherNames' => null,
'postcode' => 'DN37 5SH',
'surname' => 'Sanderson',
'systemStatus' => null,
'town' => '',
'type' => 'Primary',
'uId' => '123456789',
'linked' => [
[
'id' => 1,
'uId' => '123456789',
],
[
'id' => 2,
'uId' => '234567890',
],
],
],
$hasSeveranceWarning = null,
$invalidDate = null,
$lifeSustainingTreatment = LifeSustainingTreatment::fromShortName('Option A'),
$lpaDonorSignatureDate = new DateTimeImmutable('2012-12-12'),
$lpaIsCleansed = true,
$onlineLpaId = 'A33718377316',
$receiptDate = new DateTimeImmutable('2014-09-26'),
$registrationDate = new DateTimeImmutable('2019-10-10'),
$rejectedDate = null,
$replacementAttorneys = [],
$status = 'Registered',
$statusDate = null,
$trustCorporations = [
[
'addressLine1' => 'Street 1',
'addressLine2' => 'Street 2',
'addressLine3' => 'Street 3',
'country' => 'GB',
'county' => 'County',
'dob' => null,
'email' => null,
'firstname' => 'trust',
'firstnames' => null,
'name' => 'A',
'otherNames' => null,
'postcode' => 'ABC 123',
'surname' => 'test',
'systemStatus' => '1',
'town' => 'Town',
'type' => 'Primary',
'uId' => '678901234',
],
[
'addressLine1' => 'Street 1',
'addressLine2' => 'Street 2',
'addressLine3' => 'Street 3',
'country' => 'GB',
'county' => 'County',
'dob' => null,
'email' => null,
'firstname' => 'trust',
'firstnames' => null,
'name' => 'B',
'otherNames' => null,
'postcode' => 'ABC 123',
'surname' => 'test',
'systemStatus' => '1',
'town' => 'Town',
'type' => 'Primary',
'uId' => '789012345',
],
],
$uId = '700000000047',
$withdrawnDate = null
);
}

#[Test]
public function does_not_find_nonexistant_actor(): void
{
$result = $this->mock->hasActor('012345678');

$this->assertNull($result);
}

#[Test]
public function finds_a_donor_actor(): void
{
$result = $this->mock->hasActor('123456789');

$this->assertInstanceOf(LpaActor::class, $result);
$this->assertEquals(ActorType::DONOR, $result->actorType);
}

#[Test]
public function finds_an_attorney_actor(): void
{
$result = $this->mock->hasActor('456789012');

$this->assertInstanceOf(LpaActor::class, $result);
$this->assertEquals('B', $result->actor['firstname']);
$this->assertEquals(ActorType::ATTORNEY, $result->actorType);
}

#[Test]
public function finds_a_trust_corporation_actor(): void
{
$result = $this->mock->hasActor('789012345');

$this->assertInstanceOf(LpaActor::class, $result);
$this->assertEquals('B', $result->actor['name']);
$this->assertEquals(ActorType::TRUST_CORPORATION, $result->actorType);
}
}

0 comments on commit 57cbe20

Please sign in to comment.