Gestion du changement de type de contrat + correction du calcule des RTT sur un contrat qui commence en milieu de semaine (#19)
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [x] Pas de régression - [x] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: #19 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #19.
This commit is contained in:
74
tests/Service/Rtt/RttRecoveryComputationServiceTest.php
Normal file
74
tests/Service/Rtt/RttRecoveryComputationServiceTest.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service\Rtt;
|
||||
|
||||
use App\Entity\Contract;
|
||||
use App\Service\Rtt\RttRecoveryComputationService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* The service constructor takes several final-class collaborators that PHPUnit cannot
|
||||
* double. Pure helpers are exercised via newInstanceWithoutConstructor + reflection.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class RttRecoveryComputationServiceTest extends TestCase
|
||||
{
|
||||
public function testResolveWeekAnchorDateReturnsFirstContractedDayWhenWeekStartsBeforeHire(): void
|
||||
{
|
||||
$service = new ReflectionClass(RttRecoveryComputationService::class)->newInstanceWithoutConstructor();
|
||||
$contract = new Contract();
|
||||
|
||||
$weekDays = ['2026-03-16', '2026-03-17', '2026-03-18', '2026-03-19', '2026-03-20', '2026-03-21', '2026-03-22'];
|
||||
$contractsByDate = [
|
||||
'2026-03-16' => null,
|
||||
'2026-03-17' => null,
|
||||
'2026-03-18' => null,
|
||||
'2026-03-19' => $contract,
|
||||
'2026-03-20' => $contract,
|
||||
'2026-03-21' => $contract,
|
||||
'2026-03-22' => $contract,
|
||||
];
|
||||
|
||||
$anchor = $this->invokePrivate($service, 'resolveWeekAnchorDate', $weekDays, $contractsByDate);
|
||||
|
||||
self::assertSame('2026-03-19', $anchor);
|
||||
}
|
||||
|
||||
public function testResolveWeekAnchorDateReturnsFirstDayWhenItIsContracted(): void
|
||||
{
|
||||
$service = new ReflectionClass(RttRecoveryComputationService::class)->newInstanceWithoutConstructor();
|
||||
$contract = new Contract();
|
||||
|
||||
$weekDays = ['2026-03-23', '2026-03-24', '2026-03-25'];
|
||||
$contractsByDate = [
|
||||
'2026-03-23' => $contract,
|
||||
'2026-03-24' => $contract,
|
||||
'2026-03-25' => $contract,
|
||||
];
|
||||
|
||||
$anchor = $this->invokePrivate($service, 'resolveWeekAnchorDate', $weekDays, $contractsByDate);
|
||||
|
||||
self::assertSame('2026-03-23', $anchor);
|
||||
}
|
||||
|
||||
public function testResolveWeekAnchorDateFallsBackToFirstDayWhenNoContract(): void
|
||||
{
|
||||
$service = new ReflectionClass(RttRecoveryComputationService::class)->newInstanceWithoutConstructor();
|
||||
|
||||
$weekDays = ['2026-03-16', '2026-03-17'];
|
||||
$contractsByDate = ['2026-03-16' => null, '2026-03-17' => null];
|
||||
|
||||
$anchor = $this->invokePrivate($service, 'resolveWeekAnchorDate', $weekDays, $contractsByDate);
|
||||
|
||||
self::assertSame('2026-03-16', $anchor);
|
||||
}
|
||||
|
||||
private function invokePrivate(object $obj, string $method, mixed ...$args): mixed
|
||||
{
|
||||
return new ReflectionClass($obj::class)->getMethod($method)->invoke($obj, ...$args);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user