b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / vendor / ezimuel / guzzlestreams / tests /
Filename/home/dev2.destoffenstraat.com/vendor/ezimuel/guzzlestreams/tests/AppendStreamTest.php
Size5.25 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified24-Oct-2022 14:58
Last accessed21-Aug-2025 17:01
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
namespace GuzzleHttp\Tests\Stream;

use GuzzleHttp\Stream\AppendStream;
use GuzzleHttp\Stream\Exception\CannotAttachException;
use GuzzleHttp\Stream\Stream;
use PHPUnit\Framework\TestCase;

class AppendStreamTest extends TestCase
{
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Each stream must be readable
*/
public function testValidatesStreamsAreReadable()
{
$a = new AppendStream();
$s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
->getMockForAbstractClass();
$s->expects($this->once())
->method('isReadable')
->will($this->returnValue(true));
$a->addStream($s);
}

public function testValidatesSeekType()
{
$a = new AppendStream();
$this->assertFalse($a->seek(100, SEEK_CUR));
}

public function testTriesToRewindOnSeek()
{
$a = new AppendStream();
$s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
->getMockForAbstractClass();
$s->expects($this->once())
->method('isReadable')
->will($this->returnValue(true));
$s->expects($this->once())
->method('isSeekable')
->will($this->returnValue(true));
$s->expects($this->once())
->method('seek')
->will($this->returnValue(false));
$a->addStream($s);
$this->assertFalse($a->seek(10));
}

public function testSeeksToPositionByReading()
{
$a = new AppendStream([
Stream::factory('foo'),
Stream::factory('bar'),
Stream::factory('baz'),
]);

$this->assertTrue($a->seek(3));
$this->assertEquals(3, $a->tell());
$this->assertEquals('bar', $a->read(3));
$a->seek(6);
$this->assertEquals(6, $a->tell());
$this->assertEquals('baz', $a->read(3));
}

public function testDetachesEachStream()
{
$s1 = Stream::factory('foo');
$s2 = Stream::factory('foo');
$a = new AppendStream([$s1, $s2]);
$this->assertSame('foofoo', (string) $a);
$a->detach();
$this->assertSame('', (string) $a);
$this->assertSame(0, $a->getSize());
}

public function testClosesEachStream()
{
$s1 = Stream::factory('foo');
$a = new AppendStream([$s1]);
$a->close();
$this->assertSame('', (string) $a);
}

public function testIsNotWritable()
{
$a = new AppendStream([Stream::factory('foo')]);
$this->assertFalse($a->isWritable());
$this->assertTrue($a->isSeekable());
$this->assertTrue($a->isReadable());
$this->assertFalse($a->write('foo'));
}

public function testDoesNotNeedStreams()
{
$a = new AppendStream();
$this->assertEquals('', (string) $a);
}

public function testCanReadFromMultipleStreams()
{
$a = new AppendStream([
Stream::factory('foo'),
Stream::factory('bar'),
Stream::factory('baz'),
]);
$this->assertFalse($a->eof());
$this->assertSame(0, $a->tell());
$this->assertEquals('foo', $a->read(3));
$this->assertEquals('bar', $a->read(3));
$this->assertEquals('baz', $a->read(3));
$this->assertEmpty($a->read(1));
$this->assertTrue($a->eof());
$this->assertSame(9, $a->tell());
$this->assertEquals('foobarbaz', (string) $a);
}

public function testCanDetermineSizeFromMultipleStreams()
{
$a = new AppendStream([
Stream::factory('foo'),
Stream::factory('bar'),
]);
$this->assertEquals(6, $a->getSize());

$s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
->getMockForAbstractClass();
$s->expects($this->once())
->method('isSeekable')
->will($this->returnValue(null));
$s->expects($this->once())
->method('isReadable')
->will($this->returnValue(true));
$a->addStream($s);
$this->assertNull($a->getSize());
}

public function testCatchesExceptionsWhenCastingToString()
{
$s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
->getMockForAbstractClass();
$s->expects($this->once())
->method('read')
->will($this->throwException(new \RuntimeException('foo')));
$s->expects($this->once())
->method('isReadable')
->will($this->returnValue(true));
$s->expects($this->any())
->method('eof')
->will($this->returnValue(false));
$a = new AppendStream([$s]);
$this->assertFalse($a->eof());
$this->assertSame('', (string) $a);
}

/**
* @doesNotPerformAssertions
*/
public function testCanDetach()
{
$s = new AppendStream();
$s->detach();
}

public function testReturnsEmptyMetadata()
{
$s = new AppendStream();
$this->assertEquals([], $s->getMetadata());
$this->assertNull($s->getMetadata('foo'));
}

public function testCannotAttach()
{
$p = new AppendStream();
$this->expectException(CannotAttachException::class);
$p->attach('a');
}
}