summaryrefslogtreecommitdiff
path: root/server/vendor/guzzlehttp/psr7/tests/AppendStreamTest.php
diff options
context:
space:
mode:
authorEole <josselin.35@live.fr>2016-01-21 10:29:26 +0100
committerEole <josselin.35@live.fr>2016-01-21 10:29:26 +0100
commita44cc1d2e3c0f147e91a5c052ac7fd879e34e706 (patch)
treebdd6f72e0ba732c4fcc0479d1cfcf4d0baa5885d /server/vendor/guzzlehttp/psr7/tests/AppendStreamTest.php
parent35db27b0e62b4cdcb03b0d21bceb4efc769e6161 (diff)
Init Server Composer Components
Diffstat (limited to 'server/vendor/guzzlehttp/psr7/tests/AppendStreamTest.php')
-rw-r--r--server/vendor/guzzlehttp/psr7/tests/AppendStreamTest.php186
1 files changed, 186 insertions, 0 deletions
diff --git a/server/vendor/guzzlehttp/psr7/tests/AppendStreamTest.php b/server/vendor/guzzlehttp/psr7/tests/AppendStreamTest.php
new file mode 100644
index 0000000..3c197dc
--- /dev/null
+++ b/server/vendor/guzzlehttp/psr7/tests/AppendStreamTest.php
@@ -0,0 +1,186 @@
+<?php
+namespace GuzzleHttp\Tests\Psr7;
+
+use GuzzleHttp\Psr7\AppendStream;
+use GuzzleHttp\Psr7;
+
+class AppendStreamTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage Each stream must be readable
+ */
+ public function testValidatesStreamsAreReadable()
+ {
+ $a = new AppendStream();
+ $s = $this->getMockBuilder('Psr\Http\Message\StreamInterface')
+ ->setMethods(['isReadable'])
+ ->getMockForAbstractClass();
+ $s->expects($this->once())
+ ->method('isReadable')
+ ->will($this->returnValue(false));
+ $a->addStream($s);
+ }
+
+ /**
+ * @expectedException \RuntimeException
+ * @expectedExceptionMessage The AppendStream can only seek with SEEK_SET
+ */
+ public function testValidatesSeekType()
+ {
+ $a = new AppendStream();
+ $a->seek(100, SEEK_CUR);
+ }
+
+ /**
+ * @expectedException \RuntimeException
+ * @expectedExceptionMessage Unable to seek stream 0 of the AppendStream
+ */
+ public function testTriesToRewindOnSeek()
+ {
+ $a = new AppendStream();
+ $s = $this->getMockBuilder('Psr\Http\Message\StreamInterface')
+ ->setMethods(['isReadable', 'rewind', 'isSeekable'])
+ ->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('rewind')
+ ->will($this->throwException(new \RuntimeException()));
+ $a->addStream($s);
+ $a->seek(10);
+ }
+
+ public function testSeeksToPositionByReading()
+ {
+ $a = new AppendStream([
+ Psr7\stream_for('foo'),
+ Psr7\stream_for('bar'),
+ Psr7\stream_for('baz'),
+ ]);
+
+ $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 = Psr7\stream_for('foo');
+ $s2 = Psr7\stream_for('bar');
+ $a = new AppendStream([$s1, $s2]);
+ $this->assertSame('foobar', (string) $a);
+ $a->detach();
+ $this->assertSame('', (string) $a);
+ $this->assertSame(0, $a->getSize());
+ }
+
+ public function testClosesEachStream()
+ {
+ $s1 = Psr7\stream_for('foo');
+ $a = new AppendStream([$s1]);
+ $a->close();
+ $this->assertSame('', (string) $a);
+ }
+
+ /**
+ * @expectedExceptionMessage Cannot write to an AppendStream
+ * @expectedException \RuntimeException
+ */
+ public function testIsNotWritable()
+ {
+ $a = new AppendStream([Psr7\stream_for('foo')]);
+ $this->assertFalse($a->isWritable());
+ $this->assertTrue($a->isSeekable());
+ $this->assertTrue($a->isReadable());
+ $a->write('foo');
+ }
+
+ public function testDoesNotNeedStreams()
+ {
+ $a = new AppendStream();
+ $this->assertEquals('', (string) $a);
+ }
+
+ public function testCanReadFromMultipleStreams()
+ {
+ $a = new AppendStream([
+ Psr7\stream_for('foo'),
+ Psr7\stream_for('bar'),
+ Psr7\stream_for('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->assertSame('', $a->read(1));
+ $this->assertTrue($a->eof());
+ $this->assertSame(9, $a->tell());
+ $this->assertEquals('foobarbaz', (string) $a);
+ }
+
+ public function testCanDetermineSizeFromMultipleStreams()
+ {
+ $a = new AppendStream([
+ Psr7\stream_for('foo'),
+ Psr7\stream_for('bar')
+ ]);
+ $this->assertEquals(6, $a->getSize());
+
+ $s = $this->getMockBuilder('Psr\Http\Message\StreamInterface')
+ ->setMethods(['isSeekable', 'isReadable'])
+ ->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('Psr\Http\Message\StreamInterface')
+ ->setMethods(['isSeekable', 'read', 'isReadable', 'eof'])
+ ->getMockForAbstractClass();
+ $s->expects($this->once())
+ ->method('isSeekable')
+ ->will($this->returnValue(true));
+ $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);
+ }
+
+ public function testCanDetach()
+ {
+ $s = new AppendStream();
+ $s->detach();
+ }
+
+ public function testReturnsEmptyMetadata()
+ {
+ $s = new AppendStream();
+ $this->assertEquals([], $s->getMetadata());
+ $this->assertNull($s->getMetadata('foo'));
+ }
+}