public function testCreateCloseIoWrapper()
 {
     $config = new CloseIoConfig();
     $config->setApiKey('testkey');
     $closeIoApiWrapper = new CloseIoApiWrapper($config);
     $this->assertTrue(get_class($closeIoApiWrapper) === 'LooplineSystems\\CloseIoApiWrapper\\CloseIoApiWrapper');
 }
 /**
  * @param CloseIoConfig $config
  * @throws \Exception
  */
 public function __construct(CloseIoConfig $config)
 {
     if ($config->getApiKey() !== '' && $config->getUrl() !== '') {
         $this->apiHandler = $this->initApiHandler($config);
     } else {
         throw new \Exception('Config must contain url and api key');
     }
 }
 /**
  * @return CustomFieldApi
  */
 private function getCustomFieldApi()
 {
     // init wrapper
     $closeIoConfig = new CloseIoConfig();
     $closeIoConfig->setApiKey('testapikey');
     $closeIoApiWrapper = new CloseIoApiWrapper($closeIoConfig);
     return $closeIoApiWrapper->getCustomFieldApi();
 }
 public function testBadRequest()
 {
     $config = new CloseIoConfig();
     $config->setApiKey('testkey');
     $closeIoApiWrapper = new CloseIoApiWrapper($config);
     $leadApi = $closeIoApiWrapper->getLeadApi();
     $this->setExpectedException('LooplineSystems\\CloseIoApiWrapper\\Library\\Exception\\BadApiRequestException');
     $leadApi->getLead('bad-id');
 }
 /**
  * @param $jsonString
  * @param $expected
  * @dataProvider jsonStringProvider
  * @throws \LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException
  */
 public function testSetData($jsonString, $expected)
 {
     $closeIoConfig = new CloseIoConfig();
     $closeIoConfig->setApiKey('testapikey');
     $closeIoApiHandler = new ApiHandler($closeIoConfig);
     $request = new CloseIoRequest($closeIoApiHandler);
     if ($expected === false) {
         $this->setExpectedException('LooplineSystems\\CloseIoApiWrapper\\Library\\Exception\\JsonDecodingException');
         $request->setData($jsonString);
     } else {
         $request->setData($jsonString);
         $this->assertNotEmpty($request->getData());
     }
 }
 /**
  * @param mixed $data
  * @param bool $expected
  * @param string $expectedData
  *
  * @dataProvider jsonStringProvider
  * @throws \LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException
  */
 public function testSetData($data, $expected, $expectedData = null)
 {
     $closeIoConfig = new CloseIoConfig();
     $closeIoConfig->setApiKey('testapikey');
     $closeIoApiHandler = new ApiHandler($closeIoConfig);
     $request = new CloseIoRequest($closeIoApiHandler);
     if ($expected === false) {
         $this->setExpectedException(InvalidParamException::class);
         $request->setData($data);
     } else {
         $request->setData($data);
         $this->assertEquals($expectedData, $request->getData());
     }
 }
 /**
  * @param string $url
  * @param string $apiKey
  * @param bool $expected
  * @dataProvider configProvider
  * @throws \LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException
  */
 public function testCreateCloseIoConfig($url, $apiKey, $expected)
 {
     if ($expected === true) {
         if ($url === null) {
             $closeIoConfig = new closeIoConfig();
         } else {
             $closeIoConfig = new closeIoConfig($url);
         }
         $closeIoConfig->setApiKey($apiKey);
         $this->assertNotFalse(filter_var($closeIoConfig->getUrl(), FILTER_VALIDATE_URL));
         $this->assertTrue($closeIoConfig->getApiKey() != '' && is_string($closeIoConfig->getApiKey()));
     } else {
         if (!filter_var($url, FILTER_VALIDATE_URL)) {
             $this->setExpectedException('LooplineSystems\\CloseIoApiWrapper\\Library\\Exception\\InvalidParamException');
             $closeIoConfig = new closeIoConfig($url);
         } else {
             $closeIoConfig = new CloseIoConfig($url);
             $closeIoConfig->setApiKey($apiKey);
             $this->assertNull($closeIoConfig->getApiKey());
         }
     }
 }