Ejemplo n.º 1
0
 public function testCanUseSeekEndWithUnknownSize()
 {
     $baseStream = Psr7\stream_for('testing');
     $decorated = Psr7\FnStream::decorate($baseStream, array('getSize' => function () {
         return null;
     }));
     $cached = new CachingStream($decorated);
     $cached->seek(1, SEEK_END);
     $this->assertEquals('ng', $cached->read(2));
 }
Ejemplo n.º 2
0
 public function testDecoratesWithCustomizations()
 {
     $called = false;
     $a = Psr7\stream_for('foo');
     $b = FnStream::decorate($a, array('read' => function ($len) use(&$called, $a) {
         $called = true;
         return $a->read($len);
     }));
     $this->assertEquals('foo', $b->read(3));
     $this->assertTrue($called);
 }
Ejemplo n.º 3
0
 /**
  * @expectedException \RuntimeException
  */
 public function testThrowsWhenBodyCannotBeRewound()
 {
     $body = Psr7\stream_for('abc');
     $body->read(1);
     $body = FnStream::decorate($body, array('rewind' => function () {
         throw new \RuntimeException('a');
     }));
     $res = new Psr7\Response(200, array(), $body);
     Psr7\rewind_body($res);
 }
Ejemplo n.º 4
0
    public function testSerializesFilesWithCustomHeadersAndMultipleValues()
    {
        $f1 = Psr7\FnStream::decorate(Psr7\stream_for('foo'), array('getMetadata' => function () {
            return '/foo/bar.txt';
        }));
        $f2 = Psr7\FnStream::decorate(Psr7\stream_for('baz'), array('getMetadata' => function () {
            return '/foo/baz.jpg';
        }));
        $b = new MultipartStream(array(array('name' => 'foo', 'contents' => $f1, 'headers' => array('x-foo' => 'bar', 'content-disposition' => 'custom')), array('name' => 'foo', 'contents' => $f2, 'headers' => array('cOntenT-Type' => 'custom'))), 'boundary');
        $expected = <<<EOT
--boundary
x-foo: bar
content-disposition: custom
Content-Length: 3
Content-Type: text/plain

foo
--boundary
cOntenT-Type: custom
Content-Disposition: form-data; name="foo"; filename="baz.jpg"
Content-Length: 3

baz
--boundary--

EOT;
        $this->assertEquals($expected, str_replace("\r", '', $b));
    }