builder() public static method

Create a rest adapter builder
public static builder ( ) : RestAdapterBuilder
return RestAdapterBuilder
 protected function getClient($service, HttpClientAdapter $httpClient, SerializerInterface $serializer)
 {
     $builder = RestAdapter::builder()->setBaseUrl('http://mockservice.com');
     $builder->setHttpClient($httpClient);
     $builder->setSerializer($serializer);
     return $builder->build()->create($service);
 }
 public function testWillUseInterface()
 {
     $httpClient = Mockery::mock(Client::class);
     $serializer = Mockery::mock(Serializer::class);
     $adapter = RestAdapter::builder()->setBaseUrl('')->setHttpClient($httpClient)->setSerializer($serializer)->build();
     $generatedClass = new \Tebru\Retrofit\Service\Tebru\Retrofit\Test\Mock\MockService('', $httpClient, $serializer);
     $service = $adapter->create(MockService::class);
     $this->assertEquals($generatedClass, $service);
 }
 public static function make($apiKey, $baseUrl, ClientInterface $client = null, SerializerBuilder $serializerBuilder = null)
 {
     if (null === $client) {
         $client = new Client(['exceptions' => false, 'auth' => [$apiKey, null]]);
     }
     if (null === $serializerBuilder) {
         $serializerBuilder = SerializerBuilder::create();
     }
     $serializer = $serializerBuilder->build();
     return RestAdapter::builder()->setBaseUrl($baseUrl)->setHttpClient($client)->setSerializer($serializer)->build();
 }
 public function testWillUseInterface()
 {
     $httpClient = Mockery::mock(HttpClientAdapter::class);
     $serializer = Mockery::mock(Serializer::class);
     $eventDispatcher = Mockery::mock(EventDispatcherInterface::class);
     $eventDispatcher->shouldReceive('addSubscriber')->times(1);
     $logger = Mockery::mock(LoggerInterface::class);
     $adapter = RestAdapter::builder()->setBaseUrl('')->setClientAdapter($httpClient)->setSerializer($serializer)->setEventDispatcher($eventDispatcher)->setLogger($logger)->build();
     $generatedClass = new \Tebru\Retrofit\Generated\Tebru\Retrofit\Test\Mock\Service\MockServiceUrlRequest('', $httpClient, $serializer, $eventDispatcher, $logger);
     $service = $adapter->create(MockServiceUrlRequest::class);
     $this->assertEquals($generatedClass, $service);
 }
Example #5
0
 /**
  * @return ApiClient
  * @throws RetrofitException
  */
 private function getClient()
 {
     $defaults = ['auth' => ['user', 'password'], 'exceptions' => false];
     $clientAdapter = version_compare(Client::VERSION, '6', '<') ? new GuzzleV5ClientAdapter(new Client(['defaults' => $defaults])) : new GuzzleV6ClientAdapter(new Client($defaults));
     $restAdapter = RestAdapter::builder()->setBaseUrl('http://127.0.0.1:8000')->setClientAdapter($clientAdapter)->build();
     return $restAdapter->create(ApiClient::class);
 }
 /**
  * @return RestAdapterBuilder
  */
 private function getRestAdapterBuilder()
 {
     return RestAdapter::builder()->setBaseUrl('http://example.com');
 }
 /**
  * @return RestAdapterBuilder
  */
 private function getRestAdapterBuilder()
 {
     return RestAdapter::builder()->setBaseUrl('http://example.com')->setHttpClient(Mockery::mock(HttpClientAdapter::class));
 }
 /**
  * @param string $method
  * @param string $path
  * @param array  $options
  * @param array  $query
  * @param array  $headers
  * @param bool   $jsonBody
  * @param bool   $baseUrl
  *
  * @return RestAdapterBuilder
  */
 private function createBuilder($method, $path, $options = [], $query = [], $headers = [], $jsonBody = false, $baseUrl = false)
 {
     $request = Mockery::mock(RequestInterface::class);
     if (!empty($query)) {
         $request->shouldReceive('setQuery')->times(1)->with($query)->andReturnNull();
     }
     if (!empty($headers)) {
         $request->shouldReceive('addHeaders')->times(1)->with($headers)->andReturnNull();
     }
     if (true === $jsonBody) {
         $request->shouldReceive('hasHeader')->times(1)->with('Content-Type')->andReturn(false);
         $request->shouldReceive('setHeader')->times(1)->with('Content-Type', 'application/json')->andReturnNull();
     }
     $response = Mockery::mock(ResponseInterface::class);
     $response->shouldReceive('getBody')->times(1)->withNoArgs()->andReturn($this->serializeUser($this->getUser()));
     $httpClient = Mockery::mock(ClientInterface::class);
     $requestUrl = $baseUrl ? $path : self::BASE_URL . $path;
     $httpClient->shouldReceive('createRequest')->times(1)->with($method, $requestUrl, $options)->andReturn($request);
     $httpClient->shouldReceive('send')->times(1)->with($request)->andReturn($response);
     $builder = RestAdapter::builder()->setBaseUrl(self::BASE_URL);
     $builder->setHttpClient($httpClient);
     return $builder;
 }
 protected function setUp()
 {
     $restAdapter = RestAdapter::builder()->setBaseUrl('http://localhost:5000')->build();
     $this->client = $restAdapter->create(CannedClient::class);
     self::$pathToJson = __DIR__ . '/../canned';
 }