你的提交说明
Some checks failed
Run Unit Tests / test (push) Failing after 3s

This commit is contained in:
james 2025-06-12 11:15:54 +08:00
parent b060e45a30
commit bc5f5bd99e
2 changed files with 2 additions and 52 deletions

View File

@ -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
View File

@ -0,0 +1 @@
fffffffff