ExtLibeventLoopTest.php 1.5 KB

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