protected function createApiMock($response, $statusCode = 200)
 {
     $jsonFile = $this->createJsonFile();
     $jobsMethods = array('collectCloverXml', 'getJsonFile', 'collectGitInfo', 'collectEnvVars', 'dumpJsonFile', 'send');
     $api = $this->getMockBuilder('Satooshi\\Bundle\\CoverallsV1Bundle\\Api\\Jobs')->disableOriginalConstructor()->setMethods($jobsMethods)->getMock();
     $api->expects($this->once())->method('collectCloverXml')->with()->will($this->returnSelf());
     $api->expects($this->once())->method('getJsonFile')->with()->will($this->returnValue($jsonFile));
     $api->expects($this->once())->method('collectGitInfo')->with()->will($this->returnSelf());
     $api->expects($this->once())->method('collectEnvVars')->with($this->equalTo($_SERVER))->will($this->returnSelf());
     $api->expects($this->once())->method('dumpJsonFile')->with()->will($this->returnSelf());
     $request = $this->getMockBuilder('\\GuzzleHttp\\Psr7\\Request')->setConstructorArgs(['POST', '/'])->getMock();
     if ($statusCode === 200) {
         $api->expects($this->once())->method('send')->with()->will($this->returnValue($response));
     } else {
         if ($statusCode === null) {
             $exception = \GuzzleHttp\Exception\ConnectException::create($request);
         } elseif ($statusCode === 422) {
             $exception = \GuzzleHttp\Exception\ClientException::create($request, $response);
         } else {
             $exception = \GuzzleHttp\Exception\ServerException::create($request, $response);
         }
         $api->expects($this->once())->method('send')->with()->will($this->throwException($exception));
     }
     return $api;
 }