Exemplo n.º 1
0
 public function testSetters()
 {
     /** @var \Psr\Log\LoggerInterface $logger */
     $logger = \Mockery::mock('\\Psr\\Log\\LoggerInterface');
     $handler1 = function (array $request) {
     };
     $handler2 = function (array $request) {
     };
     /** @var \Hitmeister\Component\Api\Transport\Transport $transport */
     $transport = \Mockery::mock('\\Hitmeister\\Component\\Api\\Transport\\Transport');
     /** @var \Mockery\Mock $middleware */
     $middleware = \Mockery::mock('alias:\\Hitmeister\\Component\\Api\\Middleware');
     $middleware->shouldReceive('signRequest')->withArgs([$handler1, 'client_key', 'client_secret'])->andReturn($handler2);
     $middleware->shouldReceive('processResponse')->withArgs([$handler2, $logger]);
     $builder = ClientBuilder::create()->setLogger($logger)->setHandler($handler1)->setTransport($transport)->setClientKey('client_key')->setClientSecret('client_secret')->setBaseUrl('https://www.hm.de/api/v20/');
     $client = $builder->build();
     $this->assertEquals($transport, $client->getTransport());
 }
Exemplo n.º 2
0
 /**
  * @return Client
  */
 public function build()
 {
     $this->validate();
     if (null === $this->logger) {
         $this->logger = new NullLogger();
     }
     if (null === $this->handler) {
         $this->handler = ClientBuilder::defaultHandler();
     }
     $this->handler = Middleware::signRequest($this->handler, $this->clientKey, $this->clientSecret);
     $this->handler = Middleware::processResponse($this->handler, $this->logger);
     if (null === $this->transport) {
         $this->transport = new Transport($this->handler, new RequestBuilder($this->baseUrl));
     }
     return new Client($this->transport);
 }