diff --git a/service-api/app/features/context/Integration/LpaContext.php b/service-api/app/features/context/Integration/LpaContext.php index 48dbca0370..fa7d4809d0 100644 --- a/service-api/app/features/context/Integration/LpaContext.php +++ b/service-api/app/features/context/Integration/LpaContext.php @@ -22,6 +22,7 @@ use App\Service\Lpa\FindActorInLpa\ActorMatch; use App\Service\Lpa\GetInstructionsAndPreferencesImages; use App\Service\Lpa\RemoveLpa; +use App\Service\Lpa\SiriusLpa; use App\Service\Lpa\SiriusLpaManager; use App\Service\Lpa\SiriusPerson; use App\Service\ViewerCodes\ViewerCodeService; @@ -41,6 +42,7 @@ use PHPUnit\Framework\Assert; use PHPUnit\Framework\ExpectationFailedException; use Psr\Http\Message\RequestInterface; +use Psr\Log\LoggerInterface; use stdClass; use function PHPUnit\Framework\assertEquals; @@ -386,13 +388,22 @@ public function iProvideTheAttorneyDetailsFromAValidPaperLPADocument(): void $lpaMatchResponse = $addOlderLpa->validateRequest($this->userId, $data); $expectedLpaArray = json_decode(json_encode($this->lpa), true); - $expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray); + $expectedLpa = new SiriusLpa($expectedLpaArray, $this->container->get(LoggerInterface::class)); $expectedResponse = new AccessForAllValidation( new ActorMatch( - new SiriusPerson(json_decode(json_encode($this->lpa->attorneys[0]), true)), + new SiriusPerson( + json_decode( + json_encode( + $this->lpa->attorneys[0] + ), + true + ), + $this->container->get(LoggerInterface::class), + ), 'attorney', - $this->lpa->uId), - $expectedLpa, + $this->lpa->uId, + ), + $expectedLpa, null, ); @@ -1594,13 +1605,20 @@ public function iConfirmDetailsShownToMeOfTheFoundLPAAreCorrect(): void $lpaMatchResponse = $addOlderLpa->validateRequest($this->userId, $data); $expectedLpaArray = json_decode(json_encode($this->lpa), true); - $expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray); + $expectedLpa = new SiriusLpa($expectedLpaArray, $this->container->get(LoggerInterface::class)); $expectedResponse = new AccessForAllValidation( new ActorMatch( - new SiriusPerson(json_decode(json_encode($lpa->donor), true)), + new SiriusPerson( + json_decode( + json_encode($lpa->donor), + true + ), + $this->container->get(LoggerInterface::class), + ), 'donor', - $lpa->uId), - $expectedLpa, + $lpa->uId, + ), + $expectedLpa, null, ); @@ -1823,68 +1841,6 @@ public function iProvideDetailsThatDoNotMatchThePaperDocument($firstnames, $last throw new ExpectationFailedException('LPA should not have matched data provided'); } - /** - * @When /^I provide details "([^"]*)" "([^"]*)" "([^"]*)" "([^"]*)" that match a valid paper document$/ - */ - public function iProvideDetailsThatMatchAValidPaperDocument($firstnames, $lastname, $postcode, $dob) - { - $this->lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/test_lpa.json')); - - $this->lpa->donor->firstname = 'Rachel'; - $this->lpa->donor->surname = 'S’anderson'; - - $data = [ - 'reference_number' => (int) $this->lpaUid, - 'dob' => $dob, - 'postcode' => $postcode, - 'first_names' => $firstnames, - 'last_name' => $lastname, - 'force_activation_key' => false, - ]; - - //UserLpaActorMap: getAllForUser - $this->awsFixtures->append( - new Result([]) - ); - - $this->pactGetInteraction( - $this->apiGatewayPactProvider, - '/v1/use-an-lpa/lpas/' . $this->lpaUid, - StatusCodeInterface::STATUS_OK, - $this->lpa - ); - - $codeExists = new stdClass(); - $codeExists->Created = null; - - $this->pactPostInteraction( - $this->codesApiPactProvider, - '/v1/exists', - [ - 'lpa' => $this->lpa->uId, - 'actor' => $this->lpa->donor->uId, - ], - StatusCodeInterface::STATUS_OK, - $codeExists - ); - - $addAccessForAllLpa = $this->container->get(AddAccessForAllLpa::class); - $lpaMatchResponse = $addAccessForAllLpa->validateRequest($this->userId, $data); - - $expectedLpaArray = json_decode(json_encode($this->lpa), true); - $expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray); - $expectedResponse = new AccessForAllValidation( - new ActorMatch( - new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)), - 'donor', - $this->lpa->uId), - $expectedLpa, - null - ); - - Assert::assertEquals($expectedResponse, $lpaMatchResponse); - } - /** * @When /^I provide the details from a valid paper LPA document$/ */ @@ -1932,13 +1888,20 @@ public function iProvideTheDetailsFromAValidPaperLPADocument(): void $lpaMatchResponse = $addOlderLpa->validateRequest($this->userId, $data); $expectedLpaArray = json_decode(json_encode($this->lpa), true); - $expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray); + $expectedLpa = new SiriusLpa($expectedLpaArray, $this->container->get(LoggerInterface::class)); $expectedResponse = new AccessForAllValidation( new ActorMatch( - new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)), + new SiriusPerson( + json_decode( + json_encode($this->lpa->donor), + true + ), + $this->container->get(LoggerInterface::class) + ), 'donor', - $this->lpa->uId), - $expectedLpa, + $this->lpa->uId, + ), + $expectedLpa, null ); @@ -1971,7 +1934,7 @@ public function iProvideTheDetailsFromAValidPaperDocumentThatAlreadyHasAnActivat $this->lpa ); - $codeExists = new stdClass(); + $codeExists = new stdClass(); $createdDate = (new DateTime())->modify('-14 days'); $activationKeyDueDate = DateTimeImmutable::createFromMutable($createdDate); @@ -2001,11 +1964,19 @@ public function iProvideTheDetailsFromAValidPaperDocumentThatAlreadyHasAnActivat Assert::assertEquals('LPA has an activation key already', $ex->getMessage()); Assert::assertEquals( [ - 'donor' => new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)), + 'donor' => new SiriusPerson( + json_decode( + json_encode( + $this->lpa->donor + ), + true + ), + $this->container->get(LoggerInterface::class), + ), 'caseSubtype' => $this->lpa->caseSubtype, 'activationKeyDueDate' => $activationKeyDueDate, ], - $ex->getAdditionalData() + $ex->getAdditionalData(), ); return; } @@ -2733,13 +2704,20 @@ public function iRequestForANewActivationKeyAgain(): void $response = $addOlderLpa->validateRequest($this->userId, $data); $expectedLpaArray = json_decode(json_encode($this->lpa), true); - $expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray); + $expectedLpa = new SiriusLpa($expectedLpaArray, $this->container->get(LoggerInterface::class)); $expectedResponse = new AccessForAllValidation( new ActorMatch( - new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)), + new SiriusPerson( + json_decode( + json_encode($this->lpa->donor), + true + ), + $this->container->get(LoggerInterface::class) + ), 'donor', - $this->lpa->uId), - $expectedLpa, + $this->lpa->uId, + ), + $expectedLpa, null ); diff --git a/service-api/app/src/App/src/DataAccess/ApiGateway/SiriusLpas.php b/service-api/app/src/App/src/DataAccess/ApiGateway/SiriusLpas.php index 474e89ad0d..b3a3d2df46 100644 --- a/service-api/app/src/App/src/DataAccess/ApiGateway/SiriusLpas.php +++ b/service-api/app/src/App/src/DataAccess/ApiGateway/SiriusLpas.php @@ -141,6 +141,7 @@ public function lookup(array $uids): array $results[$uid] = new Lpa( new SiriusLpa( $this->sanitiser->sanitise($response), + $this->logger, ), new DateTimeImmutable($result->getHeaderLine('Date')) ); diff --git a/service-api/app/src/App/src/Service/Lpa/SiriusLpa.php b/service-api/app/src/App/src/Service/Lpa/SiriusLpa.php index d59961b406..1324aee4db 100644 --- a/service-api/app/src/App/src/Service/Lpa/SiriusLpa.php +++ b/service-api/app/src/App/src/Service/Lpa/SiriusLpa.php @@ -12,6 +12,7 @@ use ArrayAccess; use IteratorAggregate; use JsonSerializable; +use Psr\Log\LoggerInterface; use Traversable; /** @@ -29,7 +30,7 @@ class SiriusLpa implements { use SiriusHasActorTrait; - public function __construct(private array $lpa) + public function __construct(private array $lpa, private LoggerInterface $logger) { if ($this->lpa['donor'] !== null) { $donorAsSiriusPerson = $this->convertToSiriusPerson($this->lpa['donor']); @@ -68,7 +69,7 @@ private function convertToSiriusPerson(SiriusPerson|array $entity): SiriusPerson { return $entity instanceof SiriusPerson ? $entity - : new SiriusPerson($entity); + : new SiriusPerson($entity, $this->logger); } private function getTrustCorporations(): array @@ -78,16 +79,34 @@ private function getTrustCorporations(): array public function offsetExists(mixed $offset): bool { + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); + $this->logger->debug( + 'Use of SiriusLpa object as array (exists) in file ' + . $trace[0]['file'] . ' on line ' . $trace[0]['line'] + ); + return isset($this->lpa[$offset]); } public function offsetGet(mixed $offset): mixed { + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); + $this->logger->debug( + 'Use of SiriusLpa object as array (getter) in file ' + . $trace[0]['file'] . ' on line ' . $trace[0]['line'] + ); + return $this->lpa[$offset]; } public function offsetSet(mixed $offset, mixed $value): void { + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); + $this->logger->debug( + 'Use of SiriusLpa object as array (setter) in file ' + . $trace[0]['file'] . ' on line ' . $trace[0]['line'] + ); + $this->lpa[$offset] = $value; } diff --git a/service-api/app/src/App/src/Service/Lpa/SiriusPerson.php b/service-api/app/src/App/src/Service/Lpa/SiriusPerson.php index f9a090c2f7..03dc1f8a47 100644 --- a/service-api/app/src/App/src/Service/Lpa/SiriusPerson.php +++ b/service-api/app/src/App/src/Service/Lpa/SiriusPerson.php @@ -13,6 +13,7 @@ use DateTimeInterface; use IteratorAggregate; use JsonSerializable; +use Psr\Log\LoggerInterface; use Traversable; /** @@ -28,7 +29,7 @@ class SiriusPerson implements IteratorAggregate, JsonSerializable { - public function __construct(private array $person) + public function __construct(private array $person, private LoggerInterface $logger) { } @@ -87,16 +88,34 @@ public function getDob(): DateTimeInterface public function offsetExists(mixed $offset): bool { + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); + $this->logger->debug( + 'Use of SiriusPerson object as array (exists) in file ' + . $trace[0]['file'] . ' on line ' . $trace[0]['line'] + ); + return isset($this->person[$offset]); } public function offsetGet(mixed $offset): mixed { + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); + $this->logger->debug( + 'Use of SiriusPerson object as array (getter) in file ' + . $trace[0]['file'] . ' on line ' . $trace[0]['line'] + ); + return $this->person[$offset]; } public function offsetSet(mixed $offset, mixed $value): void { + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); + $this->logger->debug( + 'Use of SiriusPerson object as array (setter) in file ' + . $trace[0]['file'] . ' on line ' . $trace[0]['line'] + ); + $this->person[$offset] = $value; } diff --git a/service-api/app/test/AppTest/Service/ActorCodes/ActorCodeServiceTest.php b/service-api/app/test/AppTest/Service/ActorCodes/ActorCodeServiceTest.php index 6ffe824c9a..3c660dafca 100644 --- a/service-api/app/test/AppTest/Service/ActorCodes/ActorCodeServiceTest.php +++ b/service-api/app/test/AppTest/Service/ActorCodes/ActorCodeServiceTest.php @@ -215,6 +215,7 @@ private function initValidParameterSet(): array [ 'uId' => $testUid, ], + $this->loggerProphecy->reveal(), ); $mockActor = new LpaActor( diff --git a/service-api/app/test/AppTest/Service/ActorCodes/Validation/CodesApiValidationStrategyTest.php b/service-api/app/test/AppTest/Service/ActorCodes/Validation/CodesApiValidationStrategyTest.php index cc53075c71..a33736eaf1 100644 --- a/service-api/app/test/AppTest/Service/ActorCodes/Validation/CodesApiValidationStrategyTest.php +++ b/service-api/app/test/AppTest/Service/ActorCodes/Validation/CodesApiValidationStrategyTest.php @@ -71,6 +71,7 @@ public function it_will_validate_a_code(): void [ 'uId' => 'lpa-uid', ], + $this->loggerProphecy->reveal(), ), new DateTime('now') ); @@ -190,6 +191,7 @@ public function it_wont_validate_a_code_with_a_mismatched_actor(): void [ 'uId' => 'lpa-uid', ], + $this->loggerProphecy->reveal(), ), new DateTime('now') ); @@ -230,6 +232,7 @@ public function it_wont_validate_a_code_with_a_bad_dob(): void [ 'uId' => 'lpa-uid', ], + $this->loggerProphecy->reveal(), ), new DateTime('now') ); @@ -342,6 +345,7 @@ public function it_wont_validate_a_code_with_a_bad_dob_for_trust_corporation(): ], 'uId' => 'lpa-uid', ], + $this->loggerProphecy->reveal(), ), new DateTime('now') ); diff --git a/service-api/app/test/AppTest/Service/Lpa/AddAccessForAllLpaTest.php b/service-api/app/test/AppTest/Service/Lpa/AddAccessForAllLpaTest.php index 5c9835c48d..f0b17d3dd3 100644 --- a/service-api/app/test/AppTest/Service/Lpa/AddAccessForAllLpaTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/AddAccessForAllLpaTest.php @@ -238,7 +238,8 @@ public function older_lpa_lookup_successful_if_lpa_already_requested_but_force_f 'firstname' => 'Donor', 'middlenames' => 'Example', 'surname' => 'Person', - ] + ], + $this->loggerProphecy->reveal(), ), 'donor', (string) $this->lpaUid, @@ -299,6 +300,7 @@ public function older_lpa_lookup_throws_an_exception_if_lpa_registration_date_no 'registrationDate' => '2019-08-31', 'status' => 'Registered', ], + $this->loggerProphecy->reveal(), ), new DateTime() ); @@ -333,6 +335,7 @@ public function older_lpa_lookup_throws_an_exception_if_lpa_status_not_registere 'registrationDate' => '2019-08-31', 'status' => 'Registered', ], + $this->loggerProphecy->reveal(), ), new DateTime() ); @@ -519,6 +522,7 @@ public function older_lpa_get_by_uid_response(): Lpa $attorney2, ], ], + $this->loggerProphecy->reveal(), ), new DateTime() ); diff --git a/service-api/app/test/AppTest/Service/Lpa/CheckLpaCleansedTest.php b/service-api/app/test/AppTest/Service/Lpa/CheckLpaCleansedTest.php index d3af46fa1b..932cf571c4 100644 --- a/service-api/app/test/AppTest/Service/Lpa/CheckLpaCleansedTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/CheckLpaCleansedTest.php @@ -53,9 +53,12 @@ public function older_lpa_add_confirmation_throws_an_exception_if_lpa_not_cleans ); $actorDetailsMatch = new ActorMatch( - new SiriusPerson([ - 'uId' => '700000000002', - ]), + new SiriusPerson( + [ + 'uId' => '700000000002', + ], + $this->loggerProphecy->reveal(), + ), '', '700000000001', ); @@ -83,9 +86,12 @@ public function older_lpa_add_confirmation_accepts_a_cleansed_lpa_and_registered ); $actorDetailsMatch = new ActorMatch( - new SiriusPerson([ - 'uId' => '700000000002', - ]), + new SiriusPerson( + [ + 'uId' => '700000000002', + ], + $this->loggerProphecy->reveal(), + ), '', '700000000001', ); @@ -111,9 +117,12 @@ public function older_lpa_add_confirmation_accepts_a_lpa_not_cleansed_and_regist ); $actorDetailsMatch = new ActorMatch( - new SiriusPerson([ - 'uId' => '700000000002', - ]), + new SiriusPerson( + [ + 'uId' => '700000000002', + ], + $this->loggerProphecy->reveal(), + ), '', '700000000001', ); @@ -139,9 +148,12 @@ public function older_lpa_add_confirmation_accepts_an_lpa_cleansed_and_registere ); $actorDetailsMatch = new ActorMatch( - new SiriusPerson([ - 'uId' => '700000000002', - ]), + new SiriusPerson( + [ + 'uId' => '700000000002', + ], + $this->loggerProphecy->reveal(), + ), '', '700000000001', ); diff --git a/service-api/app/test/AppTest/Service/Lpa/FindActorInLpaTest.php b/service-api/app/test/AppTest/Service/Lpa/FindActorInLpaTest.php index 363ecad043..2613bb54f8 100644 --- a/service-api/app/test/AppTest/Service/Lpa/FindActorInLpaTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/FindActorInLpaTest.php @@ -6,6 +6,7 @@ use App\Entity\LpaStore\LpaStoreDonor; use App\Entity\Person; +use App\Entity\Sirius\SiriusLpa as CombinedSiriusLpa; use App\Entity\Sirius\SiriusLpaAttorney; use App\Entity\Sirius\SiriusLpaDonor; use App\Service\Lpa\FindActorInLpa; @@ -15,6 +16,7 @@ use App\Service\Lpa\SiriusLpa; use App\Service\Lpa\SiriusPerson; use DateTimeImmutable; +use Monolog\Logger; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -50,6 +52,7 @@ public function returns_actor_and_lpa_details_if_match_found(?ActorMatch $expect $this->activeAttorneyFixtureOld(), ], ], + $this->loggerProphecy->reveal(), ); $this->getAttorneyStatusProphecy @@ -89,7 +92,7 @@ public function returns_actor_and_lpa_details_if_match_found_combined_sirius( $this->activeAttorneyFixture(), ]; - $lpa = new \App\Entity\Sirius\SiriusLpa( + $lpa = new CombinedSiriusLpa( applicationHasGuidance: null, applicationHasRestrictions: null, applicationType: null, @@ -141,16 +144,16 @@ public function returns_actor_and_lpa_details_if_match_found_combined_sirius( public static function actorLookupDataProviderOldSiriusPerson(): array { return self::actorLookupDataProvider( - FindActorInLpaTest::activeAttorneyFixtureOld(), - FindActorInLpaTest::donorFixtureOld() + self::activeAttorneyFixtureOld(), + self::donorFixtureOld() ); } public static function actorLookupDataProviderCombinedSirius(): array { return self::actorLookupDataProvider( - FindActorInLpaTest::activeAttorneyFixture(), - FindActorInLpaTest::donorFixture() + self::activeAttorneyFixture(), + self::donorFixture() ); } @@ -250,23 +253,26 @@ private static function actorLookupDataProvider( ]; } - public static function inactiveAttorneyFixtureOld(): SiriusPerson + private function inactiveAttorneyFixtureOld(): SiriusPerson { - return new SiriusPerson([ - 'uId' => '700000002222', - 'dob' => '1977-11-21', - 'firstname' => 'Attorneyone', - 'surname' => 'Person', - 'addresses' => [ - [ - 'postcode' => 'Gg1 2ff', + return new SiriusPerson( + [ + 'uId' => '700000002222', + 'dob' => '1977-11-21', + 'firstname' => 'Attorneyone', + 'surname' => 'Person', + 'addresses' => [ + [ + 'postcode' => 'Gg1 2ff', + ], ], + 'systemStatus' => false, // inactive attorney ], - 'systemStatus' => false, // inactive attorney - ]); + $this->loggerProphecy->reveal(), + ); } - public static function inactiveAttorneyFixture(): SiriusLpaAttorney + private function inactiveAttorneyFixture(): SiriusLpaAttorney { return new SiriusLpaAttorney( addressLine1: null, @@ -289,23 +295,26 @@ public static function inactiveAttorneyFixture(): SiriusLpaAttorney ); } - public static function ghostAttorneyFixtureOld(): SiriusPerson + private function ghostAttorneyFixtureOld(): SiriusPerson { - return new SiriusPerson([ - 'uId' => '700000003333', - 'dob' => '1960-05-05', - 'firstname' => '', // ghost attorney - 'surname' => '', - 'addresses' => [ - [ - 'postcode' => 'BB1 9ee', + return new SiriusPerson( + [ + 'uId' => '700000003333', + 'dob' => '1960-05-05', + 'firstname' => '', // ghost attorney + 'surname' => '', + 'addresses' => [ + [ + 'postcode' => 'BB1 9ee', + ], ], + 'systemStatus' => true, ], - 'systemStatus' => true, - ]); + $this->loggerProphecy->reveal(), + ); } - public static function ghostAttorneyFixture(): Person + private function ghostAttorneyFixture(): Person { return new SiriusLpaAttorney( addressLine1: null, @@ -328,42 +337,48 @@ public static function ghostAttorneyFixture(): Person ); } - public static function multipleAddressAttorneyFixtureOld(): SiriusPerson + private function multipleAddressAttorneyFixtureOld(): SiriusPerson { - return new SiriusPerson([ - 'uId' => '700000004444', - 'dob' => '1980-03-01', - 'firstname' => 'Attorneythree', - 'surname' => 'Person', - 'addresses' => [ // multiple addresses - [ - 'postcode' => 'Ab1 2Cd', - ], - [ - 'postcode' => 'Bc2 3Df', + return new SiriusPerson( + [ + 'uId' => '700000004444', + 'dob' => '1980-03-01', + 'firstname' => 'Attorneythree', + 'surname' => 'Person', + 'addresses' => [ // multiple addresses + [ + 'postcode' => 'Ab1 2Cd', + ], + [ + 'postcode' => 'Bc2 3Df', + ], ], + 'systemStatus' => true, ], - 'systemStatus' => true, - ]); + $this->loggerProphecy->reveal(), + ); } - public static function activeAttorneyFixtureOld(): SiriusPerson + private static function activeAttorneyFixtureOld(): SiriusPerson { - return new SiriusPerson([ - 'uId' => '700000001234', - 'dob' => '1980-03-01', - 'firstname' => 'Test', - 'surname' => 'T’esting', - 'addresses' => [ - [ - 'postcode' => 'Ab1 2Cd', + return new SiriusPerson( + [ + 'uId' => '700000001234', + 'dob' => '1980-03-01', + 'firstname' => 'Test', + 'surname' => 'T’esting', + 'addresses' => [ + [ + 'postcode' => 'Ab1 2Cd', + ], ], + 'systemStatus' => true, ], - 'systemStatus' => true, - ]); + new Logger('test-output'), + ); } - public static function activeAttorneyFixture(): SiriusLpaAttorney + private static function activeAttorneyFixture(): SiriusLpaAttorney { return new SiriusLpaAttorney( addressLine1: null, @@ -386,22 +401,25 @@ public static function activeAttorneyFixture(): SiriusLpaAttorney ); } - public static function donorFixtureOld(): SiriusPerson + private static function donorFixtureOld(): SiriusPerson { - return new SiriusPerson([ - 'uId' => '700000001111', - 'dob' => '1975-10-05', - 'firstname' => 'Donor', - 'surname' => 'Person', - 'addresses' => [ - [ - 'postcode' => 'PY1 3Kd', + return new SiriusPerson( + [ + 'uId' => '700000001111', + 'dob' => '1975-10-05', + 'firstname' => 'Donor', + 'surname' => 'Person', + 'addresses' => [ + [ + 'postcode' => 'PY1 3Kd', + ], ], ], - ]); + new Logger('test-output'), + ); } - public static function donorFixture(): SiriusLpaDonor + private static function donorFixture(): SiriusLpaDonor { return new SiriusLpaDonor( addressLine1: null, diff --git a/service-api/app/test/AppTest/Service/Lpa/GetAttorneyStatusTest.php b/service-api/app/test/AppTest/Service/Lpa/GetAttorneyStatusTest.php index dbee2edd44..0b8698ad77 100644 --- a/service-api/app/test/AppTest/Service/Lpa/GetAttorneyStatusTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/GetAttorneyStatusTest.php @@ -30,7 +30,10 @@ public function setUp(): void #[Test] public function returns_0_if_attorney_is_active(): void { - $attorney = new SiriusPerson(['id' => 7, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => true]); + $attorney = new SiriusPerson( + ['id' => 7, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => true], + $this->loggerProphecy->reveal(), + ); $status = new GetAttorneyStatus( $this->loggerProphecy->reveal() @@ -98,7 +101,10 @@ public function returns_0_if_attorney_is_active_combined_format_sirius(): void #[Test] public function returns_1_if_attorney_is_a_ghost(): void { - $attorney = new SiriusPerson(['uId' => 7, 'firstname' => '', 'surname' => '', 'systemStatus' => true]); + $attorney = new SiriusPerson( + ['uId' => 7, 'firstname' => '', 'surname' => '', 'systemStatus' => true], + $this->loggerProphecy->reveal(), + ); $status = new GetAttorneyStatus( $this->loggerProphecy->reveal() @@ -166,7 +172,10 @@ public function returns_1_if_attorney_is_a_ghost_combined_format_sirius(): void #[Test] public function returns_2_if_attorney_is_inactive(): void { - $attorney = new SiriusPerson(['uId' => 7, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => false]); + $attorney = new SiriusPerson( + ['uId' => 7, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => false], + $this->loggerProphecy->reveal(), + ); $status = new GetAttorneyStatus( $this->loggerProphecy->reveal() diff --git a/service-api/app/test/AppTest/Service/Lpa/GetTrustCorporationStatusTest.php b/service-api/app/test/AppTest/Service/Lpa/GetTrustCorporationStatusTest.php index bb12c04c4a..5c4e3d8763 100644 --- a/service-api/app/test/AppTest/Service/Lpa/GetTrustCorporationStatusTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/GetTrustCorporationStatusTest.php @@ -34,7 +34,8 @@ public function returns_0_if_trustCorporation_is_active(): void 'uId' => 7, 'companyName' => 'ABC Ltd', 'systemStatus' => true - ] + ], + $this->loggerProphecy->reveal(), ); $status = new GetTrustCorporationStatus( @@ -79,7 +80,8 @@ public function returns_1_if_trustCorporation_is_a_ghost(): void 'uId' => 8, 'companyName' => '', 'systemStatus' => false - ] + ], + $this->loggerProphecy->reveal(), ); $status = new GetTrustCorporationStatus( @@ -124,7 +126,8 @@ public function returns_2_if_trustCorporation_is_inactive(): void 'uId' => 7, 'companyName' => 'XYZ Ltd', 'systemStatus' => false - ] + ], + $this->loggerProphecy->reveal(), ); $status = new GetTrustCorporationStatus( diff --git a/service-api/app/test/AppTest/Service/Lpa/IsValidLpaTest.php b/service-api/app/test/AppTest/Service/Lpa/IsValidLpaTest.php index 38b2d1ee35..1fa2d084c9 100644 --- a/service-api/app/test/AppTest/Service/Lpa/IsValidLpaTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/IsValidLpaTest.php @@ -5,12 +5,12 @@ namespace AppTest\Service\Lpa; use App\Service\Lpa\IsValidLpa; +use App\Service\Lpa\SiriusLpa; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Psr\Log\LoggerInterface; -use App\Service\Lpa\SiriusLpa; class IsValidLpaTest extends TestCase { @@ -41,7 +41,8 @@ public function check_if_lpa_valid_when_status_registered(): void 'donor' => [ 'id' => 1, ], - ] + ], + $this->loggerProphecy->reveal(), ); $resolver = $this->isValidLpaResolver(); @@ -59,7 +60,8 @@ public function check_if_lpa_valid_when_status_cancelled(): void 'donor' => [ 'id' => 1, ], - ] + ], + $this->loggerProphecy->reveal(), ); $resolver = $this->isValidLpaResolver(); @@ -77,7 +79,8 @@ public function check_if_lpa_valid_when_status_other_than_registered_or_cancelle 'donor' => [ 'id' => 1, ], - ] + ], + $this->loggerProphecy->reveal(), ); $resolver = $this->isValidLpaResolver(); diff --git a/service-api/app/test/AppTest/Service/Lpa/ResolveActor/SiriusHasActorTraitTest.php b/service-api/app/test/AppTest/Service/Lpa/ResolveActor/SiriusHasActorTraitTest.php index 78223154a6..89e98fdb9e 100644 --- a/service-api/app/test/AppTest/Service/Lpa/ResolveActor/SiriusHasActorTraitTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/ResolveActor/SiriusHasActorTraitTest.php @@ -11,39 +11,68 @@ use App\Service\Lpa\SiriusPerson; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use Prophecy\Prophecy\ObjectProphecy; +use Psr\Log\LoggerInterface; class SiriusHasActorTraitTest extends TestCase { + use ProphecyTrait; + private LoggerInterface|ObjectProphecy $loggerProphecy; private HasActorInterface $mock; public function setUp(): void { - $this->mock = new class () implements HasActorInterface { + $this->mock = new class ( + $this->prophesize(LoggerInterface::class)->reveal() + ) implements HasActorInterface { use SiriusHasActorTrait; + public function __construct(private LoggerInterface $logger) + { + } + private function getDonor(): SiriusPerson { - return new SiriusPerson([ - 'id' => 1, - 'uId' => '123456789', - 'linked' => [['id' => 1, 'uId' => '123456789'], ['id' => 2, 'uId' => '234567890']], - ]); + return new SiriusPerson( + [ + 'id' => 1, + 'uId' => '123456789', + 'linked' => [['id' => 1, 'uId' => '123456789'], ['id' => 2, 'uId' => '234567890']], + ], + $this->logger, + ); } private function getAttorneys(): array { return [ - new SiriusPerson(['id' => 3, 'uId' => '345678901', 'firstname' => 'A', 'surname' => 'B']), - new SiriusPerson(['id' => 4, 'uId' => '456789012', 'firstname' => 'B', 'surname' => 'C']), - new SiriusPerson(['id' => 5, 'uId' => '567890123', 'firstname' => 'C', 'surname' => 'D']), + new SiriusPerson( + ['id' => 3, 'uId' => '345678901', 'firstname' => 'A', 'surname' => 'B'], + $this->logger, + ), + new SiriusPerson( + ['id' => 4, 'uId' => '456789012', 'firstname' => 'B', 'surname' => 'C'], + $this->logger, + ), + new SiriusPerson( + ['id' => 5, 'uId' => '567890123', 'firstname' => 'C', 'surname' => 'D'], + $this->logger, + ), ]; } private function getTrustCorporations(): array { return [ - new SiriusPerson(['id' => 6, 'uId' => '678901234', 'companyName' => 'A']), - new SiriusPerson(['id' => 7, 'uId' => '789012345', 'companyName' => 'B']), + new SiriusPerson( + ['id' => 6, 'uId' => '678901234', 'companyName' => 'A'], + $this->logger, + ), + new SiriusPerson( + ['id' => 7, 'uId' => '789012345', 'companyName' => 'B'], + $this->logger, + ), ]; } }; diff --git a/service-api/app/test/AppTest/Service/Lpa/SiriusLpaManagerTest.php b/service-api/app/test/AppTest/Service/Lpa/SiriusLpaManagerTest.php index 43d69873e2..119a26bcc9 100644 --- a/service-api/app/test/AppTest/Service/Lpa/SiriusLpaManagerTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/SiriusLpaManagerTest.php @@ -4,7 +4,6 @@ namespace AppTest\Service\Lpa; -use Common\Service\Lpa\Factory\Sirius; use App\DataAccess\{Repository\InstructionsAndPreferencesImagesInterface, Repository\LpasInterface, Repository\UserLpaActorMapInterface, @@ -103,9 +102,12 @@ public function can_get_by_id(): void 'id' => 6, 'companyName' => 'XYZ Ltd', 'systemStatus' => true, - ]), + ], + $this->loggerProphecy->reveal(), + ), ], ], + $this->loggerProphecy->reveal(), ), new DateTime() ); @@ -113,20 +115,23 @@ public function can_get_by_id(): void $expectedLpaResponse = new Lpa( new SiriusLpa( [ - 'attorneys' => [ + 'attorneys' => [ ['id' => 1, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => true], ['id' => 3, 'firstname' => 'A', 'systemStatus' => true], ['id' => 4, 'surname' => 'B', 'systemStatus' => true], ], - 'trustCorporations' => [ + 'trustCorporations' => [ new SiriusPerson( [ 'id' => 6, 'companyName' => 'XYZ Ltd', 'systemStatus' => true, - ]), + ], + $this->loggerProphecy->reveal(), + ), ], ], + $this->loggerProphecy->reveal(), ), $lpaResponse->getLookupTime() ); @@ -138,42 +143,73 @@ public function can_get_by_id(): void $this->lpasInterfaceProphecy->get($testUid)->willReturn($lpaResponse); $this->getAttorneyStatusProphecy - ->__invoke(new SiriusPerson(['id' => 1, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => true])) + ->__invoke( + new SiriusPerson( + ['id' => 1, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => true], + $this->loggerProphecy->reveal(), + ) + ) ->willReturn(AttorneyStatus::ACTIVE_ATTORNEY); $this->getAttorneyStatusProphecy - ->__invoke(new SiriusPerson(['id' => 2, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => false])) + ->__invoke( + new SiriusPerson( + ['id' => 2, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => false], + $this->loggerProphecy->reveal(), + ) + ) ->willReturn(AttorneyStatus::INACTIVE_ATTORNEY); $this->getAttorneyStatusProphecy - ->__invoke(new SiriusPerson(['id' => 3, 'firstname' => 'A', 'systemStatus' => true])) + ->__invoke( + new SiriusPerson( + ['id' => 3, 'firstname' => 'A', 'systemStatus' => true], + $this->loggerProphecy->reveal(), + ) + ) ->willReturn(AttorneyStatus::ACTIVE_ATTORNEY); $this->getAttorneyStatusProphecy - ->__invoke(new SiriusPerson(['id' => 4, 'surname' => 'B', 'systemStatus' => true])) + ->__invoke( + new SiriusPerson( + ['id' => 4, 'surname' => 'B', 'systemStatus' => true], + $this->loggerProphecy->reveal(), + ) + ) ->willReturn(AttorneyStatus::ACTIVE_ATTORNEY); $this->getAttorneyStatusProphecy - ->__invoke(new SiriusPerson(['id' => 5, 'systemStatus' => true])) + ->__invoke( + new SiriusPerson( + ['id' => 5, 'systemStatus' => true], + $this->loggerProphecy->reveal(), + ) + ) ->willReturn(AttorneyStatus::GHOST_ATTORNEY); $this->getTrustCorporationStatusProphecy ->__invoke( - new SiriusPerson([ - 'id' => 6, - 'companyName' => 'XYZ Ltd', - 'systemStatus' => true, - ]) + new SiriusPerson( + [ + 'id' => 6, + 'companyName' => 'XYZ Ltd', + 'systemStatus' => true, + ], + $this->loggerProphecy->reveal(), + ) ) ->willReturn(0); $this->getTrustCorporationStatusProphecy ->__invoke( - new SiriusPerson([ - 'id' => 7, - 'companyName' => 'ABC Ltd', - 'systemStatus' => true, - ]) + new SiriusPerson( + [ + 'id' => 7, + 'companyName' => 'ABC Ltd', + 'systemStatus' => true, + ], + $this->loggerProphecy->reveal(), + ) ) ->willReturn(2); @@ -217,6 +253,7 @@ private function init_valid_user_token_test($validState = true): stdClass ], 'inactiveAttorneys' => [], ], + $this->loggerProphecy->reveal(), ), new DateTime() ); @@ -251,12 +288,17 @@ private function init_valid_user_token_test($validState = true): stdClass )->willReturn($validState); // attorney status is active - $this->getAttorneyStatusProphecy->__invoke(new SiriusPerson([ - 'id' => $t->ActorId, - 'firstname' => 'Test', - 'surname' => 'Test', - 'systemStatus' => true, - ]))->willReturn(AttorneyStatus::ACTIVE_ATTORNEY); + $this->getAttorneyStatusProphecy->__invoke( + new SiriusPerson( + [ + 'id' => $t->ActorId, + 'firstname' => 'Test', + 'surname' => 'Test', + 'systemStatus' => true, + ], + $this->loggerProphecy->reveal(), + ) + )->willReturn(AttorneyStatus::ACTIVE_ATTORNEY); return $t; } @@ -309,6 +351,7 @@ private function init_valid_user_token_active_and_inactive_actor(): stdClass ], ], ], + $this->loggerProphecy->reveal(), ), new DateTime(), ); @@ -344,19 +387,29 @@ private function init_valid_user_token_active_and_inactive_actor(): stdClass )->willReturn(true); // attorney status is active - $this->getAttorneyStatusProphecy->__invoke(new SiriusPerson([ - 'id' => $t->ActorId, - 'firstname' => 'Test', - 'surname' => 'Test', - 'systemStatus' => true, - ]))->willReturn(AttorneyStatus::ACTIVE_ATTORNEY); - - $this->getAttorneyStatusProphecy->__invoke(new SiriusPerson([ - 'id' => 2, - 'firstname' => 'Test', - 'surname' => 'Test', - 'systemStatus' => false, - ]))->willReturn(AttorneyStatus::INACTIVE_ATTORNEY); + $this->getAttorneyStatusProphecy->__invoke( + new SiriusPerson( + [ + 'id' => $t->ActorId, + 'firstname' => 'Test', + 'surname' => 'Test', + 'systemStatus' => true, + ], + $this->loggerProphecy->reveal(), + ) + )->willReturn(AttorneyStatus::ACTIVE_ATTORNEY); + + $this->getAttorneyStatusProphecy->__invoke( + new SiriusPerson( + [ + 'id' => 2, + 'firstname' => 'Test', + 'surname' => 'Test', + 'systemStatus' => false, + ], + $this->loggerProphecy->reveal(), + ) + )->willReturn(AttorneyStatus::INACTIVE_ATTORNEY); return $t; } @@ -414,6 +467,7 @@ public function can_get_by_user_token(): void ], 'inactiveAttorneys' => [], ], + $this->loggerProphecy->reveal(), ), $result['lpa'] ); @@ -521,7 +575,8 @@ private function init_valid_get_all_users(bool $includeActivated) [ 'uId' => 'uid-1', 'status' => 'Registered', - ] + ], + $this->loggerProphecy->reveal(), ), new DateTime(), ), @@ -531,6 +586,7 @@ private function init_valid_get_all_users(bool $includeActivated) 'uId' => 'uid-2', 'status' => 'Registered', ], + $this->loggerProphecy->reveal(), ), new DateTime() ), @@ -557,6 +613,7 @@ private function init_valid_get_all_users(bool $includeActivated) 'status' => 'Registered', 'uId' => 'uid-3', ], + $this->loggerProphecy->reveal(), ), new DateTime(), ); @@ -675,7 +732,8 @@ private function init_valid_get_by_viewer_account() 'inactiveAttorneys' => [], 'applicationHasGuidance' => true, 'applicationHasRestrictions' => true, - ] + ], + $this->loggerProphecy->reveal(), ), new DateTime() ); diff --git a/service-api/app/test/AppTest/Service/Lpa/SiriusLpaTest.php b/service-api/app/test/AppTest/Service/Lpa/SiriusLpaTest.php index dbaaea969d..2ca7bea7e0 100644 --- a/service-api/app/test/AppTest/Service/Lpa/SiriusLpaTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/SiriusLpaTest.php @@ -7,16 +7,29 @@ use App\Service\Lpa\SiriusLpa; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use Prophecy\Prophecy\ObjectProphecy; +use Psr\Log\LoggerInterface; class SiriusLpaTest extends TestCase { + use ProphecyTrait; + + private LoggerInterface|ObjectProphecy $loggerProphecy; + + protected function setUp(): void + { + $this->loggerProphecy = $this->prophesize(LoggerInterface::class); + } + #[Test] public function it_can_be_instantiated(): void { $sut = new SiriusLpa( [ 'uId' => 700000000000, - ] + ], + $this->loggerProphecy->reveal(), ); $this->assertInstanceOf(SiriusLpa::class, $sut); @@ -28,7 +41,8 @@ public function it_is_array_accessible(): void $sut = new SiriusLpa( [ 'uId' => 700000000000, - ] + ], + $this->loggerProphecy->reveal(), ); $this->assertEquals(700000000000, $sut['uId']); @@ -46,7 +60,8 @@ public function it_can_be_iterated(): void $sut = new SiriusLpa( [ 'uId' => 700000000000, - ] + ], + $this->loggerProphecy->reveal(), ); foreach ($sut as $key => $value) { @@ -60,7 +75,8 @@ public function it_can_become_an_array(): void $sut = new SiriusLpa( [ 'uId' => 700000000000, - ] + ], + $this->loggerProphecy->reveal(), ); $this->assertEquals( @@ -77,7 +93,8 @@ public function it_becomes_the_expected_json(): void $sut = new SiriusLpa( [ 'uId' => 700000000000, - ] + ], + $this->loggerProphecy->reveal(), ); $this->assertJsonStringEqualsJsonString( @@ -92,7 +109,8 @@ public function it_typecasts_on_getters(): void [ 'uId' => 700000000000, 'status' => 'Registered', - ] + ], + $this->loggerProphecy->reveal(), ); $this->assertSame('700000000000', $sut->getUid()); diff --git a/service-api/app/test/AppTest/Service/Lpa/SiriusPersonTest.php b/service-api/app/test/AppTest/Service/Lpa/SiriusPersonTest.php index 82ca951bee..931762e61c 100644 --- a/service-api/app/test/AppTest/Service/Lpa/SiriusPersonTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/SiriusPersonTest.php @@ -7,16 +7,29 @@ use App\Service\Lpa\SiriusPerson; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use Prophecy\Prophecy\ObjectProphecy; +use Psr\Log\LoggerInterface; class SiriusPersonTest extends TestCase { + use ProphecyTrait; + + private LoggerInterface|ObjectProphecy $loggerProphecy; + + protected function setUp(): void + { + $this->loggerProphecy = $this->prophesize(LoggerInterface::class); + } + #[Test] public function it_can_be_instantiated(): void { $sut = new SiriusPerson( [ 'uId' => 700000000000, - ] + ], + $this->loggerProphecy->reveal(), ); $this->assertInstanceOf(SiriusPerson::class, $sut); @@ -28,7 +41,8 @@ public function it_is_array_accessible(): void $sut = new SiriusPerson( [ 'uId' => 700000000000, - ] + ], + $this->loggerProphecy->reveal(), ); $this->assertEquals(700000000000, $sut['uId']); @@ -46,7 +60,8 @@ public function it_can_be_iterated(): void $sut = new SiriusPerson( [ 'uId' => 700000000000, - ] + ], + $this->loggerProphecy->reveal(), ); foreach ($sut as $key => $value) { @@ -60,7 +75,8 @@ public function it_can_become_an_array(): void $sut = new SiriusPerson( [ 'uId' => 700000000000, - ] + ], + $this->loggerProphecy->reveal(), ); $this->assertEquals( @@ -77,7 +93,8 @@ public function it_becomes_the_expected_json(): void $sut = new SiriusPerson( [ 'uId' => 700000000000, - ] + ], + $this->loggerProphecy->reveal(), ); $this->assertJsonStringEqualsJsonString( @@ -94,7 +111,8 @@ public function it_typecasts_on_getters(): void 'uId' => 700000000000, 'systemStatus' => 1, 'companyName' => null, - ] + ], + $this->loggerProphecy->reveal(), ); $this->assertSame('700000000000', $sut->getUid());