diff --git a/tests/Unit/Connection/UdpConnectionTest.php b/tests/Unit/Connection/UdpConnectionTest.php index f5cab3d6c..ea05ea1c4 100644 --- a/tests/Unit/Connection/UdpConnectionTest.php +++ b/tests/Unit/Connection/UdpConnectionTest.php @@ -1,5 +1,44 @@ start(); + +it('tests ' . UdpConnection::class, function () use ($remoteAddress) { + + $socketClient = stream_socket_client("udp://$remoteAddress"); + $udpConnection = new UdpConnection($socketClient, $remoteAddress); + $udpConnection->protocol = \Workerman\Protocols\Text::class; + expect($udpConnection->send('foo'))->toBeTrue(); + + expect($udpConnection->getRemoteIp())->toBe('::1'); + expect($udpConnection->getRemotePort())->toBe(12345); + expect($udpConnection->getRemoteAddress())->toBe($remoteAddress); + expect($udpConnection->getLocalIp())->toBeIn(['::1', '[::1]', '127.0.0.1']); + expect($udpConnection->getLocalPort())->toBeInt(); + + expect(json_encode($udpConnection))->toBeJson() + ->toContain('transport') + ->toContain('getRemoteIp') + ->toContain('remotePort') + ->toContain('getRemoteAddress') + ->toContain('getLocalIp') + ->toContain('getLocalPort') + ->toContain('isIpV4') + ->toContain('isIpV6'); + + $udpConnection->close('bye'); + if (is_resource($socketClient)) { + fclose($socketClient); + } }); \ No newline at end of file