UdpConnectionTest.php 716 B

12345678910111213141516171819202122232425
  1. <?php
  2. use Symfony\Component\Process\PhpProcess;
  3. $process = null;
  4. beforeAll(function () use (&$process) {
  5. $process = new PhpProcess(file_get_contents(__DIR__ . '/Stub/UdpServer.php'));
  6. $process->start();
  7. usleep(250000);
  8. });
  9. afterAll(function () use (&$process) {
  10. echo "\nUDP Test:\n", $process->getOutput();
  11. $process->stop();
  12. });
  13. it('tests udp connection', function () {
  14. $socket = stream_socket_client('udp://127.0.0.1:8083', $errno, $errstr, 1);
  15. expect($errno)->toBeInt()->toBe(0);
  16. fwrite($socket, 'xiami');
  17. $data = fread($socket, 1024);
  18. expect($data)->toBeString('received: xiami');
  19. fclose($socket);
  20. })
  21. ->skipOnWindows(); //require posix