Esempio n. 1
0
 /** @test */
 public function itThrowAnExceptionWhenNoRequestDefinitionIsFound()
 {
     $this->expectException(\InvalidArgumentException::class);
     $this->expectExceptionMessage('Unable to get the request definition for getPet');
     $requests = $this->prophesize(RequestDefinitions::class);
     $requests->getIterator()->willReturn(new \ArrayIterator());
     $schema = new Schema($requests->reveal(), '/api');
     $schema->getRequestDefinition('getPet');
 }
Esempio n. 2
0
 /**
  * Configure the base uri from using the API Schema if no baseUri is provided
  * Or from the baseUri config if provided
  *
  * @return UriInterface
  */
 private function getBaseUri()
 {
     // Create a base uri from the API Schema
     if ($this->config['baseUri'] === null) {
         $scheme = null;
         $schemes = $this->schema->getSchemes();
         if ($schemes === null) {
             throw new \LogicException('You need to provide at least on scheme in your API Schema');
         }
         foreach ($this->schema->getSchemes() as $candidate) {
             // Always prefer https
             if ($candidate === 'https') {
                 $scheme = 'https';
             }
             if ($scheme === null && $candidate === 'http') {
                 $scheme = 'http';
             }
         }
         if ($scheme === null) {
             throw new \RuntimeException('Cannot choose a proper scheme from the API Schema. Supported: https, http');
         }
         $host = $this->schema->getHost();
         if ($host === null) {
             throw new \LogicException('The host in the API Schema should not be null');
         }
         return $this->uriFactory->createUri($scheme . '://' . $host);
     } else {
         return $this->uriFactory->createUri($this->config['baseUri']);
     }
 }