-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathStreamTest.php
More file actions
89 lines (80 loc) · 2.37 KB
/
StreamTest.php
File metadata and controls
89 lines (80 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
use FastD\Http\Stream;
use PHPUnit\Framework\TestCase;
/**
*
* @author jan huang <bboyjanhuang@gmail.com>
* @copyright 2018
*
* @link https://www.github.com/janhuang
* @link http://www.fast-d.cn/
*/
class StreamTest extends TestCase
{
/**
* @var Stream
*/
protected $stream;
public function setUp()
{
$this->stream = new Stream('php://memory', 'wb+');
}
public function testStreamStatus()
{
$this->assertTrue($this->stream->isReadable());
$this->assertTrue($this->stream->isWritable());
}
public function testToStringRetrievesFullContentsOfStream()
{
$message = 'foo bar';
$this->stream->write($message);
$this->assertEquals($message, (string) $this->stream);
}
public function testGetContentsOfStream()
{
$message = 'foo bar';
$this->stream->write($message);
$this->assertEmpty($this->stream->getContents());
$this->stream->rewind();
$this->assertEquals($message, (string) $this->stream);
$this->stream->rewind();
$this->assertEquals($this->stream->getContents(), (string) $this->stream);
$this->assertTrue($this->stream->eof());
}
public function testStreamSize()
{
$message = 'foo bar';
$this->stream->write($message);
$this->assertEquals(7, $this->stream->getSize());
}
public function testStreamReadAndWrite()
{
$message = 'foo bar';
$this->stream->write($message);
$this->assertFalse($this->stream->eof());
$this->assertEquals(7, $this->stream->tell());
$this->assertTrue($this->stream->seek(4));
$this->assertEquals('ba', $this->stream->read(2));
$this->assertEquals('r', $this->stream->read(1));
}
public function testStreamEOF()
{
$message = 'foo bar';
$this->stream->write($message);
$this->stream->seek(0);
$this->assertFalse($this->stream->eof());
$this->stream->getContents();
$this->assertTrue($this->stream->eof());
}
/**
* @expectedException \RuntimeException
*/
public function testStreamClose()
{
$message = 'foo bar';
$this->stream->write($message);
$this->assertEquals(7, $this->stream->getSize());
$this->stream->close();
$this->stream->write($message);
}
}