Files
ESBSC-CONVOC/tests/yellow_cycles.php
2026-11-17 11:11:56 +01:00

39 lines
4.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require dirname(__DIR__).'/bootstrap.php';
use App\{YellowCycles,Eligibility};
$n=0;
function cycleCheck(bool $ok,string $label):void{global $n;if(!$ok)throw new RuntimeException($label);echo 'OK '.(++$n).' '.$label."\n";}
function yellow(int $id,string $date,array $extra=[]):array{return array_replace(['id'=>$id,'player_id'=>1,'event_type'=>'yellow','review_status'=>'confirmed','event_date'=>$date,'warning_effective_date'=>null,'warning_end_date'=>null],$extra);}
function decision(int $id=1,array $extra=[]):array{return array_replace(['id'=>$id,'player_id'=>1,'sanction_type'=>'yellow_accumulation','status'=>'official','duration_kind'=>'matches','effective_date'=>'2026-09-20','decision_date'=>'2026-09-17','purge_from'=>null,'exclusion_date'=>null,'matches_required'=>1],$extra);}
$p=['id'=>1,'active'=>1,'person_number'=>'1'];
$m=['id'=>1,'team_id'=>1,'match_date'=>'2026-09-22','counts_for_purge'=>1,'status'=>'played','is_official'=>1];
$events=[yellow(1,'2026-09-01'),yellow(2,'2026-09-08'),yellow(3,'2026-09-15')];
function details(array $s,array $m,string $date='2026-09-23',int $team=1):array{global $p;return Eligibility::calculate($p,$team,$date,$s,$m)['details'];}
$d=details([decision()],[$m]);
cycleCheck(YellowCycles::active($events,$d,'2026-09-23')===0,'Trois jaunes et suspension purgée : zéro');
cycleCheck(YellowCycles::active($events,details([decision()],[]),'2026-09-23')===3,'Aucune purge : trois restent visibles');
cycleCheck(YellowCycles::active($events,details([decision()],[$m],'2026-09-22'),'2026-09-22')===3,'Match du jour non encore crédité pour contrôle avant match');
cycleCheck(YellowCycles::active($events,details([decision()],[$m],'2026-09-23',2),'2026-09-23')===3,'Purge d’une autre équipe non créditée');
cycleCheck(YellowCycles::active($events,details([decision()], [array_replace($m,['status'=>'scheduled','counts_for_purge'=>0])]),'2026-09-23')===3,'Match prévu non crédité');
cycleCheck(YellowCycles::active($events,details([decision(1,['status'=>'revoked'])],[$m]),'2026-09-23')===3,'Sanction révoquée sans remise à zéro');
cycleCheck(YellowCycles::active($events,details([decision(1,['status'=>'provisional'])],[$m]),'2026-09-23')===3,'Décision provisoire sans remise à zéro');
cycleCheck(YellowCycles::active($events,details([decision(1,['sanction_type'=>'commission'])],[$m]),'2026-09-23')===3,'Sanction non identifiée comme cumul : pas de déduction');
cycleCheck(YellowCycles::active([...$events,yellow(4,'2026-09-18')],$d,'2026-09-23')===1,'Quatrième jaune avant purge conservé');
cycleCheck(YellowCycles::active([...$events,yellow(4,'2026-09-23')],$d,'2026-09-23')===1,'Nouveau jaune après purge conservé');
cycleCheck(YellowCycles::active(array_slice($events,0,2),$d,'2026-09-23')===2,'Historique incomplet : pas de remise à zéro inventée');
$cancelled=$events;$cancelled[1]['review_status']='cancelled';
cycleCheck(YellowCycles::active($cancelled,$d,'2026-09-23')===2,'Jaune annulé exclu et triple incomplet');
cycleCheck(YellowCycles::active($events,[],'2026-09-16')===3,'Lecture historique avant suspension');
cycleCheck(YellowCycles::active([yellow(1,'2026-06-01'),yellow(2,'2026-09-08'),yellow(3,'2026-09-15')],$d,'2026-09-23')===2,'Trois jaunes hors fenêtre ne forment pas un cycle');
cycleCheck(YellowCycles::active([yellow(1,'2026-09-01',['warning_end_date'=>'2026-09-23'])],[],'2026-09-23')===1,'Fin de validité incluse');
cycleCheck(YellowCycles::active([yellow(1,'2026-09-01',['warning_end_date'=>'2026-09-22'])],[],'2026-09-23')===0,'Date de fin explicite respectée');
cycleCheck(YellowCycles::active([yellow(1,'2026-09-01',['warning_effective_date'=>'2026-09-24'])],[],'2026-09-23')===0,'Date d’effet future exclue');
$more=[...$events,yellow(4,'2026-09-25'),yellow(5,'2026-10-01'),yellow(6,'2026-10-08'),yellow(7,'2026-10-20')];
$s2=decision(2,['effective_date'=>'2026-10-15','decision_date'=>'2026-10-12']);$m2=array_replace($m,['id'=>2,'match_date'=>'2026-10-18']);
cycleCheck(YellowCycles::active($more,details([decision(),$s2],[$m,$m2],'2026-10-21'),'2026-10-21')===1,'Deux cycles successifs, septième jaune conservé');
cycleCheck(YellowCycles::active($more,details([decision(),$s2],[$m,$m2],'2026-10-21'),'2026-10-21')===1,'Calcul répétable sans écriture');
cycleCheck(YellowCycles::active($events,details([decision(),decision(2)],[$m]),'2026-09-23')===0,'Un même triple ne peut être consommé deux fois');
cycleCheck(YellowCycles::active($events,details([decision(1,['matches_required'=>2])],[$m]),'2026-09-23')===3,'Purge partielle : aucun reset');
cycleCheck(YellowCycles::active([yellow(91,'2025-01-01'),yellow(92,'2025-01-08'),yellow(93,'2025-01-15'),...$events],$d,'2026-09-23')===0,'Anciens cycles expirés ne capturent pas la décision récente');
echo "$n contrôles réussis.\n";