/**
  * @param int $num_pages
  * @param RequestInterface|null $prev
  * @return Mock|ResponseInterface
  */
 protected function createResponseChainMock($num_pages, RequestInterface $prev = null)
 {
     $query_params = $prev ? clone $prev->getQueryParams() : new Parameters();
     $sample_content = $this->createSampleResponseContent();
     $request = $this->createRequestMock();
     $request->method('getMethod')->willReturn(RequestInterface::METHOD_GET);
     $request->method('getQueryParams')->willReturn($query_params);
     $response = $this->createResponseMock();
     $response->method('getRequest')->willReturn($request);
     $request->method('execute')->willReturn($response);
     $callback = function () use($num_pages, $sample_content) {
         return $num_pages > 0 ? $sample_content : $this->createEmptyResponseContent();
     };
     $clone_callback = function () use($num_pages, $request) {
         return $this->createResponseChainMock($num_pages - 1, $request)->getRequest();
     };
     $url_callback = function () use($query_params) {
         return $this->createUnparameterizedUrl() . '?' . http_build_query($query_params->getArrayCopy());
     };
     $response->method('getContent')->willReturnCallback($callback);
     $request->method('createClone')->willReturnCallback($clone_callback);
     $request->method('getUrl')->willReturnCallback($url_callback);
     return $response;
 }
 /**
  * @param string $level
  * @param RequestInterface $request
  * @param array $context
  */
 public function logRequest($level, RequestInterface $request, array $context = array())
 {
     $new_line = ' \\' . PHP_EOL . '  ';
     $method_flag = static::getMethodFlag($request->getMethod());
     $param_flag = static::getParamFlag($request->getMethod());
     $params = array_merge($this->processParams($request->getQueryParams(), $param_flag, false), $this->processParams($request->getBodyParams(), $param_flag, false), $this->processParams($request->getFileParams(), $param_flag, true));
     $buffer = 'curl' . ($method_flag ? ' -' . $method_flag : '');
     foreach ($params as $param) {
         $buffer .= $new_line . $param;
     }
     $buffer .= $new_line . $this->processUrl($request);
     $this->flush($buffer);
 }