source: externals/php/vendor/guzzlehttp/psr7/tests/LazyOpenStreamTest.php@ d55ec21

Last change on this file since d55ec21 was 01a620f, checked in by Joachim Langenbach <joachim.langenbach@…>, 11 years ago

Removed submodules for php externals and use composer to provide them and versioned them afterwards

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[01a620f]1<?php
2namespace GuzzleHttp\Tests\Psr7;
3
4use GuzzleHttp\Psr7\LazyOpenStream;
5
6class LazyOpenStreamTest extends \PHPUnit_Framework_TestCase
7{
8 private $fname;
9
10 public function setup()
11 {
12 $this->fname = tempnam('/tmp', 'tfile');
13
14 if (file_exists($this->fname)) {
15 unlink($this->fname);
16 }
17 }
18
19 public function tearDown()
20 {
21 if (file_exists($this->fname)) {
22 unlink($this->fname);
23 }
24 }
25
26 public function testOpensLazily()
27 {
28 $l = new LazyOpenStream($this->fname, 'w+');
29 $l->write('foo');
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);
34 }
35
36 public function testProxiesToFile()
37 {
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());
46 $l->seek(1);
47 $this->assertEquals('oo', $l->getContents());
48 $this->assertEquals('foo', (string) $l);
49 $this->assertEquals(3, $l->getSize());
50 $this->assertInternalType('array', $l->getMetadata());
51 $l->close();
52 }
53
54 public function testDetachesUnderlyingStream()
55 {
56 file_put_contents($this->fname, 'foo');
57 $l = new LazyOpenStream($this->fname, 'r');
58 $r = $l->detach();
59 $this->assertInternalType('resource', $r);
60 fseek($r, 0);
61 $this->assertEquals('foo', stream_get_contents($r));
62 fclose($r);
63 }
64}
Note: See TracBrowser for help on using the repository browser.