/** * @dataProvider jsonErrorResponseProvider * * @param string $jsonResponse */ public function testResponseErrors($jsonResponse, $expected) { $response = new CloseIoResponse(); $response->setData(json_decode($jsonResponse, true)); if ($expected) { $this->assertGreaterThan(0, count($response->getErrors())); } else { $this->assertEquals(0, count($response->getErrors())); } }
/** * @param $curlHandler * @return CloseIoResponse */ public function execute($curlHandler) { $result = curl_exec($curlHandler); $curlInfo = curl_getinfo($curlHandler); $lastHttpCode = $curlInfo['http_code']; curl_close($curlHandler); $response = new CloseIoResponse(); $response->setReturnCode($lastHttpCode); $response->setRawData($result); $response->setData(json_decode($result, true)); $response->setCurlInfoRaw($curlInfo); return $response; }
/** * @test * @dataProvider customFieldDataProvider * * @param CustomField $customField */ public function testUpdateCustomField($customField) { $customFieldApi = $this->getCustomFieldApi(); $customField->setId('TestId'); $originalCustomField = clone $customField; $returnedCustomField = $customField; $returnedCustomField->setName('Test Name'); // init expected response $expectedResponse = new CloseIoResponse(); $expectedResponse->setReturnCode('200'); $expectedResponse->setRawData(json_encode($returnedCustomField)); $expectedResponse->setData(json_decode($expectedResponse->getRawData(), true)); // create stub $mockCurl = $this->getMockResponderCurl($expectedResponse); $customFieldApi->setCurl($mockCurl); /* @var CustomField $response */ $response = $customFieldApi->updateCustomField($customField); $this->assertEquals($customField->getName(), $response->getName()); $this->assertEquals($originalCustomField->getId(), $response->getId()); }
/** * @throws \LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException * @throws \LooplineSystems\CloseIoApiWrapper\Library\Exception\ResourceNotFoundException * @param Lead $lead * @dataProvider leadProvider */ public function testUpdateLead($lead) { $leadsApi = $this->getLeadsApi(); $lead->setId('TestId'); $originalLead = clone $lead; $returnedLead = $lead; $returnedLead->setName('Test Name'); // init expected response $expectedResponse = new CloseIoResponse(); $expectedResponse->setReturnCode('200'); $expectedResponse->setRawData(json_encode($returnedLead)); $expectedResponse->setData(json_decode($expectedResponse->getRawData(), true)); // create stub $mockCurl = $this->getMockResponderCurl($expectedResponse); $leadsApi->setCurl($mockCurl); /* @var Lead $response */ $response = $leadsApi->updateLead($lead); $this->assertEquals($lead->getDescription(), $response->getDescription()); $this->assertEquals($originalLead->getId(), $response->getId()); }