|
10 | 10 | use SwooleTW\Http\Server\Sandbox; |
11 | 11 | use SwooleTW\Http\Tests\TestCase; |
12 | 12 | use Illuminate\Container\Container; |
| 13 | +use SwooleTW\Http\Websocket\HandShakeHandler; |
13 | 14 | use SwooleTW\Http\Websocket\Parser; |
14 | 15 | use SwooleTW\Http\Server\PidManager; |
15 | 16 | use SwooleTW\Http\Table\SwooleTable; |
16 | 17 | use Laravel\Lumen\Exceptions\Handler; |
17 | 18 | use Illuminate\Support\Facades\Config; |
18 | 19 | use SwooleTW\Http\Websocket\Websocket; |
19 | 20 | use SwooleTW\Http\Server\Facades\Server; |
20 | | -use SwooleTW\Http\Websocket\Facades\Pusher; |
21 | 21 | use SwooleTW\Http\Websocket\HandlerContract; |
22 | 22 | use SwooleTW\Http\Websocket\Rooms\TableRoom; |
23 | 23 | use SwooleTW\Http\Websocket\Rooms\RoomContract; |
@@ -48,6 +48,8 @@ class ManagerTest extends TestCase |
48 | 48 | 'swoole_http.websocket.enabled' => true, |
49 | 49 | 'swoole_websocket.parser' => SocketIOParser::class, |
50 | 50 | 'swoole_websocket.handler' => WebsocketHandler::class, |
| 51 | + 'swoole_websocket.handshake.enabled' => true, |
| 52 | + 'swoole_websocket.handshake.handler' => HandShakeHandler::class, |
51 | 53 | 'swoole_websocket.default' => 'table', |
52 | 54 | 'swoole_websocket.settings.table' => [ |
53 | 55 | 'room_rows' => 10, |
@@ -414,6 +416,66 @@ public function testOnOpen() |
414 | 416 | $manager->onOpen(m::mock('server'), $request); |
415 | 417 | } |
416 | 418 |
|
| 419 | + public function testOnHandShake() |
| 420 | + { |
| 421 | + $request = m::mock(Request::class); |
| 422 | + $request->shouldReceive('rawcontent') |
| 423 | + ->once() |
| 424 | + ->andReturn([]); |
| 425 | + $request->fd = 1; |
| 426 | + $request->header['sec-websocket-key'] = 'Bet8DkPFq9ZxvIBvPcNy1A=='; |
| 427 | + |
| 428 | + $response = m::mock(Response::class); |
| 429 | + $response->shouldReceive('header')->withAnyArgs()->times(4)->andReturnSelf(); |
| 430 | + $response->shouldReceive('status')->with(101)->once()->andReturnSelf(); |
| 431 | + $response->shouldReceive('end')->withAnyArgs()->once()->andReturnSelf(); |
| 432 | + |
| 433 | + $container = $this->getContainer($this->getServer(), $this->getConfig(true)); |
| 434 | + $container->singleton(Websocket::class, function () { |
| 435 | + $websocket = m::mock(Websocket::class); |
| 436 | + $websocket->shouldReceive('reset') |
| 437 | + ->with(true) |
| 438 | + ->once() |
| 439 | + ->andReturnSelf(); |
| 440 | + $websocket->shouldReceive('setSender') |
| 441 | + ->with(1) |
| 442 | + ->once(); |
| 443 | + $websocket->shouldReceive('eventExists') |
| 444 | + ->with('connect') |
| 445 | + ->once() |
| 446 | + ->andReturn(true); |
| 447 | + $websocket->shouldReceive('setContainer') |
| 448 | + ->with(m::type(Container::class)) |
| 449 | + ->once(); |
| 450 | + $websocket->shouldReceive('call') |
| 451 | + ->with('connect', m::type('Illuminate\Http\Request')) |
| 452 | + ->once(); |
| 453 | + |
| 454 | + return $websocket; |
| 455 | + }); |
| 456 | + $container->singleton(Sandbox::class, function () { |
| 457 | + $sandbox = m::mock(Sandbox::class); |
| 458 | + $sandbox->shouldReceive('setRequest') |
| 459 | + ->with(m::type('Illuminate\Http\Request')) |
| 460 | + ->once(); |
| 461 | + $sandbox->shouldReceive('enable') |
| 462 | + ->once(); |
| 463 | + $sandbox->shouldReceive('disable') |
| 464 | + ->once(); |
| 465 | + $sandbox->shouldReceive('getApplication') |
| 466 | + ->once() |
| 467 | + ->andReturn(m::mock(Container::class)); |
| 468 | + |
| 469 | + return $sandbox; |
| 470 | + }); |
| 471 | + |
| 472 | + $container->alias(Sandbox::class, 'swoole.sandbox'); |
| 473 | + |
| 474 | + $manager = $this->getWebsocketManager(); |
| 475 | + $manager->setApplication($container); |
| 476 | + $manager->onHandShake($request, $response); |
| 477 | + } |
| 478 | + |
417 | 479 | public function testOnMessage() |
418 | 480 | { |
419 | 481 | $frame = m::mock('frame'); |
|
0 commit comments