Files
weerscherm/tests/ForecastMapperTest.php
theoandClaude Sonnet 5 8bbfd62d16 feat: toon vandaag ook in de 5-daagse verwachting (nu 6 dagen)
ForecastMapper mapt voortaan index 0 t/m 5 van Open-Meteo (was 1 t/m 5),
zodat vandaag als eerste kolom in de verwachtingsstrook verschijnt naast
de bestaande 5 dagen erna. Verwachtingskolommen gaan van 5 naar 6 breed
(103px i.p.v. 124px), weericoon iets verkleind (58 -> 50px) om te passen.
Spec bijgewerkt om de wijziging vast te leggen. Service-worker-versie naar
v4 zodat het scherm dit zelf binnen enkele minuten oppikt.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-13 10:01:14 +02:00

58 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Weerscherm\Tests;
use PHPUnit\Framework\TestCase;
use Weerscherm\ForecastMapper;
final class ForecastMapperTest extends TestCase
{
/** @return array<string, mixed> */
private function daily(): array
{
return json_decode((string) file_get_contents(__DIR__ . '/fixtures/forecast.json'), true)['daily'];
}
public function testIncludesTodayAndReturnsSixDays(): void
{
$f = ForecastMapper::map($this->daily());
self::assertCount(6, $f);
self::assertSame([
'date' => '2026-09-11', 'weather_code' => 3, 'temp_max' => 17.9, 'temp_min' => 11.0,
'precip_mm' => 0.0, 'precip_prob' => 10,
], $f[0]);
self::assertSame('2026-09-16', $f[5]['date']);
}
public function testNullValuesStayNull(): void
{
$daily = $this->daily();
$daily['weather_code'][3] = null;
$daily['precipitation_probability_max'][3] = null;
$f = ForecastMapper::map($daily);
self::assertNull($f[3]['weather_code']);
self::assertNull($f[3]['precip_prob']);
self::assertSame(17.4, $f[3]['temp_max']);
}
public function testShorterResponseGivesFewerDays(): void
{
$daily = $this->daily();
foreach ($daily as $key => $values) {
$daily[$key] = array_slice($values, 0, 3);
}
self::assertCount(3, ForecastMapper::map($daily));
}
public function testMissingTimeArrayGivesEmptyList(): void
{
self::assertSame([], ForecastMapper::map([]));
}
}