From 3b816be46109611540ba3585b8ad9e36fbcfe91d Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Sat, 16 Jun 2018 21:51:41 +0800 Subject: [PATCH] fix parser test in swoole 4.0 --- tests/SocketIO/ParserTest.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/SocketIO/ParserTest.php b/tests/SocketIO/ParserTest.php index 1298a067..1c60b954 100644 --- a/tests/SocketIO/ParserTest.php +++ b/tests/SocketIO/ParserTest.php @@ -12,6 +12,8 @@ class ParserTest extends TestCase { + protected static $server; + public function testEncode() { $event = 'foo'; @@ -52,7 +54,7 @@ public function testDecode() public function testExecute() { $frame = m::mock(Frame::class); - $server = new Server('0.0.0.0'); + $server = $this->getServer(); $app = App::shouldReceive('call')->once(); @@ -68,11 +70,11 @@ public function testHeartbeatStrategy() $frame->data = $payload; $frame->fd = 1; - // // will lead to mockery bug - // $server = m::mock(swoole_websocket_server::class); + // will lead to mockery bug + // $server = m::mock(Server::class); // $server->shouldReceive('push')->once(); - $server = new Server('0.0.0.0'); + $server = $this->getServer(); $strategy = new HeartbeatStrategy; $this->assertFalse($strategy->handle($server, $frame)); @@ -84,4 +86,13 @@ public function testHeartbeatStrategy() // $frame->data = '2probe'; // $this->assertTrue($strategy->handle($server, $frame)); } + + protected function getServer() + { + if (static::$server) { + return static::$server; + } + + return static::$server = new Server('0.0.0.0'); + } }