Naast het getal in elke modulekaart staat nu hetzelfde soort lijntje als bij buiten (200x40). Zonder labels: daar is in zo'n kaart geen ruimte voor, de schaal staat al op de regel eronder en het venster is hetzelfde "vandaag" als bij het grafiekje van buiten ernaast. Per module een eigen getmeasure, gecachet onder temperature-<module> met een gedeelde TTL; fetch() heeft daarvoor een losse ttlKey gekregen, want anders zou de TTL-lookup per module mislukken en zou er helemaal niet gecachet worden. Het basisstation meet zelf temperatuur en wordt zonder module_id opgevraagd, dus die parameter is optioneel geworden. In de payload als indoor[].history; mislukt er een, dan blijft die lijst leeg en verdwijnt alleen dat lijntje, met de foutcode in errors. Een stale-vlag per kamer zou het contract nodeloos zwaar maken. De hoogte is overal 40px, ook bij een vastgezette module: gelijke hoogte houdt de kamers onderling vergelijkbaar, en een hoger lijntje zou de toch al krappe speling onder de kolom opeten. De grafiekjes voegen geen hoogte toe aan de kaarten. FakeSource houdt nu alle aanroepen bij in plaats van alleen de laatste, zodat een test de volgorde van de vier temperatuur-calls kan nalopen. Servicewerker naar v11. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
77 lines
2.6 KiB
PHP
77 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Weerscherm\Tests;
|
|
|
|
use Weerscherm\WeatherSource;
|
|
|
|
/** Testdubbel: geeft per methode een array terug of gooit de ingestelde exception, en telt de aanroepen. */
|
|
final class FakeSource implements WeatherSource
|
|
{
|
|
/** @var array<string, array|\Throwable> */
|
|
public array $responses = [];
|
|
|
|
/** @var array<string, int> */
|
|
public array $calls = ['stations' => 0, 'measure' => 0, 'pressure' => 0, 'temperature' => 0, 'forecast' => 0];
|
|
|
|
/** @var array<string, array> */
|
|
public array $lastArgs = [];
|
|
|
|
/** @var array<string, list<array>> alle aanroepen per soort, in volgorde */
|
|
public array $allArgs = [];
|
|
|
|
public static function fromFixtures(): self
|
|
{
|
|
$s = new self();
|
|
$s->responses = [
|
|
'stations' => json_decode((string) file_get_contents(__DIR__ . '/fixtures/getstationsdata.json'), true)['body'],
|
|
'measure' => json_decode((string) file_get_contents(__DIR__ . '/fixtures/getmeasure.json'), true)['body'],
|
|
'pressure' => json_decode((string) file_get_contents(__DIR__ . '/fixtures/getmeasure-pressure.json'), true)['body'],
|
|
'temperature' => json_decode((string) file_get_contents(__DIR__ . '/fixtures/getmeasure-temperature.json'), true)['body'],
|
|
'forecast' => array_intersect_key(
|
|
json_decode((string) file_get_contents(__DIR__ . '/fixtures/forecast.json'), true),
|
|
['daily' => null, 'hourly' => null],
|
|
),
|
|
];
|
|
return $s;
|
|
}
|
|
|
|
public function stationsData(): array
|
|
{
|
|
return $this->answer('stations', []);
|
|
}
|
|
|
|
public function measure(string $deviceId, string $moduleId, int $begin, int $end): array
|
|
{
|
|
return $this->answer('measure', func_get_args());
|
|
}
|
|
|
|
public function pressureHistory(string $deviceId, int $begin, int $end): array
|
|
{
|
|
return $this->answer('pressure', func_get_args());
|
|
}
|
|
|
|
public function temperatureHistory(string $deviceId, ?string $moduleId, int $begin, int $end): array
|
|
{
|
|
return $this->answer('temperature', func_get_args());
|
|
}
|
|
|
|
public function forecast(float $lat, float $lon, string $timezone): array
|
|
{
|
|
return $this->answer('forecast', func_get_args());
|
|
}
|
|
|
|
private function answer(string $key, array $args): array
|
|
{
|
|
$this->calls[$key]++;
|
|
$this->lastArgs[$key] = $args;
|
|
$this->allArgs[$key][] = $args;
|
|
$r = $this->responses[$key] ?? new \RuntimeException("geen response voor $key");
|
|
if ($r instanceof \Throwable) {
|
|
throw $r;
|
|
}
|
|
return $r;
|
|
}
|
|
}
|