LibEventLoopTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace React\Tests\EventLoop;
  3. use React\EventLoop\LibEventLoop;
  4. class LibEventLoopTest extends AbstractLoopTest
  5. {
  6. private $fifoPath;
  7. public function createLoop()
  8. {
  9. if ('Linux' === PHP_OS && !extension_loaded('posix')) {
  10. $this->markTestSkipped('libevent tests skipped on linux due to linux epoll issues.');
  11. }
  12. if (!function_exists('event_base_new')) {
  13. $this->markTestSkipped('libevent tests skipped because ext-libevent is not installed.');
  14. }
  15. return new LibEventLoop();
  16. }
  17. public function tearDown()
  18. {
  19. if (file_exists($this->fifoPath)) {
  20. unlink($this->fifoPath);
  21. }
  22. }
  23. public function createStream()
  24. {
  25. if ('Linux' !== PHP_OS) {
  26. return parent::createStream();
  27. }
  28. $this->fifoPath = tempnam(sys_get_temp_dir(), 'react-');
  29. unlink($this->fifoPath);
  30. // Use a FIFO on linux to get around lack of support for disk-based file
  31. // descriptors when using the EPOLL back-end.
  32. posix_mkfifo($this->fifoPath, 0600);
  33. $stream = fopen($this->fifoPath, 'r+');
  34. return $stream;
  35. }
  36. public function writeToStream($stream, $content)
  37. {
  38. if ('Linux' !== PHP_OS) {
  39. return parent::writeToStream($stream, $content);
  40. }
  41. fwrite($stream, $content);
  42. }
  43. }