Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/client/connecting.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ speaks revision `2026-07-28`, the connection is ready. If it doesn't, the client
`initialize` handshake and offers `2025-11-25`, or the revision set with
`setFallbackProtocolVersion()`. A server process that exits fails the connection instead.

Calling `connect()` again on the same client closes its current transport before opening the new one.

With `setFallbackProtocolVersion(null)`, `connect()` fails instead. See
[How the client settles on an era](../protocol-versions.md#how-the-client-settles-on-an-era).

Expand Down
2 changes: 2 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public static function builder(): Builder
*/
public function connect(TransportInterface $transport): void
{
$this->disconnect();

$this->transport = $transport;
$this->protocol->connect($transport, $this->config);

Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/Client/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@

final class ClientTest extends TestCase
{
public function testReconnectClosesPreviousTransport(): void
{
$client = Client::builder()->build();
$firstTransport = $this->createMock(TransportInterface::class);
$firstTransport->expects($this->once())->method('close');
$firstTransport->method('setState')->willReturnCallback(static function (ClientStateInterface $state): void {
$state->setInitialized(true);
});

$secondTransport = $this->createMock(TransportInterface::class);
$secondTransport->expects($this->once())->method('close');
$secondTransport->method('setState')->willReturnCallback(static function (ClientStateInterface $state): void {
$state->setInitialized(true);
});

$client->connect($firstTransport);
$client->connect($secondTransport);

$this->assertTrue($client->isConnected());

$client->disconnect();
}

public function testSendRootsListChangedSendsNotificationWhenCapabilityDeclared(): void
{
$sent = [];
Expand Down
Loading