/** * Verify basic functionality of clear(). * * @test * @covers ::clear * * @return void */ public function clear() { $cache = new ArrayCache(); $request = new Request('not under test', 'not under test', [], []); $cache->set($request, new Response(200, [], [])); $this->assertNotNull($cache->get($request)); $cache->clear(); $this->assertNull($cache->get($request)); }
/** * Verfiy response is return from cache. * * @test * @covers ::get * * @return void */ public function getFromCache() { \Chadicus\FunctionRegistry::set(__NAMESPACE__, 'time', function () { return 1; }); $hash = md5('1aPrivateKeyaPublicKey'); $cache = new Cache\ArrayCache(); $cache->set(new Request(Client::BASE_URL . "a+Resource/1?apikey=aPublicKey&ts=1&hash={$hash}", 'GET'), new Response(599, ['custom' => 'header'], ['key' => 'value'])); $adapter = new FakeAdapter(); $client = new Client('aPrivateKey', 'aPublicKey', $adapter, $cache); $response = $client->get('a Resource', 1); $this->assertSame(599, $response->getHttpCode()); $this->assertSame(['custom' => 'header'], $response->getHeaders()); $this->assertSame(['key' => 'value'], $response->getBody()); // assert the adapter was not used $this->assertNull($adapter->getRequest()); }