Esempio n. 1
0
 public function testSetLogger()
 {
     // This test assumes that the debug output defaults to off.
     $file_name = getLogFileName();
     $message = 'The sky is the daily bread of the eyes.';
     setOutputDestination($file_name);
     $this->runner->getLogger()->debug($message);
     $output = retrieveOutput($file_name);
     $this->assertFalse(strpos($output, $message) !== false);
     $this->runner->setLogger(['debug' => true, 'format' => 'json']);
     $this->runner->getLogger()->debug($message);
     $output = retrieveOutput($file_name);
     $this->assertTrue(strpos($output, $message) !== false);
     resetOutputDestination($file_name);
 }
Esempio n. 2
0
 /**
  * Sends a request to the API
  *
  * @param string $uri        URL for API request
  * @param string $method     Request method (i.e. PUT, POST, DELETE, or GET)
  * @param array  $arg_params Request parameters
  * @return \Psr\Http\Message\ResponseInterface
  */
 private function send($uri, $method, array $arg_params = array())
 {
     $extra_params = array('headers' => array('User-Agent' => $this->userAgent(), 'Content-type' => 'application/json'), RequestOptions::VERIFY => strpos(TERMINUS_HOST, 'onebox') === false);
     if ($session = Session::instance()->get('session', false)) {
         $extra_params['headers']['Authorization'] = "Bearer {$session}";
     }
     $params = array_merge_recursive($extra_params, $arg_params);
     if (isset($params['form_params'])) {
         $params['json'] = $params['form_params'];
         unset($params['form_params']);
     }
     $params[RequestOptions::VERIFY] = strpos(TERMINUS_HOST, 'onebox') === false;
     $client = new Client(array('base_uri' => $this->getBaseUri(), 'cookies' => $this->fillCookieJar($params)));
     unset($params['cookies']);
     Runner::getLogger()->debug("#### REQUEST ####\nParams: {params}\nURI: {uri}\nMethod: {method}", array('params' => json_encode($params), 'uri' => $uri, 'method' => $method));
     //Required objects and arrays stir benign warnings.
     error_reporting(E_ALL ^ E_WARNING);
     $request = new HttpRequest(ucwords($method), $uri, $params);
     error_reporting(E_ALL);
     $response = $client->send($request, $params);
     return $response;
 }