PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 2.5.5
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v2.5.5
3.7.2 3.7.1 3.7.0 3.6.0 3.6.1 3.5.2 trunk 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.6.0 2.6.1 All 73 releases
stockpack / vendor / guzzlehttp / psr7 / tests / LazyOpenStreamTest.php

LazyOpenStreamTest.php in StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more 2.5.5, at vendor/guzzlehttp/psr7/tests/LazyOpenStreamTest.php

65 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace GuzzleHttp\Tests\Psr7;
3
4 use GuzzleHttp\Psr7\LazyOpenStream;
5
6 class LazyOpenStreamTest extends BaseTest
7 {
8 private $fname;
9
10 protected function setUp()
11 {
12 $this->fname = tempnam('/tmp', 'tfile');
13
14 if (file_exists($this->fname)) {
15 unlink($this->fname);
16 }
17 }
18
19 protected 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 }
65