public function testCacheMiddleware() { $response = new Response(204); $mocks = array_fill(0, 2, $response); $mock = new MockHandler($mocks); $handler = HandlerStack::create($mock); $adapter = $this->getMock(StorageAdapterInterface::class); $adapter->expects($this->at(0))->method('fetch')->with($this->isInstanceOf(RequestInterface::class))->willReturn(false); $adapter->expects($this->at(1))->method('save')->with($this->isInstanceOf(RequestInterface::class), $this->equalTo($response)); $adapter->expects($this->at(2))->method('fetch')->with($this->isInstanceOf(RequestInterface::class))->willReturn($response); $handler->push(Middleware::cache($adapter)); $client = new Client(['handler' => $handler]); $client->get('http://foo.bar'); $client->get('http://foo.bar'); }
public function testCollect() { $mocks = array_fill(0, 3, new Response(204)); $mock = new MockHandler($mocks); $handler = HandlerStack::create($mock); $collector = new GuzzleCollector(); $handler->push(Middleware::history($collector->getHistory())); $client = new Client(['handler' => $handler]); $request = Request::createFromGlobals(); $response = $this->getMock('Symfony\\Component\\HttpFoundation\\Response'); $collector->collect($request, $response, new \Exception()); $this->assertCount(0, $collector->getCalls()); $client->get('http://foo.bar'); $collector->collect($request, $response, new \Exception()); $this->assertCount(1, $collector->getCalls()); $client->get('http://foo.bar'); $collector->collect($request, $response, new \Exception()); $this->assertCount(2, $collector->getCalls()); }