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\ExtEventLoop;
6
 
7
class ExtEventLoopTest extends AbstractLoopTest
8
{
9
    public function createLoop($readStreamCompatible = false)
10
    {
11
        if ('Linux' === PHP_OS && !extension_loaded('posix')) {
12
            $this->markTestSkipped('libevent tests skipped on linux due to linux epoll issues.');
13
        }
14
 
15
        if (!extension_loaded('event')) {
16
            $this->markTestSkipped('ext-event tests skipped because ext-event is not installed.');
17
        }
18
 
19
        $cfg = null;
20
        if ($readStreamCompatible) {
21
            $cfg = new \EventConfig();
22
            $cfg->requireFeatures(\EventConfig::FEATURE_FDS);
23
        }
24
 
25
        return new ExtEventLoop($cfg);
26
    }
27
 
28
    public function createStream()
29
    {
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
        if ('Linux' === PHP_OS) {
33
            $this->fifoPath = tempnam(sys_get_temp_dir(), 'react-');
34
 
35
            unlink($this->fifoPath);
36
 
37
            posix_mkfifo($this->fifoPath, 0600);
38
 
39
            $stream = fopen($this->fifoPath, 'r+');
40
 
41
        // ext-event (as of 1.8.1) does not yet support in-memory temporary
42
        // streams. Setting maxmemory:0 and performing a write forces PHP to
43
        // back this temporary stream with a real file.
44
        //
45
        // This problem is mentioned at https://bugs.php.net/bug.php?id=64652&edit=3
46
        // but remains unresolved (despite that issue being closed).
47
        } else {
48
            $stream = fopen('php://temp/maxmemory:0', 'r+');
49
 
50
            fwrite($stream, 'x');
51
            ftruncate($stream, 0);
52
        }
53
 
54
        return $stream;
55
    }
56
 
57
    public function writeToStream($stream, $content)
58
    {
59
        if ('Linux' !== PHP_OS) {
60
            return parent::writeToStream($stream, $content);
61
        }
62
 
63
        fwrite($stream, $content);
64
    }
65
 
66
    /**
67
     * @group epoll-readable-error
68
     */
69
    public function testCanUseReadableStreamWithFeatureFds()
70
    {
71
        if (PHP_VERSION_ID > 70000) {
72
            $this->markTestSkipped('Memory stream not supported');
73
        }
74
 
75
        $this->loop = $this->createLoop(true);
76
 
77
        $input = fopen('php://temp/maxmemory:0', 'r+');
78
 
79
        fwrite($input, 'x');
80
        ftruncate($input, 0);
81
 
82
        $this->loop->addReadStream($input, $this->expectCallableExactly(2));
83
 
84
        $this->writeToStream($input, "foo\n");
85
        $this->loop->tick();
86
 
87
        $this->writeToStream($input, "bar\n");
88
        $this->loop->tick();
89
    }
90
}