12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace React\Tests\EventLoop;
- use React\EventLoop\ExtEventLoop;
- class ExtEventLoopTest extends AbstractLoopTest
- {
- public function createLoop($readStreamCompatible = false)
- {
- if ('Linux' === PHP_OS && !extension_loaded('posix')) {
- $this->markTestSkipped('libevent tests skipped on linux due to linux epoll issues.');
- }
- if (!extension_loaded('event')) {
- $this->markTestSkipped('ext-event tests skipped because ext-event is not installed.');
- }
- $cfg = null;
- if ($readStreamCompatible) {
- $cfg = new \EventConfig();
- $cfg->requireFeatures(\EventConfig::FEATURE_FDS);
- }
- return new ExtEventLoop($cfg);
- }
- public function createStream()
- {
-
-
- if ('Linux' === PHP_OS) {
- $this->fifoPath = tempnam(sys_get_temp_dir(), 'react-');
- unlink($this->fifoPath);
- posix_mkfifo($this->fifoPath, 0600);
- $stream = fopen($this->fifoPath, 'r+');
-
-
-
-
-
-
- } else {
- $stream = fopen('php://temp/maxmemory:0', 'r+');
- fwrite($stream, 'x');
- ftruncate($stream, 0);
- }
- return $stream;
- }
- public function writeToStream($stream, $content)
- {
- if ('Linux' !== PHP_OS) {
- return parent::writeToStream($stream, $content);
- }
- fwrite($stream, $content);
- }
-
- public function testCanUseReadableStreamWithFeatureFds()
- {
- if (PHP_VERSION_ID > 70000) {
- $this->markTestSkipped('Memory stream not supported');
- }
- $this->loop = $this->createLoop(true);
- $input = fopen('php://temp/maxmemory:0', 'r+');
- fwrite($input, 'x');
- ftruncate($input, 0);
- $this->loop->addReadStream($input, $this->expectCallableExactly(2));
- fwrite($input, "foo\n");
- $this->loop->tick();
- fwrite($input, "bar\n");
- $this->loop->tick();
- }
- }
|