2
namespace GuzzleHttp\Tests\Stream;
4
use GuzzleHttp\Stream\GuzzleStreamWrapper;
5
use GuzzleHttp\Stream\Stream;
8
* @covers GuzzleHttp\Stream\GuzzleStreamWrapper
10
class GuzzleStreamWrapperTest extends \PHPUnit_Framework_TestCase
12
public function testResource()
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));
23
// This fails on HHVM for some reason
24
if (!defined('HHVM_VERSION')) {
55
$this->assertTrue(fclose($handle));
56
$this->assertSame('foobar', (string) $stream);
60
* @expectedException \InvalidArgumentException
62
public function testValidatesStream()
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);
77
* @expectedException \PHPUnit_Framework_Error_Warning
79
public function testReturnsFalseWhenStreamDoesNotExist()
81
fopen('guzzle://foo', 'r');
84
public function testCanOpenReadonlyStream()
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);