Test cases for ConnectionGroup
This commit is contained in:
parent
ca84671f33
commit
3abdced846
52
tests/Group/ConnectionGroupTest.php
Normal file
52
tests/Group/ConnectionGroupTest.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\React\WebSocket\Group;
|
||||
|
||||
use NoccyLabs\React\WebSocket\WebSocketConnection;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use React\Http\Message\ServerRequest;
|
||||
use React\Stream\ThroughStream;
|
||||
|
||||
#[CoversClass(ConnectionGroup::class)]
|
||||
class ConnectionGroupTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
public function testThatGroupsAreCountable()
|
||||
{
|
||||
$groupManager = new GroupManager();
|
||||
|
||||
$group = new ConnectionGroup();
|
||||
$this->assertEquals(0, count($group));
|
||||
$group->add(new WebSocketConnection(new ServerRequest('GET','/'),new ThroughStream(), new ThroughStream(), $groupManager));
|
||||
$this->assertEquals(1, count($group));
|
||||
$group->add(new WebSocketConnection(new ServerRequest('GET','/'),new ThroughStream(), new ThroughStream(), $groupManager));
|
||||
$this->assertEquals(2, count($group));
|
||||
$group->add(new WebSocketConnection(new ServerRequest('GET','/'),new ThroughStream(), new ThroughStream(), $groupManager));
|
||||
$this->assertEquals(3, count($group));
|
||||
}
|
||||
|
||||
public function testThatGroupNamesAreAssignedUniquely()
|
||||
{
|
||||
$group = new ConnectionGroup();
|
||||
$this->assertNotEmpty($group->getName());
|
||||
|
||||
$group2 = new ConnectionGroup();
|
||||
$this->assertNotEmpty($group2->getName());
|
||||
|
||||
$this->assertNotEquals($group->getName(), $group2->getName());
|
||||
}
|
||||
|
||||
public function testWritingToAll()
|
||||
{
|
||||
$groupManager = new GroupManager();
|
||||
|
||||
$r = [];
|
||||
$group = new ConnectionGroup();
|
||||
$group->add(new WebSocketConnection(new ServerRequest('GET','/'),new ThroughStream(), new ThroughStream(function ($data) use (&$r) { $r[]=$data; }), $groupManager));
|
||||
$group->add(new WebSocketConnection(new ServerRequest('GET','/'),new ThroughStream(), new ThroughStream(function ($data) use (&$r) { $r[]=$data; }), $groupManager));
|
||||
$group->add(new WebSocketConnection(new ServerRequest('GET','/'),new ThroughStream(), new ThroughStream(function ($data) use (&$r) { $r[]=$data; }), $groupManager));
|
||||
$group->writeAll("test");
|
||||
$this->assertEquals(3, count($r));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user