react-websocket/tests/WebSocketMiddlewareTest.php

57 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace NoccyLabs\React\WebSocket;
use PHPUnit\Framework\Attributes\CoversClass;
use React\Http\Message\ServerRequest;
#[CoversClass(WebSocketMiddleware::class)]
class WebSocketMiddlewareTest extends \PHPUnit\Framework\TestCase
{
public function testThatRegularRequestsAreIgnored()
{
$mock = $this->getMockBuilder(InvokableDummy::class)->getMock();
$mock->expects($this->never())
->method('test');
$next = $this->getMockBuilder(InvokableDummy::class)->getMock();
$next->expects($this->once())
->method('test');
$request = new ServerRequest("GET", "/", [], "");
$middleware = new WebSocketMiddleware();
$middleware->on('connection', [$mock,"test"]);
$middleware->__invoke($request, [$next,"test"]);
}
public function testThatWebSocketRequestsAreHandled()
{
$mock = $this->getMockBuilder(InvokableDummy::class)->getMock();
$mock->expects($this->once())
->method('test');
$next = $this->getMockBuilder(InvokableDummy::class)->getMock();
$next->expects($this->never())
->method('test');
$request = new ServerRequest("GET", "/", [
'upgrade' => [ 'websocket' ]
]);
$middleware = new WebSocketMiddleware();
$middleware->on('connection', [$mock,"test"]);
$middleware->__invoke($request, [$next,"test"]);
}
}
class InvokableDummy
{
public function test()
{
}
}