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\Stream;
4
 
5
use React\Stream\Stream;
6
use React\EventLoop as rel;
7
 
8
class StreamIntegrationTest extends TestCase
9
{
10
    public function loopProvider()
11
    {
12
        return array(
13
            array(function() { return true; }, function() { return new rel\StreamSelectLoop; }),
14
            array(function() { return function_exists('event_base_new'); }, function() { return new rel\LibEventLoop; }),
15
            array(function() { return class_exists('libev\EventLoop'); }, function() { return new rel\LibEvLoop; }),
16
            array(function() { return class_exists('EventBase'); }, function() { return new rel\ExtEventLoop; })
17
        );
18
    }
19
 
20
    /**
21
     * @dataProvider loopProvider
22
     */
23
    public function testBufferReadsLargeChunks($condition, $loopFactory)
24
    {
25
        if (true !== $condition()) {
26
            return $this->markTestSkipped('Loop implementation not available');
27
        }
28
 
29
        $loop = $loopFactory();
30
 
31
        list($sockA, $sockB) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
32
 
33
        $streamA = new Stream($sockA, $loop);
34
        $streamB = new Stream($sockB, $loop);
35
 
36
        $bufferSize = 4096;
37
        $streamA->bufferSize = $bufferSize;
38
        $streamB->bufferSize = $bufferSize;
39
 
40
        $testString = str_repeat("*", $streamA->bufferSize + 1);
41
 
42
        $buffer = "";
43
        $streamB->on('data', function ($data, $streamB) use (&$buffer, &$testString) {
44
            $buffer .= $data;
45
        });
46
 
47
        $streamA->write($testString);
48
 
49
        $loop->tick();
50
        $loop->tick();
51
        $loop->tick();
52
 
53
        $streamA->close();
54
        $streamB->close();
55
 
56
        $this->assertEquals($testString, $buffer);
57
    }
58
}