Example #1
0
 /**
  * @test
  */
 function it_throws_an_exception_on_invalid_config()
 {
     $service = new RestService();
     try {
         $service->config(['location' => true, 'port' => 'not a port', 'credentials' => ['name' => ['not a string'], 'password' => false], 'method' => ['not a string'], 'headers' => 'not an array', 'parameters' => 'not an array', 'options' => 'not an array', 'http_method' => 'FALSE_METHOD']);
         $this->fail('Expecting ServiceConfigurationException');
     } catch (ServiceConfigurationException $e) {
         $errors = $e->getErrors();
         foreach (['location', 'port', 'credentials.name', 'credentials.password', 'method', 'headers', 'parameters', 'options', 'http_method'] as $key) {
             $this->assertArrayHasKey($key, $errors, 'Missing validation error for: ' . $key);
         }
     }
 }
 /**
  * Prepares and returns guzzle options array for next call
  *
  * @param ServiceRequestInterface $request
  * @param null|string             $httpMethod
  * @return array
  */
 protected function prepareGuzzleOptions(ServiceRequestInterface $request, $httpMethod = null)
 {
     if ($this->isMultipartFormRequest()) {
         $this->enableMultipart();
     } else {
         $this->disableMultipart();
     }
     $headers = $request->getHeaders() ?: [];
     if ($this->debugUser) {
         $headers = array_merge($headers, ['debug-user' => $this->debugUser]);
     } else {
         if (array_key_exists('debug-user', $headers)) {
             unset($headers['debug-user']);
         }
     }
     $request->setHeaders($headers);
     return parent::prepareGuzzleOptions($request, $httpMethod);
 }