![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/ezimuel/guzzlestreams/tests/ |
<?php namespace GuzzleHttp\Tests\Stream; use GuzzleHttp\Stream\LazyOpenStream; use PHPUnit\Framework\TestCase; class LazyOpenStreamTest extends TestCase { private $fname; public function setup(): void { $this->fname = tempnam('/tmp', 'tfile'); if (file_exists($this->fname)) { unlink($this->fname); } } public function tearDown(): void { if (file_exists($this->fname)) { unlink($this->fname); } } public function testOpensLazily() { $l = new LazyOpenStream($this->fname, 'w+'); $l->write('foo'); $this->assertIsArray($l->getMetadata()); $this->assertFileExists($this->fname); $this->assertEquals('foo', file_get_contents($this->fname)); $this->assertEquals('foo', (string) $l); } public function testProxiesToFile() { file_put_contents($this->fname, 'foo'); $l = new LazyOpenStream($this->fname, 'r'); $this->assertEquals('foo', $l->read(4)); $this->assertTrue($l->eof()); $this->assertEquals(3, $l->tell()); $this->assertTrue($l->isReadable()); $this->assertTrue($l->isSeekable()); $this->assertFalse($l->isWritable()); $l->seek(1); $this->assertEquals('oo', $l->getContents()); $this->assertEquals('foo', (string) $l); $this->assertEquals(3, $l->getSize()); $this->assertIsArray($l->getMetadata()); $l->close(); } public function testDetachesUnderlyingStream() { file_put_contents($this->fname, 'foo'); $l = new LazyOpenStream($this->fname, 'r'); $r = $l->detach(); $this->assertIsResource($r); fseek($r, 0); $this->assertEquals('foo', stream_get_contents($r)); fclose($r); } }