Exemplo n.º 1
0
 /** @test */
 public function it_generates_authentication_link()
 {
     $authLink = $this->liveCoding->getAuthLink();
     if (!$this->liveCoding->isAuthorized()) {
         $this->assertContains($this->client->getId(), $authLink);
         $this->assertContains(urlencode($this->client->getRedirectUrl()), $authLink);
     }
 }
Exemplo n.º 2
0
 /**
  * [postUrlContents description].
  *
  * @param       $url
  * @param       $query
  * @param array $headers
  *
  * @return mixed|null
  */
 private function postUrlContents($url, $query, $headers = [])
 {
     $query['client_id'] = $this->client->getId();
     $response = null;
     try {
         $curl = curl_init();
         $timeout = 5;
         curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($curl, CURLOPT_URL, $url);
         curl_setopt($curl, CURLOPT_POST, count($query));
         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($query));
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
         $response = curl_exec($curl);
         if (false === $response) {
             throw new \Exception(curl_error($curl), curl_errno($curl));
         }
         curl_close($curl);
     } catch (\Exception $e) {
         trigger_error(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);
     }
     return $response;
 }