Skip to content

feat(client): add isConnected method to check server connection status#41

Merged
tohenk merged 2 commits intoElephantIO:masterfrom
evrenonur:Fix#40
Nov 24, 2025
Merged

feat(client): add isConnected method to check server connection status#41
tohenk merged 2 commits intoElephantIO:masterfrom
evrenonur:Fix#40

Conversation

@evrenonur
Copy link
Copy Markdown
Contributor

  • Introduced a new method isConnected in the Client class to determine
    if the client is currently connected to the server.
  • This method delegates the connection check to the engine's connected
    method, enhancing the client's ability to manage connection states.
  • Added unit tests to verify the behavior of the isConnected method,
    ensuring it returns true when connected and false otherwise.

Fixes: #40

- Introduced a new method `isConnected` in the Client class to determine
  if the client is currently connected to the server.
- This method delegates the connection check to the engine's `connected`
  method, enhancing the client's ability to manage connection states.
- Added unit tests to verify the behavior of the `isConnected` method,
  ensuring it returns true when connected and false otherwise.
Copilot AI review requested due to automatic review settings November 19, 2025 06:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new isConnected() method to the Client class to check the server connection status. The method provides a simple wrapper around the engine's connected() method, making it easier for consumers to check connection state directly from the Client.

Key changes:

  • Added isConnected() method to Client class that delegates to the engine's connected() method
  • Added comprehensive unit tests for the new method
  • Enhanced SocketStream's readable() method with EOF detection for better disconnect handling

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/Client.php Added isConnected() method with documentation
test/ClientTest.php Added unit tests for the new isConnected() method
src/Stream/SocketStream.php Added EOF check for improved disconnect detection

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/ClientTest.php
@@ -0,0 +1,32 @@
<?php
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the standard file header docblock that exists in other test files. Add the copyright and license information as seen in PacketTest.php and StoreTest.php.

Suggested change
<?php
<?php
/**
* Copyright (c) 2012-2024, ElephantIO contributors
*
* This file is part of ElephantIO.
*
* Licensed under the MIT License. See LICENSE file in the project root for full license information.
*/

Copilot uses AI. Check for mistakes.
Comment thread test/ClientTest.php Outdated

class ClientTest extends TestCase
{
public function testIsConnectedDelegatesToEngine()
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return type declaration. Other test methods in the codebase (e.g., PacketTest.php, StoreTest.php) use : void return type hints for consistency.

Suggested change
public function testIsConnectedDelegatesToEngine()
public function testIsConnectedDelegatesToEngine(): void

Copilot uses AI. Check for mistakes.
Comment thread test/ClientTest.php Outdated
$this->assertTrue($client->isConnected());
}

public function testIsConnectedReturnsFalseWhenEngineIsNotConnected()
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return type declaration. Other test methods in the codebase (e.g., PacketTest.php, StoreTest.php) use : void return type hints for consistency.

Suggested change
public function testIsConnectedReturnsFalseWhenEngineIsNotConnected()
public function testIsConnectedReturnsFalseWhenEngineIsNotConnected(): void

Copilot uses AI. Check for mistakes.
Comment thread test/ClientTest.php
Comment on lines +14 to +16
$engine->expects($this->any())
->method('connected')
->willReturn(true);
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using expects($this->any()) is imprecise. Since the method is called exactly once in each test, use expects($this->once()) to verify the delegation happens as expected.

Copilot uses AI. Check for mistakes.
Comment thread test/ClientTest.php
Comment on lines +25 to +27
$engine->expects($this->any())
->method('connected')
->willReturn(false);
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using expects($this->any()) is imprecise. Since the method is called exactly once in each test, use expects($this->once()) to verify the delegation happens as expected.

Copilot uses AI. Check for mistakes.
Signed-off-by: Toha <tohenk@yahoo.com>
@tohenk tohenk merged commit 5354af1 into ElephantIO:master Nov 24, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Expose underlying stream resource or provide strict connection check for Daemons

3 participants