public function testSignRequest() { /** @var \Mockery\Mock $securityHelper */ $securityHelper = \Mockery::mock('alias:\\Hitmeister\\Component\\Api\\Helper\\Security'); $securityHelper->shouldReceive('signRequest')->withArgs(['client_secret', 'POST', \Mockery::any(), 'the_body', \Mockery::any()])->andReturn('the_signature'); /** @var \Mockery\Mock $coreHelper */ $coreHelper = \Mockery::mock('alias:\\GuzzleHttp\\Ring\\Core'); $coreHelper->shouldReceive('url')->withArgs([\Mockery::type('array')]); // Fake handler $handler = function (array $request) { return $request; }; $middleware = Middleware::signRequest($handler, 'client_key', 'client_secret'); $result = $middleware(['http_method' => 'POST', 'body' => 'the_body', 'headers' => []]); $this->assertTrue(is_array($result)); $this->assertArrayHasKey('headers', $result); $this->assertTrue(is_array($result['headers'])); $this->assertArrayHasKey('HM-Client', $result['headers']); $this->assertArrayHasKey('HM-Timestamp', $result['headers']); $this->assertArrayHasKey('HM-Signature', $result['headers']); $this->assertEquals('the_signature', $result['headers']['HM-Signature'][0]); $this->assertEquals('client_key', $result['headers']['HM-Client'][0]); }
public function testBodyReadyJson() { $body = '["foo", {"bar":["baz", null, 1.0, 2]}]'; $stream = fopen('php://memory', 'r+'); fwrite($stream, $body); rewind($stream); $this->response['body'] = $stream; $request = ['http_method' => 'PUT', 'headers' => []]; $ff = $this->futureFunc; $handler = $ff($this->response); $middleware = Middleware::processResponse($handler, $this->logger); /** @var FutureArray $future */ $future = $middleware($request); $result = $future->wait(); $this->assertTrue(is_array($result)); $this->assertArrayHasKey('body', $result); $this->assertJson($result['body']); $this->assertArrayHasKey('json', $result); $this->assertNotNull($result['json']); }
/** * @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); }