예제 #1
0
 /**
  * @param Lead $lead
  * @return Lead|string
  * @throws InvalidParamException
  * @throws ResourceNotFoundException
  */
 public function updateLead(Lead $lead)
 {
     // check if lead has id
     if ($lead->getId() == null) {
         throw new InvalidParamException('When updating a lead you must provide the lead ID');
     }
     // remove id from lead since it won't be part of the patch data
     $id = $lead->getId();
     $lead->setId(null);
     $lead = json_encode($lead);
     $apiRequest = $this->prepareRequest('update-lead', $lead, ['id' => $id]);
     $response = $this->triggerPut($apiRequest);
     // return Lead object if successful
     if ($response->getReturnCode() == 200 && $response->getData() !== null) {
         $lead = new Lead($response->getData());
     } else {
         throw new ResourceNotFoundException();
     }
     return $lead;
 }
 /**
  * @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());
 }
 /**
  * @param Lead $lead
  *
  * @return Lead
  * @throws InvalidParamException
  */
 public function updateLead(Lead $lead)
 {
     // check if lead has id
     if ($lead->getId() == null) {
         throw new InvalidParamException('When updating a lead you must provide the lead ID');
     }
     // remove id from lead since it won't be part of the patch data
     $id = $lead->getId();
     $lead->setId(null);
     $lead = json_encode($lead);
     $apiRequest = $this->prepareRequest('update-lead', $lead, ['id' => $id]);
     $response = $this->triggerPut($apiRequest);
     return new Lead($response->getData());
 }
예제 #4
0
 /**
  * @param array $data
  * @dataProvider fullLeadProvider
  */
 public function testCreateDynamicLead($data)
 {
     $hydratedLead = new Lead($data);
     $dynamicLead = new Lead();
     $dynamicLead->setId($data['id']);
     $dynamicLead->setStatusId($data['status_id']);
     $dynamicLead->setStatusLabel($data['status_label']);
     $dynamicLead->setDescription($data['description']);
     $dynamicLead->setDisplayName($data['display_name']);
     $dynamicLead->setAddresses($data['addresses']);
     $dynamicLead->setOrganization($data['organization']);
     $dynamicLead->setCreatedBy($data['created_by']);
     $dynamicLead->setUrl($data['url']);
     $dynamicLead->setTasks($data['tasks']);
     $dynamicLead->setName($data['name']);
     $dynamicLead->setContacts($data['contacts']);
     $dynamicLead->setDateCreated($data['date_created']);
     $dynamicLead->setCustom($data['custom']);
     $dynamicLead->setUpdatedByName($data['updated_by_name']);
     $dynamicLead->setCreatedByName($data['created_by_name']);
     $dynamicLead->setOpportunities($data['opportunities']);
     $dynamicLead->setHtmlUrl($data['html_url']);
     $dynamicLead->setUpdatedBy($data['updated_by']);
     $dynamicLead->setDateUpdated($data['date_updated']);
     $dynamicLead->setOrganizationId($data['organization_id']);
     $dynamicLead = json_decode(json_encode($dynamicLead));
     $hydratedLead = json_decode(json_encode($hydratedLead));
     $this->assertTrue($hydratedLead == $dynamicLead);
 }