diff --git a/src/Client.php b/src/Client.php index 3064342..8158540 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1541,7 +1541,7 @@ public function networkConnect($network, $container, $endpointConfig = array()) ), array( 'Container' => $container, - 'EndpointConfig' => $endpointConfig ? json_encode($endpointConfig) : null + 'EndpointConfig' => $endpointConfig ? $endpointConfig : null ) )->then(array($this->parser, 'expectJson')); } @@ -1567,7 +1567,7 @@ public function networkDisconnect($network, $container, $force = false) ), array( 'Container' => $container, - 'Force' => $this->boolArg($force) + 'Force' => (bool) $force ) )->then(array($this->parser, 'expectEmpty')); } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 8f3ff1b..ffec9b7 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -770,14 +770,31 @@ public function testNetworkConnect() $this->expectPromiseResolveWith($json, $this->client->networkConnect(123, $config)); } - public function testNetworkDisconnect() + public function testNetworkConnectWithEndpointConfig() { $json = array(); - $this->expectRequestFlow('post', 'networks/123/disconnect', $this->createResponse(), 'expectEmpty'); + $this->browser->expects($this->once())->method('post')->with('networks/123/connect', $this->anything(), '{"Container":"abc","EndpointConfig":{"Aliases":["foo"]}}')->willReturn(\React\Promise\resolve($this->createResponseJson($json))); + $this->parser->expects($this->once())->method('expectJson')->willReturn($json); + + $this->expectPromiseResolveWith($json, $this->client->networkConnect(123, 'abc', array('Aliases' => array('foo')))); + } + + public function testNetworkDisconnect() + { + $this->browser->expects($this->once())->method('post')->with('networks/123/disconnect', $this->anything(), '{"Container":"abc","Force":false}')->willReturn(\React\Promise\resolve($this->createResponse())); + $this->parser->expects($this->once())->method('expectEmpty')->willReturn(''); $this->expectPromiseResolveWith('', $this->client->networkDisconnect(123, 'abc')); } + public function testNetworkDisconnectForce() + { + $this->browser->expects($this->once())->method('post')->with('networks/123/disconnect', $this->anything(), '{"Container":"abc","Force":true}')->willReturn(\React\Promise\resolve($this->createResponse())); + $this->parser->expects($this->once())->method('expectEmpty')->willReturn(''); + + $this->expectPromiseResolveWith('', $this->client->networkDisconnect(123, 'abc', true)); + } + public function testNetworkPrune() { $json = array(); diff --git a/tests/FunctionalClientTest.php b/tests/FunctionalClientTest.php index d51292a..c78256f 100644 --- a/tests/FunctionalClientTest.php +++ b/tests/FunctionalClientTest.php @@ -453,12 +453,12 @@ public function testCreateConnectDisconnectAndRemoveNetwork() $this->assertNotNull($network['Id']); $this->assertEquals('', $network['Warning']); - $promise = $this->client->networkConnect($network['Id'], $container['Id']); + $promise = $this->client->networkConnect($network['Id'], $container['Id'], array('Aliases' => array('foo'))); $ret = \React\Async\await($promise); $this->assertEquals('', $ret); - $promise = $this->client->networkDisconnect($network['Id'], $container['Id'], false); + $promise = $this->client->networkDisconnect($network['Id'], $container['Id'], true); $ret = \React\Async\await($promise); $this->assertEquals('', $ret);