scratch – Blame information for rev 87
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
87 | office | 1 | <?php |
2 | namespace GuzzleHttp\Tests\Stream; |
||
3 | |||
4 | use GuzzleHttp\Stream\GuzzleStreamWrapper; |
||
5 | use GuzzleHttp\Stream\Stream; |
||
6 | |||
7 | /** |
||
8 | * @covers GuzzleHttp\Stream\GuzzleStreamWrapper |
||
9 | */ |
||
10 | class GuzzleStreamWrapperTest extends \PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | public function testResource() |
||
13 | { |
||
14 | $stream = Stream::factory('foo'); |
||
15 | $handle = GuzzleStreamWrapper::getResource($stream); |
||
16 | $this->assertSame('foo', fread($handle, 3)); |
||
17 | $this->assertSame(3, ftell($handle)); |
||
18 | $this->assertSame(3, fwrite($handle, 'bar')); |
||
19 | $this->assertSame(0, fseek($handle, 0)); |
||
20 | $this->assertSame('foobar', fread($handle, 6)); |
||
21 | $this->assertTrue(feof($handle)); |
||
22 | |||
23 | // This fails on HHVM for some reason |
||
24 | if (!defined('HHVM_VERSION')) { |
||
25 | $this->assertEquals([ |
||
26 | 'dev' => 0, |
||
27 | 'ino' => 0, |
||
28 | 'mode' => 33206, |
||
29 | 'nlink' => 0, |
||
30 | 'uid' => 0, |
||
31 | 'gid' => 0, |
||
32 | 'rdev' => 0, |
||
33 | 'size' => 6, |
||
34 | 'atime' => 0, |
||
35 | 'mtime' => 0, |
||
36 | 'ctime' => 0, |
||
37 | 'blksize' => 0, |
||
38 | 'blocks' => 0, |
||
39 | |||
40 | 1 => 0, |
||
41 | 2 => 33206, |
||
42 | 3 => 0, |
||
43 | 4 => 0, |
||
44 | 5 => 0, |
||
45 | 6 => 0, |
||
46 | 7 => 6, |
||
47 | 8 => 0, |
||
48 | 9 => 0, |
||
49 | 10 => 0, |
||
50 | 11 => 0, |
||
51 | 12 => 0, |
||
52 | ], fstat($handle)); |
||
53 | } |
||
54 | |||
55 | $this->assertTrue(fclose($handle)); |
||
56 | $this->assertSame('foobar', (string) $stream); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @expectedException \InvalidArgumentException |
||
61 | */ |
||
62 | public function testValidatesStream() |
||
63 | { |
||
64 | $stream = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface') |
||
65 | ->setMethods(['isReadable', 'isWritable']) |
||
66 | ->getMockForAbstractClass(); |
||
67 | $stream->expects($this->once()) |
||
68 | ->method('isReadable') |
||
69 | ->will($this->returnValue(false)); |
||
70 | $stream->expects($this->once()) |
||
71 | ->method('isWritable') |
||
72 | ->will($this->returnValue(false)); |
||
73 | GuzzleStreamWrapper::getResource($stream); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @expectedException \PHPUnit_Framework_Error_Warning |
||
78 | */ |
||
79 | public function testReturnsFalseWhenStreamDoesNotExist() |
||
80 | { |
||
81 | fopen('guzzle://foo', 'r'); |
||
82 | } |
||
83 | |||
84 | public function testCanOpenReadonlyStream() |
||
85 | { |
||
86 | $stream = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface') |
||
87 | ->setMethods(['isReadable', 'isWritable']) |
||
88 | ->getMockForAbstractClass(); |
||
89 | $stream->expects($this->once()) |
||
90 | ->method('isReadable') |
||
91 | ->will($this->returnValue(false)); |
||
92 | $stream->expects($this->once()) |
||
93 | ->method('isWritable') |
||
94 | ->will($this->returnValue(true)); |
||
95 | $r = GuzzleStreamWrapper::getResource($stream); |
||
96 | $this->assertInternalType('resource', $r); |
||
97 | fclose($r); |
||
98 | } |
||
99 | } |