This commit is contained in:
parent
b060e45a30
commit
bc5f5bd99e
@ -1,53 +1,2 @@
|
|||||||
<?php
|
ffff
|
||||||
|
|
||||||
// 手动加载类文件
|
|
||||||
require_once __DIR__ . '/../src/libs/MyWebSocketHandler.php';
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use App\MyWebSocketHandler;
|
|
||||||
use Workerman\Connection\TcpConnection;
|
|
||||||
use Workerman\Worker;
|
|
||||||
|
|
||||||
class MyWebSocketHandlerTest extends TestCase
|
|
||||||
{
|
|
||||||
private $handler;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
$this->handler = new MyWebSocketHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testOnConnect()
|
|
||||||
{
|
|
||||||
$connection = $this->createMock(TcpConnection::class);
|
|
||||||
$worker = $this->createMock(Worker::class);
|
|
||||||
|
|
||||||
// 使用 ob_start + ob_get_clean 捕获输出
|
|
||||||
ob_start();
|
|
||||||
$this->handler->onConnect($connection);
|
|
||||||
$output = ob_get_clean();
|
|
||||||
|
|
||||||
$this->assertStringContainsString('New connection', $output);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testOnMessage()
|
|
||||||
{
|
|
||||||
$connection = $this->createMock(TcpConnection::class);
|
|
||||||
$connection->expects($this->once())
|
|
||||||
->method('send')
|
|
||||||
->with($this->equalTo('Hello world'));
|
|
||||||
|
|
||||||
$this->handler->onMessage($connection, 'world');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testOnClose()
|
|
||||||
{
|
|
||||||
$connection = $this->createMock(TcpConnection::class);
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
$this->handler->onClose($connection);
|
|
||||||
$output = ob_get_clean();
|
|
||||||
|
|
||||||
$this->assertStringContainsString('Connection closed', $output);
|
|
||||||
}
|
|
||||||
}
|
|
1
tests/fff.php
Normal file
1
tests/fff.php
Normal file
@ -0,0 +1 @@
|
|||||||
|
fffffffff
|
Loading…
x
Reference in New Issue
Block a user