From 566d90d7cd17ff4917f65665a00429a54c831b55 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Sun, 5 Jun 2016 15:14:17 +0200 Subject: [PATCH] readd default URI for client implementation for BC --- src/Client.php | 6 +++--- tests/ClientTest.php | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index 345a57a8..a7de8be1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -104,7 +104,7 @@ class Client implements ClientInterface return $this->sendAsync($request, $options)->wait(); } - public function requestAsync($method, $uri, array $options = []) + public function requestAsync($method, $uri = '', array $options = []) { $options = $this->prepareDefaults($options); // Remove request modifying parameter because it can be done up-front. @@ -123,7 +123,7 @@ class Client implements ClientInterface return $this->transfer($request, $options); } - public function request($method, $uri, array $options = []) + public function request($method, $uri = '', array $options = []) { $options[RequestOptions::SYNCHRONOUS] = true; return $this->requestAsync($method, $uri, $options)->wait(); @@ -142,7 +142,7 @@ class Client implements ClientInterface return $uri instanceof UriInterface ? $uri : new Psr7\Uri($uri); } - return Psr7\Uri::resolve($config['base_uri'], $uri); + return Psr7\Uri::resolve(Psr7\uri_for($config['base_uri']), $uri); } /** diff --git a/tests/ClientTest.php b/tests/ClientTest.php index ac12f65a..6b74a2d0 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -87,7 +87,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase public function testCanMergeOnBaseUriWithRequest() { - $mock = new MockHandler([new Response()]); + $mock = new MockHandler([new Response(), new Response()]); $client = new Client([ 'handler' => $mock, 'base_uri' => 'http://foo.com/bar/' @@ -97,6 +97,13 @@ class ClientTest extends \PHPUnit_Framework_TestCase 'http://foo.com/bar/baz', (string) $mock->getLastRequest()->getUri() ); + + $client->request('GET', new Uri('baz'), ['base_uri' => 'http://example.com/foo/']); + $this->assertEquals( + 'http://example.com/foo/baz', + (string) $mock->getLastRequest()->getUri(), + 'Can overwrite the base_uri through the request options' + ); } public function testCanUseRelativeUriWithSend()