/** * @param CustomField $customField * * @return CustomField * @throws InvalidParamException */ public function updateCustomField(CustomField $customField) { if ($customField->getId() == null) { throw new InvalidParamException('When updating a custom field you must provide the custom field ID'); } $id = $customField->getId(); $customField->setId(null); $customField = json_encode($customField); $apiRequest = $this->prepareRequest('update-customField', $customField, ['id' => $id]); $response = $this->triggerPut($apiRequest); return new CustomField($response->getData()); }
/** * @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()); }