diff --git a/tests/BovinIdentificationProviderTest.php b/tests/BovinIdentificationProviderTest.php new file mode 100644 index 0000000..083a3ae --- /dev/null +++ b/tests/BovinIdentificationProviderTest.php @@ -0,0 +1,102 @@ +createMock(BovinApiInterface::class); + $api->expects(self::never())->method('getAnimalFile'); + + $provider = new BovinIdentificationProvider($api); + + $result = $provider->provide($this->createStub(Operation::class), []); + + self::assertNull($result); + } + + public function testMapsIdentificationAndPresencePeriods(): void + { + $api = $this->createMock(BovinApiInterface::class); + + $identification = new BovinIdentificationDto( + bovin: new BovinRef('FR', 'IGNORED'), + sex: 'F', + breedType: 'LIM', + birthDate: new DateValueDto(new DateTimeImmutable('2024-01-02'), 'Y'), + workNumber: 'W123', + isFilie: true, + motherCarrier: new ParentInfoDto(new BovinRef('FR', 'MOM1'), 'CHA'), + fatherIpg: new ParentInfoDto(new BovinRef('FR', 'DAD1'), 'BBB'), + birthExploitation: new ExploitationRef('FR', 'EXP1'), + ); + + $presencePeriods = [ + new PresencePeriodDto( + new MovementDto(new DateTimeImmutable('2024-03-01'), 'ENTRY', null), + new MovementDto(new DateTimeImmutable('2024-03-10'), 'EXIT', null), + ), + ]; + + $animalFile = new AnimalFileDto( + new StandardResponseDto(true, null), + $identification, + $presencePeriods, + null + ); + + $api->expects(self::once()) + ->method('getAnimalFile') + ->with('FR123', 'FR') + ->willReturn($animalFile) + ; + + $provider = new BovinIdentificationProvider($api); + + $result = $provider->provide( + $this->createStub(Operation::class), + ['numeroNational' => 'FR123'] + ); + + self::assertNotNull($result); + self::assertSame('FR123', $result->numeroNational); + self::assertSame('F', $result->sex); + self::assertSame('LIM', $result->breedType); + self::assertSame('W123', $result->workNumber); + self::assertSame('2024-01-02', $result->birthDate); + self::assertSame('Y', $result->birthDateCompletenessFlag); + self::assertTrue($result->isFilie); + self::assertSame('MOM1', $result->motherNationalNumber); + self::assertSame('CHA', $result->motherBreedType); + self::assertSame('DAD1', $result->fatherNationalNumber); + self::assertSame('BBB', $result->fatherBreedType); + self::assertSame('EXP1', $result->birthExploitationNumber); + + self::assertCount(1, $result->presencePeriods); + self::assertSame('2024-03-01', $result->presencePeriods[0]->entryDate); + self::assertSame('ENTRY', $result->presencePeriods[0]->entryCause); + self::assertSame('2024-03-10', $result->presencePeriods[0]->exitDate); + self::assertSame('EXIT', $result->presencePeriods[0]->exitCause); + } +} diff --git a/tests/State/MeProviderTest.php b/tests/State/MeProviderTest.php new file mode 100644 index 0000000..8d54552 --- /dev/null +++ b/tests/State/MeProviderTest.php @@ -0,0 +1,48 @@ +createStub(Security::class); + $security->method('getUser')->willReturn($user); + + $provider = new MeProvider($security); + + $result = $provider->provide($this->createStub(Operation::class)); + + self::assertSame($user, $result); + self::assertInstanceOf(User::class, $result); + } + + public function testProvideThrowAccessDeniedException(): void + { + $user = null; + + $security = $this->createStub(Security::class); + $security->method('getUser')->willReturn($user); + + $provider = new MeProvider($security); + + $this->expectException(AccessDeniedException::class); + $this->expectExceptionMessage('User not authenticated.'); + + $provider->provide($this->createStub(Operation::class)); + } +}