Skip to content

Commit ec8d64e

Browse files
committed
Move base URI from Client to Factory
1 parent 9e33545 commit ec8d64e

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/Client.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ class Client
2929
* SHOULD NOT be called manually, see Factory::createClient() instead
3030
*
3131
* @param Browser $browser
32-
* @param string $url
3332
* @param ResponseParser|null $parser
3433
* @see Factory::createClient()
3534
*/
36-
public function __construct(Browser $browser, $url, ResponseParser $parser = null, StreamingParser $streamingParser = null)
35+
public function __construct(Browser $browser, ResponseParser $parser = null, StreamingParser $streamingParser = null)
3736
{
3837
if ($parser === null) {
3938
$parser = new ResponseParser();
@@ -43,7 +42,7 @@ public function __construct(Browser $browser, $url, ResponseParser $parser = nul
4342
$streamingParser = new StreamingParser();
4443
}
4544

46-
$this->browser = $browser->withBase($url);
45+
$this->browser = $browser;
4746
$this->parser = $parser;
4847
$this->streamingParser = $streamingParser;
4948
}

src/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ public function createClient($url = null)
4040
$url = 'http://localhost/';
4141
}
4242

43-
return new Client($browser, $url);
43+
return new Client($browser->withBase($url));
4444
}
4545
}

tests/ClientTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ public function setUp()
2121
$this->loop = $this->getMock('React\EventLoop\LoopInterface');
2222
$this->sender = $this->getMockBuilder('Clue\React\Buzz\Io\Sender')->disableOriginalConstructor()->getMock();
2323
$this->browser = new Browser($this->loop, $this->sender);
24+
$this->browser = $this->browser->withBase('http://x/');
2425

2526
$this->parser = $this->getMock('Clue\React\Docker\Io\ResponseParser');
2627
$this->streamingParser = $this->getMock('Clue\React\Docker\Io\StreamingParser');
27-
$this->client = new Client($this->browser, 'http://x/', $this->parser, $this->streamingParser);
28+
$this->client = new Client($this->browser, $this->parser, $this->streamingParser);
2829
}
2930

3031
public function testPing()

tests/FactoryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function testCtorDefaultBrowser()
2424
public function testCreateClientUsesCustomUnixSender()
2525
{
2626
$this->browser->expects($this->once())->method('withSender')->will($this->returnValue($this->browser));
27+
$this->browser->expects($this->once())->method('withBase')->will($this->returnValue($this->browser));
2728

2829
$client = $this->factory->createClient();
2930

@@ -33,6 +34,7 @@ public function testCreateClientUsesCustomUnixSender()
3334
public function testCreateClientWithHttp()
3435
{
3536
$this->browser->expects($this->never())->method('withSender');
37+
$this->browser->expects($this->once())->method('withBase')->with($this->equalTo('http://localhost:1234/'))->will($this->returnValue($this->browser));
3638

3739
$this->factory->createClient('http://localhost:1234/');
3840
}

0 commit comments

Comments
 (0)