Ajouter les statistiques par période

This commit is contained in:
Alexandre NOEL 2026-10-02 12:11:30 +02:00
commit 86642095cd
14 changed files with 315 additions and 125 deletions

View file

@ -503,6 +503,27 @@ try {
$assert($structure !== null && $structure['label'] === 'Structure test');
$assert((int) $structure['total_cents'] === 1234);
});
$test('Les statistiques acceptent une année, un mois et une période libre', function () use ($assert): void {
$year = (int) date('Y');
$annual = StatisticsService::annual($year);
$yearRange = StatisticsService::period("$year-01-01", "$year-12-31");
foreach (['handled','entries','exits','adoptions','deaths','births','vaccinations','treatments','medical_notes'] as $key) {
$assert((float) $annual[$key] === (float) $yearRange[$key], 'Écart annuel sur ' . $key);
}
$today = date('Y-m-d');
$daily = StatisticsService::period($today, $today);
$assert((int) $daily['adoptions'] >= 1, 'La période du jour ne retrouve pas l’adoption de test');
$comparison = StatisticsService::comparisonPeriod($today, $today);
$assert(isset($comparison['rows']['adoptions'], $comparison['previous_start'], $comparison['previous_end']));
$costs = StatisticsService::costs(null, null, $today, $today);
$assert((int) $costs['total_cents'] >= 1234, 'Les coûts ne respectent pas la période personnalisée');
$distributions = StatisticsService::distributions(null, null, null, date('Y-m-01'), date('Y-m-t'));
$assert(isset($distributions['species'], $distributions['origins']));
$view = file_get_contents(__DIR__ . '/../app/Views/statistics.php');
foreach (['period_type','type="month"','date_from','date_to'] as $field) {
$assert(str_contains($view, $field), 'Filtre statistique absent : ' . $field);
}
});
$test('Le nom de l’adoptant ouvre la bonne route annuaire', function () use ($assert): void {
$view = file_get_contents(__DIR__ . '/../app/Views/_animal_show_identity.php');
$routes = file_get_contents(__DIR__ . '/../app/Routes/web.php');