/** * @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'); } }
/** * @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()); } } }