*/ public array $responses = []; /** @var array */ public array $calls = ['stations' => 0, 'measure' => 0, 'forecast' => 0]; /** @var array */ public array $lastArgs = []; 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'], 'forecast' => json_decode((string) file_get_contents(__DIR__ . '/fixtures/forecast.json'), true)['daily'], ]; 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 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; $r = $this->responses[$key] ?? new \RuntimeException("geen response voor $key"); if ($r instanceof \Throwable) { throw $r; } return $r; } }