From 64b1c6e7df79d4c2c4bdf66c26d5931339b70346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 3 Jul 2020 20:50:51 +0200 Subject: [PATCH 1/3] Update to clue/reactphp-buzz v2.9.0 --- composer.json | 2 +- src/Client.php | 25 ++++++++----- tests/ClientTest.php | 89 +++++++++++++++----------------------------- 3 files changed, 48 insertions(+), 68 deletions(-) diff --git a/composer.json b/composer.json index 9a0abe3..3158a4b 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require": { "php": ">=5.3", - "clue/buzz-react": "^2.0", + "clue/buzz-react": "^2.9", "clue/json-stream": "^0.1", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", "react/promise": "^2.0 || ^1.1", diff --git a/src/Client.php b/src/Client.php index 4d87863..46f5e89 100644 --- a/src/Client.php +++ b/src/Client.php @@ -161,7 +161,8 @@ public function events($since = null, $until = null, $filters = array()) public function eventsStream($since = null, $until = null, $filters = array()) { return $this->streamingParser->parseJsonStream( - $this->browser->withOptions(array('streaming' => true))->get( + $this->browser->requestStreaming( + 'GET', $this->uri->expand( '/events{?since,until,filters}', array( @@ -352,7 +353,7 @@ public function containerLogsStream($container, $follow = false, $stdout = true, // first inspect container to check TTY setting, then request logs with appropriate log parser return \React\Promise\Stream\unwrapReadable($this->containerInspect($container)->then(function ($info) use ($url, $browser, $parser, $stderrEvent) { - $stream = $parser->parsePlainStream($browser->withOptions(array('streaming' => true))->get($url)); + $stream = $parser->parsePlainStream($browser->requestStreaming('GET', $url)); if (!$info['Config']['Tty']) { $stream = $parser->demultiplexStream($stream, $stderrEvent); @@ -438,7 +439,8 @@ public function containerExport($container) public function containerExportStream($container) { return $this->streamingParser->parsePlainStream( - $this->browser->withOptions(array('streaming' => true))->get( + $this->browser->requestStreaming( + 'GET', $this->uri->expand( '/containers/{container}/export', array( @@ -495,7 +497,8 @@ public function containerStats($container) public function containerStatsStream($container) { return $this->streamingParser->parseJsonStream( - $this->browser->withOptions(array('streaming' => true))->get( + $this->browser->requestStreaming( + 'GET', $this->uri->expand( '/containers/{container}/stats', array( @@ -762,7 +765,7 @@ public function containerAttachStream($container, $logs = false, $stream = false // first inspect container to check TTY setting, then attach with appropriate log parser return \React\Promise\Stream\unwrapReadable($this->containerInspect($container)->then(function ($info) use ($url, $browser, $parser, $stderrEvent) { - $stream = $parser->parsePlainStream($browser->withOptions(array('streaming' => true))->post($url)); + $stream = $parser->parsePlainStream($browser->requestStreaming('POST', $url)); if (!$info['Config']['Tty']) { $stream = $parser->demultiplexStream($stream, $stderrEvent); @@ -878,7 +881,8 @@ public function containerArchive($container, $path) public function containerArchiveStream($container, $path) { return $this->streamingParser->parsePlainStream( - $this->browser->withOptions(array('streaming' => true))->get( + $this->browser->requestStreaming( + 'GET', $this->uri->expand( '/containers/{container}/archive{?path}', array( @@ -968,7 +972,8 @@ public function imageCreate($fromImage = null, $fromSrc = null, $repo = null, $t public function imageCreateStream($fromImage = null, $fromSrc = null, $repo = null, $tag = null, $registry = null, $registryAuth = null) { return $this->streamingParser->parseJsonStream( - $this->browser->withOptions(array('streaming' => true))->post( + $this->browser->requestStreaming( + 'POST', $this->uri->expand( '/images/create{?fromImage,fromSrc,repo,tag,registry}', array( @@ -1075,7 +1080,8 @@ public function imagePush($image, $tag = null, $registry = null, $registryAuth = public function imagePushStream($image, $tag = null, $registry = null, $registryAuth = null) { return $this->streamingParser->parseJsonStream( - $this->browser->withOptions(array('streaming' => true))->post( + $this->browser->requestStreaming( + 'POST', $this->uri->expand( '/images{/registry}/{image}/push{?tag}', array( @@ -1303,7 +1309,8 @@ public function execStartDetached($exec, $tty = false) public function execStartStream($exec, $tty = false, $stderrEvent = null) { $stream = $this->streamingParser->parsePlainStream( - $this->browser->withOptions(array('streaming' => true))->post( + $this->browser->requestStreaming( + 'POST', $this->uri->expand( '/exec/{exec}/start', array( diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 732c152..b3bcd3a 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -56,7 +56,7 @@ public function testCtorWithExplicitUnixPath() $ref->setAccessible(true); $browser = $ref->getValue($client); - $ref = new \ReflectionProperty($browser, 'baseUri'); + $ref = new \ReflectionProperty($browser, 'baseUrl'); $ref->setAccessible(true); $url = $ref->getValue($browser); @@ -71,7 +71,7 @@ public function testCtorWithExplicitHttpUrl() $ref->setAccessible(true); $browser = $ref->getValue($client); - $ref = new \ReflectionProperty($browser, 'baseUri'); + $ref = new \ReflectionProperty($browser, 'baseUrl'); $ref->setAccessible(true); $url = $ref->getValue($browser); @@ -99,7 +99,7 @@ public function testEvents() $json = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('GET', '/events', $this->createResponseJsonStream($json)); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/events')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('deferredStream')->with($this->equalTo($stream))->will($this->returnPromise($json)); @@ -111,7 +111,7 @@ public function testEventsArgs() $json = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('GET', '/events?since=10&until=20&filters=%7B%22image%22%3A%5B%22busybox%22%2C%22ubuntu%22%5D%7D', $this->createResponseJsonStream($json)); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/events?since=10&until=20&filters=%7B%22image%22%3A%5B%22busybox%22%2C%22ubuntu%22%5D%7D')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('deferredStream')->with($this->equalTo($stream))->will($this->returnPromise($json)); @@ -192,14 +192,8 @@ public function testContainerLogsRejectsWhenInspectingContainerRejects() public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerResolvesWithTtyAndContainerLogsRequestIsPending() { - $this->browser->expects($this->once())->method('withOptions')->willReturnSelf(); - $this->browser->expects($this->exactly(2))->method('get')->withConsecutive( - array('/containers/123/json'), - array('/containers/123/logs?stdout=1&stderr=1') - )->willReturnOnConsecutiveCalls( - \React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}')), - new \React\Promise\Promise(function () { }) - ); + $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/logs?stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(new \React\Promise\Promise(function () { })); @@ -213,14 +207,8 @@ public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerRes public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerResolvesWithoutTtyAndContainerLogsRequestIsPending() { - $this->browser->expects($this->once())->method('withOptions')->willReturnSelf(); - $this->browser->expects($this->exactly(2))->method('get')->withConsecutive( - array('/containers/123/json'), - array('/containers/123/logs?stdout=1&stderr=1') - )->willReturnOnConsecutiveCalls( - \React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":false}}')), - new \React\Promise\Promise(function () { }) - ); + $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":false}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/logs?stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => false))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(new \React\Promise\Promise(function () { })); @@ -234,14 +222,8 @@ public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerRes public function testContainerLogsResolvesWhenInspectingContainerResolvesWithTtyAndContainerLogsRequestResolves() { - $this->browser->expects($this->once())->method('withOptions')->willReturnSelf(); - $this->browser->expects($this->exactly(2))->method('get')->withConsecutive( - array('/containers/123/json'), - array('/containers/123/logs?stdout=1&stderr=1') - )->willReturnOnConsecutiveCalls( - \React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}')), - \React\Promise\resolve(new Response(200, array(), '')) - ); + $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/logs?stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(\React\Promise\resolve('output')); @@ -255,14 +237,8 @@ public function testContainerLogsResolvesWhenInspectingContainerResolvesWithTtyA public function testContainerLogsStreamReturnStreamWhenInspectingContainerResolvesWithTtyAndContainerLogsRequestResolves() { - $this->browser->expects($this->once())->method('withOptions')->willReturnSelf(); - $this->browser->expects($this->exactly(2))->method('get')->withConsecutive( - array('/containers/123/json'), - array('/containers/123/logs?stdout=1&stderr=1') - )->willReturnOnConsecutiveCalls( - \React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}')), - \React\Promise\resolve(new Response(200, array(), '')) - ); + $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/logs?stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); $response = new ThroughStream(); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); @@ -287,7 +263,7 @@ public function testContainerExportStream() { $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('get', '/containers/123/export', $this->createResponse('')); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/export')->willReturn(\React\Promise\resolve($this->createResponse(''))); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->assertSame($stream, $this->client->containerExportStream(123)); @@ -403,9 +379,8 @@ public function testContainerAttachRejectsWhenInspectingContainerRejects() public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerResolvesWithTtyAndContainerAttachIsPending() { - $this->browser->expects($this->once())->method('withOptions')->willReturnSelf(); $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); - $this->browser->expects($this->once())->method('post')->with('/containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(new \React\Promise\Promise(function () { })); @@ -419,9 +394,8 @@ public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerR public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerResolvesWithoutTtyAndContainerAttachRequestIsPending() { - $this->browser->expects($this->once())->method('withOptions')->willReturnSelf(); $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":false}}'))); - $this->browser->expects($this->once())->method('post')->with('/containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => false))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(new \React\Promise\Promise(function () { })); @@ -435,9 +409,8 @@ public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerR public function testContainerAttachResolvesWhenInspectingContainerResolvesWithTtyAndContainerAttachResolvesAndContainerAttachRequestResolves() { - $this->browser->expects($this->once())->method('withOptions')->willReturnSelf(); $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); - $this->browser->expects($this->once())->method('post')->with('/containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(\React\Promise\resolve('output')); @@ -451,9 +424,8 @@ public function testContainerAttachResolvesWhenInspectingContainerResolvesWithTt public function testContainerAttachStreamReturnStreamWhenInspectingContainerResolvesWithTtyAndContainerAttachRequestResolves() { - $this->browser->expects($this->once())->method('withOptions')->willReturnSelf(); $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); - $this->browser->expects($this->once())->method('post')->with('/containers/123/attach?logs=1&stream=1&stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/containers/123/attach?logs=1&stream=1&stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); $response = new ThroughStream(); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); @@ -491,7 +463,7 @@ public function testContainerStatsStream() { $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('GET', '/containers/123/stats', $this->createResponse('')); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/stats')->willReturn(\React\Promise\resolve($this->createResponse(''))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->assertSame($stream, $this->client->containerStatsStream('123')); @@ -507,7 +479,9 @@ public function testContainerResize() public function testContainerArchive() { $data = 'tar stream'; - $this->expectRequestFlow('GET', '/containers/123/archive?path=file.txt', $this->createResponse($data), 'expectPlain'); + + $this->browser->expects($this->once())->method('get')->with('/containers/123/archive?path=file.txt')->willReturn(\React\Promise\resolve($this->createResponse($data))); + $this->parser->expects($this->once())->method('expectPlain')->will($this->returnValue($data)); $this->expectPromiseResolveWith($data, $this->client->containerArchive('123', 'file.txt')); } @@ -516,7 +490,7 @@ public function testContainerArchiveStream() { $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('GET', '/containers/123/archive?path=file.txt', $this->createResponse('')); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/archive?path=file.txt')->willReturn(\React\Promise\resolve($this->createResponse(''))); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->assertSame($stream, $this->client->containerArchiveStream('123', 'file.txt')); @@ -543,7 +517,7 @@ public function testImageCreate() $json = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('post', '/images/create?fromImage=busybox', $this->createResponseJsonStream($json)); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/images/create?fromImage=busybox')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('deferredStream')->with($this->equalTo($stream))->will($this->returnPromise($json)); @@ -554,7 +528,7 @@ public function testImageCreateStream() { $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('post', '/images/create?fromImage=busybox', $this->createResponseJsonStream(array())); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/images/create?fromImage=busybox')->willReturn(\React\Promise\resolve($this->createResponseJsonStream(array()))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->assertSame($stream, $this->client->imageCreateStream('busybox')); @@ -581,7 +555,7 @@ public function testImagePush() $json = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('post', '/images/123/push', $this->createResponseJsonStream($json)); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/images/123/push')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('deferredStream')->with($this->equalTo($stream))->will($this->returnPromise($json)); @@ -592,7 +566,7 @@ public function testImagePushStream() { $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('post', '/images/123/push', $this->createResponseJsonStream(array())); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/images/123/push')->willReturn(\React\Promise\resolve($this->createResponseJsonStream(array()))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->assertSame($stream, $this->client->imagePushStream('123')); @@ -605,7 +579,7 @@ public function testImagePushCustomRegistry() $json = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('post', '/images/demo.acme.com%3A5000/123/push?tag=test', $this->createResponseJsonStream($json)); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/images/demo.acme.com%3A5000/123/push?tag=test')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('deferredStream')->with($this->equalTo($stream))->will($this->returnPromise($json)); @@ -678,7 +652,7 @@ public function testExecStart() $config = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('POST', '/exec/123/start', $this->createResponse($data)); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse($data))); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('demultiplexStream')->with($stream)->willReturn($stream); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->equalTo($stream))->willReturn(\React\Promise\resolve($data)); @@ -691,7 +665,7 @@ public function testExecStartStreamWithoutTtyWillDemultiplex() $config = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('POST', '/exec/123/start', $this->createResponse()); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse())); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('demultiplexStream')->with($stream)->willReturn($stream); @@ -703,7 +677,7 @@ public function testExecStartStreamWithTtyWillNotDemultiplex() $config = array('Tty' => true); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('POST', '/exec/123/start', $this->createResponse()); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse())); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->never())->method('demultiplexStream'); @@ -715,7 +689,7 @@ public function testExecStartStreamWithCustomStderrEvent() $config = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->expectRequest('POST', '/exec/123/start', $this->createResponse()); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse())); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('demultiplexStream')->with($stream, 'stderr')->willReturn($stream); @@ -808,7 +782,6 @@ private function expectRequestFlow($method, $url, ResponseInterface $response, $ private function expectRequest($method, $url, ResponseInterface $response) { - $this->browser->expects($this->any())->method('withOptions')->willReturnSelf(); $this->browser->expects($this->once())->method(strtolower($method))->with($url)->willReturn(\React\Promise\resolve($response)); } From b42931565347958c4a160e8b1cce2750198810c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 18 Jul 2020 15:41:26 +0200 Subject: [PATCH 2/3] Update to react/http v1.0.0 --- composer.json | 2 +- src/Client.php | 2 +- tests/ClientTest.php | 2 +- tests/FunctionalClientTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 3158a4b..5fada8a 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,9 @@ }, "require": { "php": ">=5.3", - "clue/buzz-react": "^2.9", "clue/json-stream": "^0.1", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", + "react/http": "^1.0", "react/promise": "^2.0 || ^1.1", "react/promise-stream": "^1.0", "react/socket": "^1.0", diff --git a/src/Client.php b/src/Client.php index 46f5e89..49d972a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -2,10 +2,10 @@ namespace Clue\React\Docker; -use Clue\React\Buzz\Browser; use Clue\React\Docker\Io\ResponseParser; use Clue\React\Docker\Io\StreamingParser; use React\EventLoop\LoopInterface; +use React\Http\Browser; use React\Promise\PromiseInterface; use React\Stream\ReadableStreamInterface; use Rize\UriTemplate; diff --git a/tests/ClientTest.php b/tests/ClientTest.php index b3bcd3a..38f2fcd 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -20,7 +20,7 @@ class ClientTest extends TestCase public function setUp() { $this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); - $this->browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock(); + $this->browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock(); $this->parser = $this->getMockBuilder('Clue\React\Docker\Io\ResponseParser')->getMock(); $this->streamingParser = $this->getMockBuilder('Clue\React\Docker\Io\StreamingParser')->getMock(); diff --git a/tests/FunctionalClientTest.php b/tests/FunctionalClientTest.php index 8e5e31c..f0b46f4 100644 --- a/tests/FunctionalClientTest.php +++ b/tests/FunctionalClientTest.php @@ -399,7 +399,7 @@ public function testImageCreateStreamMissingWillEmitJsonError() // will emit "error" with RuntimeException and close $old && $stream->on('error', $this->expectCallableOnceParameter('RuntimeException')); - $old || $stream->on('error', $this->expectCallableOnceParameter('Clue\React\Buzz\Message\ResponseException')); + $old || $stream->on('error', $this->expectCallableOnceParameter('React\Http\Message\ResponseException')); $stream->on('close', $this->expectCallableOnce()); $this->loop->run(); From 4fea9558528f77661d3b55bc6c43554595c6dcaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 26 Jul 2020 15:22:42 +0200 Subject: [PATCH 3/3] Update to obey base URL path when given explicitly Refs https://github.com/reactphp/http/pull/379 --- src/Client.php | 94 +++++++++---------- tests/ClientTest.php | 190 ++++++++++++++++---------------------- tests/IntegrationTest.php | 63 +++++++++++++ 3 files changed, 190 insertions(+), 157 deletions(-) create mode 100644 tests/IntegrationTest.php diff --git a/src/Client.php b/src/Client.php index 49d972a..cb0230c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -70,7 +70,7 @@ public function __construct(LoopInterface $loop, $url = null) */ public function ping() { - return $this->browser->get('/_ping')->then(array($this->parser, 'expectPlain')); + return $this->browser->get('_ping')->then(array($this->parser, 'expectPlain')); } /** @@ -81,7 +81,7 @@ public function ping() */ public function info() { - return $this->browser->get('/info')->then(array($this->parser, 'expectJson')); + return $this->browser->get('info')->then(array($this->parser, 'expectJson')); } /** @@ -92,7 +92,7 @@ public function info() */ public function version() { - return $this->browser->get('/version')->then(array($this->parser, 'expectJson')); + return $this->browser->get('version')->then(array($this->parser, 'expectJson')); } /** @@ -164,7 +164,7 @@ public function eventsStream($since = null, $until = null, $filters = array()) $this->browser->requestStreaming( 'GET', $this->uri->expand( - '/events{?since,until,filters}', + 'events{?since,until,filters}', array( 'since' => $since, 'until' => $until, @@ -187,7 +187,7 @@ public function containerList($all = false, $size = false) { return $this->browser->get( $this->uri->expand( - '/containers/json{?all,size}', + 'containers/json{?all,size}', array( 'all' => $this->boolArg($all), 'size' => $this->boolArg($size) @@ -208,7 +208,7 @@ public function containerCreate($config, $name = null) { return $this->postJson( $this->uri->expand( - '/containers/create{?name}', + 'containers/create{?name}', array( 'name' => $name ) @@ -228,7 +228,7 @@ public function containerInspect($container) { return $this->browser->get( $this->uri->expand( - '/containers/{container}/json', + 'containers/{container}/json', array( 'container' => $container ) @@ -248,7 +248,7 @@ public function containerTop($container, $ps_args = null) { return $this->browser->get( $this->uri->expand( - '/containers/{container}/top{?ps_args}', + 'containers/{container}/top{?ps_args}', array( 'container' => $container, 'ps_args' => $ps_args @@ -339,7 +339,7 @@ public function containerLogsStream($container, $follow = false, $stdout = true, $parser = $this->streamingParser; $browser = $this->browser; $url = $this->uri->expand( - '/containers/{container}/logs{?follow,stdout,stderr,since,timestamps,tail}', + 'containers/{container}/logs{?follow,stdout,stderr,since,timestamps,tail}', array( 'container' => $container, 'follow' => $this->boolArg($follow), @@ -374,7 +374,7 @@ public function containerChanges($container) { return $this->browser->get( $this->uri->expand( - '/containers/{container}/changes', + 'containers/{container}/changes', array( 'container' => $container ) @@ -406,7 +406,7 @@ public function containerExport($container) { return $this->browser->get( $this->uri->expand( - '/containers/{container}/export', + 'containers/{container}/export', array( 'container' => $container ) @@ -442,7 +442,7 @@ public function containerExportStream($container) $this->browser->requestStreaming( 'GET', $this->uri->expand( - '/containers/{container}/export', + 'containers/{container}/export', array( 'container' => $container ) @@ -470,7 +470,7 @@ public function containerStats($container) { return $this->browser->get( $this->uri->expand( - '/containers/{container}/stats{?stream}', + 'containers/{container}/stats{?stream}', array( 'container' => $container, 'stream' => 0 @@ -500,7 +500,7 @@ public function containerStatsStream($container) $this->browser->requestStreaming( 'GET', $this->uri->expand( - '/containers/{container}/stats', + 'containers/{container}/stats', array( 'container' => $container ) @@ -522,7 +522,7 @@ public function containerResize($container, $w, $h) { return $this->browser->post( $this->uri->expand( - '/containers/{container}/resize{?w,h}', + 'containers/{container}/resize{?w,h}', array( 'container' => $container, 'w' => $w, @@ -543,7 +543,7 @@ public function containerStart($container) { return $this->browser->post( $this->uri->expand( - '/containers/{container}/start', + 'containers/{container}/start', array( 'container' => $container ) @@ -563,7 +563,7 @@ public function containerStop($container, $t = null) { return $this->browser->post( $this->uri->expand( - '/containers/{container}/stop{?t}', + 'containers/{container}/stop{?t}', array( 'container' => $container, 't' => $t @@ -584,7 +584,7 @@ public function containerRestart($container, $t = null) { return $this->browser->post( $this->uri->expand( - '/containers/{container}/restart{?t}', + 'containers/{container}/restart{?t}', array( 'container' => $container, 't' => $t @@ -605,7 +605,7 @@ public function containerKill($container, $signal = null) { return $this->browser->post( $this->uri->expand( - '/containers/{container}/kill{?signal}', + 'containers/{container}/kill{?signal}', array( 'container' => $container, 'signal' => $signal @@ -628,7 +628,7 @@ public function containerRename($container, $name) { return $this->browser->post( $this->uri->expand( - '/containers/{container}/rename{?name}', + 'containers/{container}/rename{?name}', array( 'container' => $container, 'name' => $name @@ -648,7 +648,7 @@ public function containerPause($container) { return $this->browser->post( $this->uri->expand( - '/containers/{container}/pause', + 'containers/{container}/pause', array( 'container' => $container ) @@ -667,7 +667,7 @@ public function containerUnpause($container) { return $this->browser->post( $this->uri->expand( - '/containers/{container}/unpause', + 'containers/{container}/unpause', array( 'container' => $container ) @@ -753,7 +753,7 @@ public function containerAttachStream($container, $logs = false, $stream = false $parser = $this->streamingParser; $browser = $this->browser; $url = $this->uri->expand( - '/containers/{container}/attach{?logs,stream,stdout,stderr}', + 'containers/{container}/attach{?logs,stream,stdout,stderr}', array( 'container' => $container, 'logs' => $this->boolArg($logs), @@ -786,7 +786,7 @@ public function containerWait($container) { return $this->browser->post( $this->uri->expand( - '/containers/{container}/wait', + 'containers/{container}/wait', array( 'container' => $container ) @@ -807,7 +807,7 @@ public function containerRemove($container, $v = false, $force = false) { return $this->browser->delete( $this->uri->expand( - '/containers/{container}{?v,force}', + 'containers/{container}{?v,force}', array( 'container' => $container, 'v' => $this->boolArg($v), @@ -844,7 +844,7 @@ public function containerArchive($container, $path) { return $this->browser->get( $this->uri->expand( - '/containers/{container}/archive{?path}', + 'containers/{container}/archive{?path}', array( 'container' => $container, 'path' => $path @@ -884,7 +884,7 @@ public function containerArchiveStream($container, $path) $this->browser->requestStreaming( 'GET', $this->uri->expand( - '/containers/{container}/archive{?path}', + 'containers/{container}/archive{?path}', array( 'container' => $container, 'path' => $path @@ -906,7 +906,7 @@ public function imageList($all = false) { return $this->browser->get( $this->uri->expand( - '/images/json{?all}', + 'images/json{?all}', array( 'all' => $this->boolArg($all) ) @@ -975,7 +975,7 @@ public function imageCreateStream($fromImage = null, $fromSrc = null, $repo = nu $this->browser->requestStreaming( 'POST', $this->uri->expand( - '/images/create{?fromImage,fromSrc,repo,tag,registry}', + 'images/create{?fromImage,fromSrc,repo,tag,registry}', array( 'fromImage' => $fromImage, 'fromSrc' => $fromSrc, @@ -1000,7 +1000,7 @@ public function imageInspect($image) { return $this->browser->get( $this->uri->expand( - '/images/{image}/json', + 'images/{image}/json', array( 'image' => $image ) @@ -1019,7 +1019,7 @@ public function imageHistory($image) { return $this->browser->get( $this->uri->expand( - '/images/{image}/history', + 'images/{image}/history', array( 'image' => $image ) @@ -1083,7 +1083,7 @@ public function imagePushStream($image, $tag = null, $registry = null, $registry $this->browser->requestStreaming( 'POST', $this->uri->expand( - '/images{/registry}/{image}/push{?tag}', + 'images{/registry}/{image}/push{?tag}', array( 'registry' => $registry, 'image' => $image, @@ -1109,7 +1109,7 @@ public function imageTag($image, $repo, $tag = null, $force = false) { return $this->browser->post( $this->uri->expand( - '/images/{image}/tag{?repo,tag,force}', + 'images/{image}/tag{?repo,tag,force}', array( 'image' => $image, 'repo' => $repo, @@ -1133,7 +1133,7 @@ public function imageRemove($image, $force = false, $noprune = false) { return $this->browser->delete( $this->uri->expand( - '/images/{image}{?force,noprune}', + 'images/{image}{?force,noprune}', array( 'image' => $image, 'force' => $this->boolArg($force), @@ -1154,7 +1154,7 @@ public function imageSearch($term) { return $this->browser->get( $this->uri->expand( - '/images/search{?term}', + 'images/search{?term}', array( 'term' => $term ) @@ -1206,7 +1206,7 @@ public function execCreate($container, $cmd, $tty = false, $stdin = false, $stdo return $this->postJson( $this->uri->expand( - '/containers/{container}/exec', + 'containers/{container}/exec', array( 'container' => $container ) @@ -1266,7 +1266,7 @@ public function execStartDetached($exec, $tty = false) { return $this->browser->post( $this->uri->expand( - '/exec/{exec}/start', + 'exec/{exec}/start', array( 'exec' => $exec ) @@ -1312,7 +1312,7 @@ public function execStartStream($exec, $tty = false, $stderrEvent = null) $this->browser->requestStreaming( 'POST', $this->uri->expand( - '/exec/{exec}/start', + 'exec/{exec}/start', array( 'exec' => $exec ) @@ -1349,7 +1349,7 @@ public function execResize($exec, $w, $h) { return $this->browser->post( $this->uri->expand( - '/exec/{exec}/resize{?w,h}', + 'exec/{exec}/resize{?w,h}', array( 'exec' => $exec, 'w' => $w, @@ -1372,7 +1372,7 @@ public function execInspect($exec) { return $this->browser->get( $this->uri->expand( - '/exec/{exec}/json', + 'exec/{exec}/json', array( 'exec' => $exec ) @@ -1390,7 +1390,7 @@ public function networkList() { return $this->browser->get( $this->uri->expand( - '/networks', + 'networks', array() ) )->then(array($this->parser, 'expectJson')); @@ -1408,7 +1408,7 @@ public function networkInspect($network) { return $this->browser->get( $this->uri->expand( - '/networks/{network}', + 'networks/{network}', array( 'network' => $network ) @@ -1428,7 +1428,7 @@ public function networkRemove($network) { return $this->browser->delete( $this->uri->expand( - '/networks/{network}', + 'networks/{network}', array( 'network' => $network ) @@ -1451,7 +1451,7 @@ public function networkCreate($name, $config = array()) return $this->postJson( $this->uri->expand( - '/networks/create' + 'networks/create' ), $config )->then(array($this->parser, 'expectJson')); @@ -1471,7 +1471,7 @@ public function networkConnect($network, $container, $endpointConfig = array()) { return $this->postJson( $this->uri->expand( - '/networks/{network}/connect', + 'networks/{network}/connect', array( 'network' => $network ) @@ -1497,7 +1497,7 @@ public function networkDisconnect($network, $container, $force = false) { return $this->postJson( $this->uri->expand( - '/networks/{network}/disconnect', + 'networks/{network}/disconnect', array( 'network' => $network ) @@ -1519,7 +1519,7 @@ public function networkPrune() { return $this->postJson( $this->uri->expand( - '/networks/prune', + 'networks/prune', array() ), array() diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 38f2fcd..8afadf3 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -48,36 +48,6 @@ public function testCtor() new Client($this->loop); } - public function testCtorWithExplicitUnixPath() - { - $client = new Client($this->loop, 'unix://docker.sock'); - - $ref = new \ReflectionProperty($client, 'browser'); - $ref->setAccessible(true); - $browser = $ref->getValue($client); - - $ref = new \ReflectionProperty($browser, 'baseUrl'); - $ref->setAccessible(true); - $url = $ref->getValue($browser); - - $this->assertEquals('http://localhost/', $url); - } - - public function testCtorWithExplicitHttpUrl() - { - $client = new Client($this->loop, 'http://localhost:8001/'); - - $ref = new \ReflectionProperty($client, 'browser'); - $ref->setAccessible(true); - $browser = $ref->getValue($client); - - $ref = new \ReflectionProperty($browser, 'baseUrl'); - $ref->setAccessible(true); - $url = $ref->getValue($browser); - - $this->assertEquals('http://localhost:8001/', $url); - } - /** * @expectedException InvalidArgumentException */ @@ -89,7 +59,7 @@ public function testCtorWithInvalidUrlThrows() public function testPing() { $body = 'OK'; - $this->expectRequestFlow('get', '/_ping', $this->createResponse($body), 'expectPlain'); + $this->expectRequestFlow('get', '_ping', $this->createResponse($body), 'expectPlain'); $this->expectPromiseResolveWith($body, $this->client->ping()); } @@ -99,7 +69,7 @@ public function testEvents() $json = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/events')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', 'events')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('deferredStream')->with($this->equalTo($stream))->will($this->returnPromise($json)); @@ -111,7 +81,7 @@ public function testEventsArgs() $json = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/events?since=10&until=20&filters=%7B%22image%22%3A%5B%22busybox%22%2C%22ubuntu%22%5D%7D')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', 'events?since=10&until=20&filters=%7B%22image%22%3A%5B%22busybox%22%2C%22ubuntu%22%5D%7D')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('deferredStream')->with($this->equalTo($stream))->will($this->returnPromise($json)); @@ -122,7 +92,7 @@ public function testContainerCreate() { $json = array(); $config = array(); - $this->expectRequestFlow('post', '/containers/create', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('post', 'containers/create', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->containerCreate($config)); } @@ -131,7 +101,7 @@ public function testContainerCreateName() { $json = array(); $config = array(); - $this->expectRequestFlow('post', '/containers/create?name=demo', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('post', 'containers/create?name=demo', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->containerCreate($config, 'demo')); } @@ -139,7 +109,7 @@ public function testContainerCreateName() public function testContainerInspect() { $json = array(); - $this->expectRequestFlow('get', '/containers/123/json', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'containers/123/json', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->containerInspect(123)); } @@ -147,7 +117,7 @@ public function testContainerInspect() public function testContainerTop() { $json = array(); - $this->expectRequestFlow('get', '/containers/123/top', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'containers/123/top', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->containerTop(123)); } @@ -155,7 +125,7 @@ public function testContainerTop() public function testContainerTopArgs() { $json = array(); - $this->expectRequestFlow('get', '/containers/123/top?ps_args=aux', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'containers/123/top?ps_args=aux', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->containerTop(123, 'aux')); } @@ -163,14 +133,14 @@ public function testContainerTopArgs() public function testContainerChanges() { $json = array(); - $this->expectRequestFlow('get', '/containers/123/changes', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'containers/123/changes', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->containerChanges(123)); } public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerIsPending() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(new \React\Promise\Promise(function () { })); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(new \React\Promise\Promise(function () { })); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(new \React\Promise\Promise(function () { })); @@ -181,7 +151,7 @@ public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerIsP public function testContainerLogsRejectsWhenInspectingContainerRejects() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\reject(new \RuntimeException())); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(\React\Promise\reject(new \RuntimeException())); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(\React\Promise\reject(new \RuntimeException())); @@ -192,8 +162,8 @@ public function testContainerLogsRejectsWhenInspectingContainerRejects() public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerResolvesWithTtyAndContainerLogsRequestIsPending() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); - $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/logs?stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', 'containers/123/logs?stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(new \React\Promise\Promise(function () { })); @@ -207,8 +177,8 @@ public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerRes public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerResolvesWithoutTtyAndContainerLogsRequestIsPending() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":false}}'))); - $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/logs?stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":false}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', 'containers/123/logs?stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => false))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(new \React\Promise\Promise(function () { })); @@ -222,8 +192,8 @@ public function testContainerLogsReturnsPendingPromiseWhenInspectingContainerRes public function testContainerLogsResolvesWhenInspectingContainerResolvesWithTtyAndContainerLogsRequestResolves() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); - $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/logs?stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', 'containers/123/logs?stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(\React\Promise\resolve('output')); @@ -237,8 +207,8 @@ public function testContainerLogsResolvesWhenInspectingContainerResolvesWithTtyA public function testContainerLogsStreamReturnStreamWhenInspectingContainerResolvesWithTtyAndContainerLogsRequestResolves() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); - $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/logs?stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', 'containers/123/logs?stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); $response = new ThroughStream(); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); @@ -254,7 +224,7 @@ public function testContainerLogsStreamReturnStreamWhenInspectingContainerResolv public function testContainerExport() { $data = 'tar stream'; - $this->expectRequestFlow('get', '/containers/123/export', $this->createResponse($data), 'expectPlain'); + $this->expectRequestFlow('get', 'containers/123/export', $this->createResponse($data), 'expectPlain'); $this->expectPromiseResolveWith($data, $this->client->containerExport(123)); } @@ -263,7 +233,7 @@ public function testContainerExportStream() { $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/export')->willReturn(\React\Promise\resolve($this->createResponse(''))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', 'containers/123/export')->willReturn(\React\Promise\resolve($this->createResponse(''))); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->assertSame($stream, $this->client->containerExportStream(123)); @@ -272,28 +242,28 @@ public function testContainerExportStream() public function testContainerWait() { $json = array(); - $this->expectRequestFlow('post', '/containers/123/wait', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('post', 'containers/123/wait', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->containerWait(123)); } public function testContainerKill() { - $this->expectRequestFlow('post', '/containers/123/kill', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'containers/123/kill', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerKill(123)); } public function testContainerKillSignalName() { - $this->expectRequestFlow('post', '/containers/123/kill?signal=SIGKILL', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'containers/123/kill?signal=SIGKILL', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerKill(123, 'SIGKILL')); } public function testContainerKillSignalNumber() { - $this->expectRequestFlow('post', '/containers/123/kill?signal=9', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'containers/123/kill?signal=9', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerKill(123, 9)); } @@ -301,63 +271,63 @@ public function testContainerKillSignalNumber() public function testContainerStart() { $config = array(); - $this->expectRequestFlow('post', '/containers/123/start', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'containers/123/start', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerStart(123, $config)); } public function testContainerStop() { - $this->expectRequestFlow('post', '/containers/123/stop', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'containers/123/stop', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerStop(123)); } public function testContainerStopTimeout() { - $this->expectRequestFlow('post', '/containers/123/stop?t=10', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'containers/123/stop?t=10', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerStop(123, 10)); } public function testContainerRestart() { - $this->expectRequestFlow('post', '/containers/123/restart', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'containers/123/restart', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerRestart(123)); } public function testContainerRestartTimeout() { - $this->expectRequestFlow('post', '/containers/123/restart?t=10', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'containers/123/restart?t=10', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerRestart(123, 10)); } public function testContainerRename() { - $this->expectRequestFlow('POST', '/containers/123/rename?name=newname', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('POST', 'containers/123/rename?name=newname', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerRename(123, 'newname')); } public function testContainerPause() { - $this->expectRequestFlow('post', '/containers/123/pause', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'containers/123/pause', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerPause(123)); } public function testContainerUnpause() { - $this->expectRequestFlow('post', '/containers/123/unpause', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'containers/123/unpause', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerUnpause(123)); } public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerIsPending() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(new \React\Promise\Promise(function () { })); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(new \React\Promise\Promise(function () { })); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(new \React\Promise\Promise(function () { })); @@ -368,7 +338,7 @@ public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerI public function testContainerAttachRejectsWhenInspectingContainerRejects() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\reject(new \RuntimeException())); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(\React\Promise\reject(new \RuntimeException())); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(\React\Promise\reject(new \RuntimeException())); @@ -379,8 +349,8 @@ public function testContainerAttachRejectsWhenInspectingContainerRejects() public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerResolvesWithTtyAndContainerAttachIsPending() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(new \React\Promise\Promise(function () { })); @@ -394,8 +364,8 @@ public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerR public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerResolvesWithoutTtyAndContainerAttachRequestIsPending() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":false}}'))); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":false}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(new \React\Promise\Promise(function () { })); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => false))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(new \React\Promise\Promise(function () { })); @@ -409,8 +379,8 @@ public function testContainerAttachReturnsPendingPromiseWhenInspectingContainerR public function testContainerAttachResolvesWhenInspectingContainerResolvesWithTtyAndContainerAttachResolvesAndContainerAttachRequestResolves() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'containers/123/attach?logs=1&stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->isInstanceOf('React\Stream\ReadableStreamInterface'))->willReturn(\React\Promise\resolve('output')); @@ -424,8 +394,8 @@ public function testContainerAttachResolvesWhenInspectingContainerResolvesWithTt public function testContainerAttachStreamReturnStreamWhenInspectingContainerResolvesWithTtyAndContainerAttachRequestResolves() { - $this->browser->expects($this->once())->method('get')->with('/containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/containers/123/attach?logs=1&stream=1&stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); + $this->browser->expects($this->once())->method('get')->with('containers/123/json')->willReturn(\React\Promise\resolve(new Response(200, array(), '{"Config":{"Tty":true}}'))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'containers/123/attach?logs=1&stream=1&stdout=1&stderr=1')->willReturn(\React\Promise\resolve(new Response(200, array(), ''))); $response = new ThroughStream(); $this->parser->expects($this->once())->method('expectJson')->willReturn(array('Config' => array('Tty' => true))); @@ -440,21 +410,21 @@ public function testContainerAttachStreamReturnStreamWhenInspectingContainerReso public function testContainerRemove() { - $this->expectRequestFlow('delete', '/containers/123', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('delete', 'containers/123', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerRemove(123, false, false)); } public function testContainerRemoveVolumeForce() { - $this->expectRequestFlow('delete', '/containers/123?v=1&force=1', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('delete', 'containers/123?v=1&force=1', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerRemove(123, true, true)); } public function testContainerStats() { - $this->expectRequestFlow('GET', '/containers/123/stats?stream=0', $this->createResponse(), 'expectJson'); + $this->expectRequestFlow('GET', 'containers/123/stats?stream=0', $this->createResponse(), 'expectJson'); $this->expectPromiseResolveWith('', $this->client->containerStats(123)); } @@ -463,7 +433,7 @@ public function testContainerStatsStream() { $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/stats')->willReturn(\React\Promise\resolve($this->createResponse(''))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', 'containers/123/stats')->willReturn(\React\Promise\resolve($this->createResponse(''))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->assertSame($stream, $this->client->containerStatsStream('123')); @@ -471,7 +441,7 @@ public function testContainerStatsStream() public function testContainerResize() { - $this->expectRequestFlow('POST', '/containers/123/resize?w=800&h=600', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('POST', 'containers/123/resize?w=800&h=600', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->containerResize(123, 800, 600)); } @@ -480,7 +450,7 @@ public function testContainerArchive() { $data = 'tar stream'; - $this->browser->expects($this->once())->method('get')->with('/containers/123/archive?path=file.txt')->willReturn(\React\Promise\resolve($this->createResponse($data))); + $this->browser->expects($this->once())->method('get')->with('containers/123/archive?path=file.txt')->willReturn(\React\Promise\resolve($this->createResponse($data))); $this->parser->expects($this->once())->method('expectPlain')->will($this->returnValue($data)); $this->expectPromiseResolveWith($data, $this->client->containerArchive('123', 'file.txt')); @@ -490,7 +460,7 @@ public function testContainerArchiveStream() { $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('GET', '/containers/123/archive?path=file.txt')->willReturn(\React\Promise\resolve($this->createResponse(''))); + $this->browser->expects($this->once())->method('requestStreaming')->with('GET', 'containers/123/archive?path=file.txt')->willReturn(\React\Promise\resolve($this->createResponse(''))); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->assertSame($stream, $this->client->containerArchiveStream('123', 'file.txt')); @@ -499,7 +469,7 @@ public function testContainerArchiveStream() public function testImageList() { $json = array(); - $this->expectRequestFlow('get', '/images/json', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'images/json', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->imageList()); } @@ -507,7 +477,7 @@ public function testImageList() public function testImageListAll() { $json = array(); - $this->expectRequestFlow('get', '/images/json?all=1', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'images/json?all=1', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->imageList(true)); } @@ -517,7 +487,7 @@ public function testImageCreate() $json = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/images/create?fromImage=busybox')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'images/create?fromImage=busybox')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('deferredStream')->with($this->equalTo($stream))->will($this->returnPromise($json)); @@ -528,7 +498,7 @@ public function testImageCreateStream() { $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/images/create?fromImage=busybox')->willReturn(\React\Promise\resolve($this->createResponseJsonStream(array()))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'images/create?fromImage=busybox')->willReturn(\React\Promise\resolve($this->createResponseJsonStream(array()))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->assertSame($stream, $this->client->imageCreateStream('busybox')); @@ -537,7 +507,7 @@ public function testImageCreateStream() public function testImageInspect() { $json = array(); - $this->expectRequestFlow('get', '/images/123/json', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'images/123/json', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->imageInspect('123')); } @@ -545,7 +515,7 @@ public function testImageInspect() public function testImageHistory() { $json = array(); - $this->expectRequestFlow('get', '/images/123/history', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'images/123/history', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->imageHistory('123')); } @@ -555,7 +525,7 @@ public function testImagePush() $json = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/images/123/push')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'images/123/push')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('deferredStream')->with($this->equalTo($stream))->will($this->returnPromise($json)); @@ -566,7 +536,7 @@ public function testImagePushStream() { $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/images/123/push')->willReturn(\React\Promise\resolve($this->createResponseJsonStream(array()))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'images/123/push')->willReturn(\React\Promise\resolve($this->createResponseJsonStream(array()))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->assertSame($stream, $this->client->imagePushStream('123')); @@ -579,7 +549,7 @@ public function testImagePushCustomRegistry() $json = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/images/demo.acme.com%3A5000/123/push?tag=test')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'images/demo.acme.com%3A5000/123/push?tag=test')->willReturn(\React\Promise\resolve($this->createResponseJsonStream($json))); $this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('deferredStream')->with($this->equalTo($stream))->will($this->returnPromise($json)); @@ -588,28 +558,28 @@ public function testImagePushCustomRegistry() public function testImageTag() { - $this->expectRequestFlow('post', '/images/123/tag?repo=test', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'images/123/tag?repo=test', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->imageTag('123', 'test')); } public function testImageTagNameForce() { - $this->expectRequestFlow('post', '/images/123/tag?repo=test&tag=tag&force=1', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'images/123/tag?repo=test&tag=tag&force=1', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->imageTag('123', 'test', 'tag', true)); } public function testImageRemove() { - $this->expectRequestFlow('delete', '/images/123', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('delete', 'images/123', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->imageRemove('123')); } public function testImageRemoveForceNoprune() { - $this->expectRequestFlow('delete', '/images/123?force=1&noprune=1', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('delete', 'images/123?force=1&noprune=1', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->imageRemove('123', true, true)); } @@ -617,7 +587,7 @@ public function testImageRemoveForceNoprune() public function testImageSearch() { $json = array(); - $this->expectRequestFlow('get', '/images/search?term=clue', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'images/search?term=clue', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->imageSearch('clue')); } @@ -625,7 +595,7 @@ public function testImageSearch() public function testExecCreate() { $json = array(); - $this->expectRequestFlow('post', '/containers/123/exec', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('post', 'containers/123/exec', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->execCreate(123, array('env'))); } @@ -633,7 +603,7 @@ public function testExecCreate() public function testExecCreateStringCommand() { $json = array(); - $this->expectRequestFlow('post', '/containers/123/exec', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('post', 'containers/123/exec', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->execCreate(123, 'env')); } @@ -641,7 +611,7 @@ public function testExecCreateStringCommand() public function testExecDetached() { $body = ''; - $this->expectRequestFlow('POST', '/exec/123/start', $this->createResponse($body), 'expectEmpty'); + $this->expectRequestFlow('POST', 'exec/123/start', $this->createResponse($body), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->execStartDetached(123, true)); } @@ -652,7 +622,7 @@ public function testExecStart() $config = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse($data))); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse($data))); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('demultiplexStream')->with($stream)->willReturn($stream); $this->streamingParser->expects($this->once())->method('bufferedStream')->with($this->equalTo($stream))->willReturn(\React\Promise\resolve($data)); @@ -665,7 +635,7 @@ public function testExecStartStreamWithoutTtyWillDemultiplex() $config = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse())); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse())); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('demultiplexStream')->with($stream)->willReturn($stream); @@ -677,7 +647,7 @@ public function testExecStartStreamWithTtyWillNotDemultiplex() $config = array('Tty' => true); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse())); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse())); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->never())->method('demultiplexStream'); @@ -689,7 +659,7 @@ public function testExecStartStreamWithCustomStderrEvent() $config = array(); $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - $this->browser->expects($this->once())->method('requestStreaming')->with('POST', '/exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse())); + $this->browser->expects($this->once())->method('requestStreaming')->with('POST', 'exec/123/start')->willReturn(\React\Promise\resolve($this->createResponse())); $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); $this->streamingParser->expects($this->once())->method('demultiplexStream')->with($stream, 'stderr')->willReturn($stream); @@ -698,7 +668,7 @@ public function testExecStartStreamWithCustomStderrEvent() public function testExecResize() { - $this->expectRequestFlow('POST', '/exec/123/resize?w=800&h=600', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('POST', 'exec/123/resize?w=800&h=600', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->execResize(123, 800, 600)); } @@ -706,7 +676,7 @@ public function testExecResize() public function testExecInspect() { $json = array(); - $this->expectRequestFlow('get', '/exec/123/json', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'exec/123/json', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->execInspect(123)); } @@ -714,7 +684,7 @@ public function testExecInspect() public function testNetworkList() { $json = array(); - $this->expectRequestFlow('get', '/networks', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'networks', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->networkList()); } @@ -722,7 +692,7 @@ public function testNetworkList() public function testNetworkInspect() { $json = array(); - $this->expectRequestFlow('get', '/networks/123', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('get', 'networks/123', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->networkInspect(123)); } @@ -730,7 +700,7 @@ public function testNetworkInspect() public function testNetworkRemove() { $json = array(); - $this->expectRequestFlow('delete', '/networks/123', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('delete', 'networks/123', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->networkRemove(123)); } @@ -739,7 +709,7 @@ public function testNetworkCreate() { $json = array(); $config = array(); - $this->expectRequestFlow('post', '/networks/create', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('post', 'networks/create', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->networkCreate($config)); } @@ -748,7 +718,7 @@ public function testNetworkConnect() { $json = array(); $config = array(); - $this->expectRequestFlow('post', '/networks/123/connect', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('post', 'networks/123/connect', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->networkConnect(123, $config)); } @@ -756,7 +726,7 @@ public function testNetworkConnect() public function testNetworkDisconnect() { $json = array(); - $this->expectRequestFlow('post', '/networks/123/disconnect', $this->createResponse(), 'expectEmpty'); + $this->expectRequestFlow('post', 'networks/123/disconnect', $this->createResponse(), 'expectEmpty'); $this->expectPromiseResolveWith('', $this->client->networkDisconnect(123, 'abc')); } @@ -764,7 +734,7 @@ public function testNetworkDisconnect() public function testNetworkPrune() { $json = array(); - $this->expectRequestFlow('post', '/networks/prune', $this->createResponseJson($json), 'expectJson'); + $this->expectRequestFlow('post', 'networks/prune', $this->createResponseJson($json), 'expectJson'); $this->expectPromiseResolveWith($json, $this->client->networkPrune()); } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php new file mode 100644 index 0000000..e6cf710 --- /dev/null +++ b/tests/IntegrationTest.php @@ -0,0 +1,63 @@ +markTestSkipped('Unable to start listening on Unix socket (Windows?)'); + } + + $deferred = new Deferred(); + $http = new \React\Http\Server($loop, function (ServerRequestInterface $request) use ($deferred) { + $deferred->resolve($request->getRequestTarget()); + }); + + $http->listen($socket); + + $client = new Client($loop, 'unix://' . $path); + $client->ping(); + + $value = \Clue\React\Block\await($deferred->promise(), $loop, 1.0); + unlink($path); + + $this->assertEquals('/_ping', $value); + } + + public function testPingCtorWithExplicitHttpUrlSendsRequestToGivenHttpUrlWithBase() + { + $loop = \React\EventLoop\Factory::create(); + + $deferred = new Deferred(); + $http = new \React\Http\Server($loop, function (ServerRequestInterface $request) use ($deferred) { + $deferred->resolve($request->getRequestTarget()); + }); + + $socket = new \React\Socket\Server(0, $loop); + $http->listen($socket); + + $client = new Client($loop, str_replace('tcp://', 'http://', $socket->getAddress()) . '/base/'); + $client->ping(); + + $value = \Clue\React\Block\await($deferred->promise(), $loop, 1.0); + + $this->assertEquals('/base/_ping', $value); + } +}