From 43e033f21281eabc6a648745419c69928a50fe5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 11 Oct 2026 02:07:20 +0200 Subject: [PATCH 1/2] Fix `networkDisconnect()` to force disconnect if `$force` is true --- src/Client.php | 2 +- tests/ClientTest.php | 12 ++++++++++-- tests/FunctionalClientTest.php | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index 3064342..391d5e4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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..4c231ae 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -772,12 +772,20 @@ public function testNetworkConnect() public function testNetworkDisconnect() { - $json = array(); - $this->expectRequestFlow('post', 'networks/123/disconnect', $this->createResponse(), 'expectEmpty'); + $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..92d6699 100644 --- a/tests/FunctionalClientTest.php +++ b/tests/FunctionalClientTest.php @@ -458,7 +458,7 @@ public function testCreateConnectDisconnectAndRemoveNetwork() $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); From 9b9782d1350500e1c0fa464fa993c260e0752c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 12 Oct 2026 01:19:28 +0200 Subject: [PATCH 2/2] Fix `networkConnect()` to send `$endpointConfig` as JSON object --- src/Client.php | 2 +- tests/ClientTest.php | 9 +++++++++ tests/FunctionalClientTest.php | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 391d5e4..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')); } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 4c231ae..ffec9b7 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -770,6 +770,15 @@ public function testNetworkConnect() $this->expectPromiseResolveWith($json, $this->client->networkConnect(123, $config)); } + public function testNetworkConnectWithEndpointConfig() + { + $json = array(); + $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())); diff --git a/tests/FunctionalClientTest.php b/tests/FunctionalClientTest.php index 92d6699..c78256f 100644 --- a/tests/FunctionalClientTest.php +++ b/tests/FunctionalClientTest.php @@ -453,7 +453,7 @@ 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);