From 6bc4f202386920757c563ea024a7f6972cd07618 Mon Sep 17 00:00:00 2001 From: Alex Saunders Date: Tue, 12 Nov 2024 17:33:33 +0000 Subject: [PATCH] bump cov --- .../Common/src/Service/Lpa/ParseLpaData.php | 4 ++ .../CastToLifeSustainingTreatmentTest.php | 42 +++++++++++++++---- .../Service/Lpa/ParseLpaDataTest.php | 7 +++- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/service-front/app/src/Common/src/Service/Lpa/ParseLpaData.php b/service-front/app/src/Common/src/Service/Lpa/ParseLpaData.php index 438150b0fc..fc3538f4ca 100644 --- a/service-front/app/src/Common/src/Service/Lpa/ParseLpaData.php +++ b/service-front/app/src/Common/src/Service/Lpa/ParseLpaData.php @@ -72,6 +72,10 @@ public function __invoke(array $data): ArrayObject return new ArrayObject($data, ArrayObject::ARRAY_AS_PROPS); } + + /** + * @codeCoverageIgnore + */ public static function getMockedCombinedFormat(bool $asLpaStoreLpa): array { $lpaArray = [ diff --git a/service-front/app/test/CommonTest/Entity/Casters/CastToLifeSustainingTreatmentTest.php b/service-front/app/test/CommonTest/Entity/Casters/CastToLifeSustainingTreatmentTest.php index 2eb7cbbfdf..ebc18ecb9c 100644 --- a/service-front/app/test/CommonTest/Entity/Casters/CastToLifeSustainingTreatmentTest.php +++ b/service-front/app/test/CommonTest/Entity/Casters/CastToLifeSustainingTreatmentTest.php @@ -6,29 +6,57 @@ use Common\Entity\Casters\CastToLifeSustainingTreatment; use EventSauce\ObjectHydrator\ObjectMapper; +use InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use ValueError; class CastToLifeSustainingTreatmentTest extends TestCase { + use ProphecyTrait; + private ObjectMapper $mockHydrator; - private CastToLifeSustainingTreatment $castToLifeSustainingTreatment; + private CastToLifeSustainingTreatment $caster; public function setUp(): void { $this->mockHydrator = $this->createMock(ObjectMapper::class); - $this->castToLifeSustainingTreatment = new CastToLifeSustainingTreatment(); + $this->caster = new CastToLifeSustainingTreatment(); } #[Test] - public function can_cast_life_sustaining_treatment(): void + #[DataProvider('lifeSustainingTreatmentProvider')] + public function can_cast_life_sustaining_treatment($input, $expectedOutput): void { - $lifeSustainingTreatment = 'option-a'; + $this->assertEquals( + $expectedOutput, + $this->caster->cast( + $input, + $this->prophesize(ObjectMapper::class)->reveal() + ) + ); + } - $expectedLifeSustainingTreatment = 'option-a'; + public function lifeSustainingTreatmentProvider(): array + { + return [ + ['Option A', 'option-a'], + ['option-a', 'option-a'], + ['Option B', 'option-b'], + ['option-b', 'option-b'], + ]; + } - $result = $this->castToLifeSustainingTreatment->cast($lifeSustainingTreatment, $this->mockHydrator); + #[Test] + public function throws_exception_on_invalid_type() + { + $this->expectException(InvalidArgumentException::class); - $this->assertEquals($expectedLifeSustainingTreatment, $result); + $this->caster->cast( + 'not-a-valid-type', + $this->prophesize(ObjectMapper::class)->reveal() + ); } } diff --git a/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php b/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php index f7306b6718..28e1f72ab9 100644 --- a/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php +++ b/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php @@ -4,16 +4,19 @@ namespace CommonTest\Service\Lpa; +use Common\Entity\LpaStore\LpaStore; +use Common\Entity\LpaStore\LpaStoreAttorney; +use Common\Entity\LpaStore\LpaStoreDonor; +use Common\Entity\LpaStore\LpaStoreTrustCorporations; use Common\Entity\Sirius\SiriusLpa; use Common\Entity\Sirius\SiriusLpaAttorney; use Common\Entity\Sirius\SiriusLpaDonor; use Common\Entity\Sirius\SiriusLpaTrustCorporations; -use Common\Enum\LpaType; -use Common\Enum\LifeSustainingTreatment; use Common\Service\Features\FeatureEnabled; use CommonTest\Helper\EntityTestHelper; use DateTimeImmutable; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use Common\Entity\CaseActor; use Common\Entity\InstructionsAndPreferences\Images;