diff --git a/tests/Group/ConnectionGroupTest.php b/tests/Group/ConnectionGroupTest.php new file mode 100644 index 0000000..db7ea97 --- /dev/null +++ b/tests/Group/ConnectionGroupTest.php @@ -0,0 +1,52 @@ +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)); + } + +} \ No newline at end of file