2
namespace GuzzleHttp\Tests\Stream;
4
use GuzzleHttp\Stream\LazyOpenStream;
6
class LazyOpenStreamTest extends \PHPUnit_Framework_TestCase
10
public function setup()
12
$this->fname = tempnam('/tmp', 'tfile');
14
if (file_exists($this->fname)) {
19
public function tearDown()
21
if (file_exists($this->fname)) {
26
public function testOpensLazily()
28
$l = new LazyOpenStream($this->fname, 'w+');
30
$this->assertInternalType('array', $l->getMetadata());
31
$this->assertFileExists($this->fname);
32
$this->assertEquals('foo', file_get_contents($this->fname));
33
$this->assertEquals('foo', (string) $l);
36
public function testProxiesToFile()
38
file_put_contents($this->fname, 'foo');
39
$l = new LazyOpenStream($this->fname, 'r');
40
$this->assertEquals('foo', $l->read(4));
41
$this->assertTrue($l->eof());
42
$this->assertEquals(3, $l->tell());
43
$this->assertTrue($l->isReadable());
44
$this->assertTrue($l->isSeekable());
45
$this->assertFalse($l->isWritable());
47
$this->assertEquals('oo', $l->getContents());
48
$this->assertEquals('foo', (string) $l);
49
$this->assertEquals(3, $l->getSize());
50
$this->assertInternalType('array', $l->getMetadata());
54
public function testDetachesUnderlyingStream()
56
file_put_contents($this->fname, 'foo');
57
$l = new LazyOpenStream($this->fname, 'r');
59
$this->assertInternalType('resource', $r);
61
$this->assertEquals('foo', stream_get_contents($r));