Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

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