Skip to content

Commit 47582e3

Browse files
committed
Use streaming parser for Client::createImage()
1 parent eb0a79a commit 47582e3

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/Client.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Clue\React\Buzz\Message\Response;
77
use Clue\React\Docker\Io\ResponseParser;
88
use React\Promise\PromiseInterface as Promise;
9+
use Clue\React\Docker\Io\StreamingParser;
910

1011
/**
1112
* Docker Remote API client
@@ -20,6 +21,7 @@ class Client
2021
private $browser;
2122
private $url;
2223
private $parser;
24+
private $streamingParser;
2325

2426
/**
2527
* Instantiate new Client
@@ -31,15 +33,20 @@ class Client
3133
* @param ResponseParser|null $parser
3234
* @see Factory::createClient()
3335
*/
34-
public function __construct(Browser $browser, $url, ResponseParser $parser = null)
36+
public function __construct(Browser $browser, $url, ResponseParser $parser = null, StreamingParser $streamingParser = null)
3537
{
3638
if ($parser === null) {
3739
$parser = new ResponseParser();
3840
}
3941

42+
if ($streamingParser === null) {
43+
$streamingParser = new StreamingParser();
44+
}
45+
4046
$this->browser = $browser;
4147
$this->url = $url;
4248
$this->parser = $parser;
49+
$this->streamingParser = $streamingParser;
4350
}
4451

4552
/**
@@ -305,10 +312,10 @@ public function imageList($all = false)
305312
*/
306313
public function imageCreate($fromImage = null, $fromSrc = null, $repo = null, $tag = null, $registry = null, $registryAuth = null)
307314
{
308-
return $this->browser->post(
315+
return $this->streamingParser->parseResponse($this->browser->post(
309316
$this->url('/images/create?fromImage=%s&fromSrc=%s&repo=%s&tag=%s&registry=%s', $fromImage, $fromSrc, $repo, $tag, $registry),
310317
$this->authHeaders($registryAuth)
311-
)->then(array($this->parser, 'expectJson'));
318+
))->then(array($this->parser, 'expectJson'));
312319
}
313320

314321
/**

tests/ClientTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ class ClientTest extends TestCase
99
{
1010
private $browser;
1111
private $parser;
12+
private $streamingParser;
1213
private $client;
1314

1415
public function setUp()
1516
{
1617
$this->browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
1718
$this->parser = $this->getMock('Clue\React\Docker\Io\ResponseParser');
18-
$this->client = new Client($this->browser, '', $this->parser);
19+
$this->streamingParser = $this->getMock('Clue\React\Docker\Io\StreamingParser');
20+
$this->client = new Client($this->browser, '', $this->parser, $this->streamingParser);
1921
}
2022

2123
public function testPing()
@@ -183,6 +185,7 @@ public function testImageList()
183185
public function testImageCreate()
184186
{
185187
$json = array();
188+
$this->streamingParser->expects($this->once())->method('parseResponse')->will($this->returnArgument(0));
186189
$this->expectRequestFlow('post', '/images/create?fromImage=busybox&fromSrc=&repo=&tag=&registry=', $this->createResponseJson($json), 'expectJson');
187190

188191
$this->expectPromiseResolveWith($json, $this->client->imageCreate('busybox'));

0 commit comments

Comments
 (0)