/** * @covers DNSMadeEasy\driver\Configuration::getDebug */ public function testGetDebug() { $this->configuration->debug(true); $this->assertTrue($this->configuration->getDebug(), "Debug should be set to true"); $this->configuration->debug(false); $this->assertFalse($this->configuration->getDebug(), "Debug should be set to false"); }
/** * Sends the request to the server. * @param string $command The URI to append after the base URL. * @param array $uriParameters An optional array of URI template parameters. * @param string $method The request method. * @param string $content The request body. * @throws RESTException * @return \DNSMadeEasy\Result */ private function send($command, $uriParameters, $method, $content = NULL) { $url = $this->_config->getURL(); $ch = curl_init($url . $this->_uriTemplate->expand($command, $uriParameters)); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 300); curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getAuthenticationHeaders()); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if ($content !== NULL) { curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($content)); } switch (strtolower($method)) { case "get": curl_setopt($ch, CURLOPT_HTTPGET, true); break; case "post": curl_setopt($ch, CURLOPT_POST, true); break; case "put": curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); //CURL_OPTPUT requires INFILE and writing to ram/disk, which is annoying break; case "delete": curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); break; } curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); if (true || $this->_config->usingSandbox()) { //TODO le true ajouté par DDC pour bypass le control curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //Temporary workaround because https://api.sandbox.dnsmadeeasy.com uses a bad certificate curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } else { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); } $result = curl_exec($ch); //Something bad has happened, for example the API is down, etc. if (curl_errno($ch)) { $errorNumber = curl_errno($ch); $error = curl_error($ch); throw new RESTException("Error: {$errorNumber} - {$error}"); } $info = curl_getinfo($ch); $request = new Request($info, $content); $response = new Response($result, $info['total_time']); //If debug mode is on, output the debug messages. if ($this->_config->getDebug()) { $this->_debugger->request($request); $this->_debugger->response($response); } curl_close($ch); return new Result($response); }
/** * Turns the debugger on and off. * @param boolean $value Whether to turn the debugger on or off. */ public function debug($value) { $this->_config->debug($value); }
/** * @covers DNSMadeEasy\driver\REST::send */ public function testSendInDebugMode() { $reflectionClass = new \ReflectionClass('DNSMadeEasy\\driver\\REST'); $send = $reflectionClass->getMethod('send'); $send->setAccessible(true); $configuration = new Configuration($this->getApiKey(), $this->getSecretKey(), true); $configuration->debug(true); $rest = new REST($configuration); $this->setOutputCallback(function ($output) { $this->assertInternalType('string', $output); }); $send->invoke($rest, '/dns/soa{?rows,page}', array('rows' => 1, 'page' => 1), 'GET'); }