public function testReceivePacket() { $packet = new Packet(); $mock = $this->getMockBuilder(__CLASS__)->getMock(); $mock->expects($this->once())->method('testReceivePacket')->willReturnCallback(function ($givenPacket) use($packet) { $this->assertEquals($packet, $givenPacket); }); $this->driver->expects($this->once())->method('read')->willReturn($packet); $this->connection->onPacketReceived([$mock, 'testReceivePacket']); $this->connection->receivePacket(); }
/** * Adds connection to list and sets connection to master mode * * @param Connection $connection * * @return $this */ public function addConnection(Connection $connection) { $connection->setMasterMode(); $connection->onPacketReceived([$this, 'receivedPacket']); $this->connections[$connection->getPid()] = $connection; return $this; }