cache_path = sys_get_temp_dir() . '/currency_rate_test_' . uniqid() . '.json'; } protected function tearDown(): void { if (is_file($this->cache_path)) { unlink($this->cache_path); } } public function testRubAlwaysReturnsOne(): void { $client = new Client(['url' => 'https://unreachable.invalid/', 'timeout' => 1, 'cache_path' => $this->cache_path]); $this->assertSame(1.0, $client->rate('rub')); $this->assertSame(1.0, $client->rate('RUB')); } public function testUnreachableSourceReturnsNullWithoutThrowing(): void { $client = new Client(['url' => 'https://unreachable.invalid/', 'timeout' => 1, 'cache_path' => $this->cache_path]); $this->assertNull($client->rate('EUR')); } public function testReadsFromFreshCacheWithoutNetwork(): void { file_put_contents($this->cache_path, json_encode(['EUR' => 104.5])); // url заведомо невалиден — если бы клиент реально пошёл в сеть, тест бы не прошёл (null). $client = new Client(['url' => 'not-a-url', 'timeout' => 1, 'cache_path' => $this->cache_path, 'ttl' => 86400]); $this->assertSame(104.5, $client->rate('EUR')); } public function testUnknownCodeReturnsNull(): void { file_put_contents($this->cache_path, json_encode(['EUR' => 104.5])); $client = new Client(['url' => 'not-a-url', 'timeout' => 1, 'cache_path' => $this->cache_path, 'ttl' => 86400]); $this->assertNull($client->rate('XXX')); } }