/**
  * @param Lead $lead
  * @description tests adding a lead using mock curl object
  * @dataProvider leadProvider
  */
 public function testAddLead(Lead $lead)
 {
     $leadsApi = $this->getLeadsApi();
     $returnedLead = clone $lead;
     $returnedLead->setId('TestIdString');
     $expectedResponse = new CloseIoResponse();
     $expectedResponse->setReturnCode(201);
     $expectedResponse->setRawData(json_encode($returnedLead));
     $expectedResponse->setData(json_decode($expectedResponse->getRawData(), true));
     $leadsApi->setCurl($this->getMockResponderCurl($expectedResponse));
     $response = $leadsApi->addLead($lead);
     $createdLead = new Lead($response->getData());
     $this->assertTrue($createdLead->getName() === $lead->getName());
     $this->assertNotEmpty($createdLead->getId());
     $this->assertEmpty($lead->getId());
 }
 /**
  * @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;
 }
 /**
  * @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());
 }