public function setUp() { $response = $this->createResponse(); $mockAdapter = new MockAdapter(); $mockAdapter->setResponse($response); $client = new Client(['adapter' => $mockAdapter]); $this->adapter = new GuzzleAdapter($client); }
public function testReadsRequestBody() { $response = new Response(200); $m = new MockAdapter($response); $m->setResponse($response); $body = Stream::factory('foo'); $request = new Request('PUT', 'http://httpbin.org/put', [], $body); $this->assertSame($response, $m->send(new Transaction(new Client(), $request))); $this->assertEquals(3, $body->tell()); }
public function testSendingRequestCanBeIntercepted() { $response = new Response(200); $response2 = new Response(200); $adapter = new MockAdapter(); $adapter->setResponse($response); $client = new Client(['adapter' => $adapter]); $client->getEmitter()->on('before', function (BeforeEvent $e) use($response2) { $e->intercept($response2); }); $this->assertSame($response2, $client->get('http://test.com')); $this->assertEquals('http://test.com', $response2->getEffectiveUrl()); }
public function testItShouldThrowAnExceptionWhenAnApiErrorIsReturned() { $this->mock->setResponse(new Response(200, [], Stream::factory(file_get_contents(__DIR__ . '/fixtures/invalidApiKey.json')))); $this->setExpectedException('Symm\\ViewRangerClient\\Exception\\ViewRangerClientException'); $this->client->getLastBeaconPosition('*****@*****.**', 1234); }