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\ReadableStream;
6
use React\Stream\WritableStream;
7
 
8
/**
9
 * @covers React\Stream\WritableStream
10
 */
11
class WritableStreamTest extends TestCase
12
{
13
    /** @test */
14
    public function pipingStuffIntoItShouldWorkButDoNothing()
15
    {
16
        $readable = new ReadableStream();
17
        $through = new WritableStream();
18
 
19
        $readable->pipe($through);
20
        $readable->emit('data', array('foo'));
21
    }
22
 
23
    /** @test */
24
    public function endShouldCloseTheStream()
25
    {
26
        $through = new WritableStream();
27
        $through->on('data', $this->expectCallableNever());
28
        $through->end();
29
 
30
        $this->assertFalse($through->isWritable());
31
    }
32
 
33
    /** @test */
34
    public function endShouldWriteDataBeforeClosing()
35
    {
36
        $through = $this->getMock('React\Stream\WritableStream', array('write'));
37
        $through
38
            ->expects($this->once())
39
            ->method('write')
40
            ->with('foo');
41
        $through->end('foo');
42
 
43
        $this->assertFalse($through->isWritable());
44
    }
45
 
46
    /** @test */
47
    public function itShouldBeWritableByDefault()
48
    {
49
        $through = new WritableStream();
50
        $this->assertTrue($through->isWritable());
51
    }
52
 
53
    /** @test */
54
    public function closeShouldClose()
55
    {
56
        $through = new WritableStream();
57
        $through->close();
58
 
59
        $this->assertFalse($through->isWritable());
60
    }
61
 
62
    /** @test */
63
    public function doubleCloseShouldWork()
64
    {
65
        $through = new WritableStream();
66
        $through->close();
67
        $through->close();
68
 
69
        $this->assertFalse($through->isWritable());
70
    }
71
}