Beispiel #1
0
 public function testFile()
 {
     $file = new PhpStream('tests/data/response', 'wb');
     $file->write('foobar');
     $file->close();
     $response = Response::file('tests/data/response', 'text/plain');
     $this->assertEquals(Status::OK, $response->getStatusCode());
     $this->assertEquals('text/plain', $response->getHeaderLine('Content-Type'));
     $this->assertEquals('foobar', $response->getBody());
 }
Beispiel #2
0
 public function testErrorHandling()
 {
     $this->assertThrows('Jivoo\\InvalidArgumentException', function () {
         new PhpStream('not/a/file');
     });
     $this->stream->close();
     $this->assertEquals('', $this->stream);
     $this->assertTrue($this->stream->eof());
     $this->assertEquals('', $this->stream->getContents());
     $this->assertEquals([], $this->stream->getMetadata());
     $this->assertNull($this->stream->getSize());
     $this->assertFalse($this->stream->isReadable());
     $this->assertFalse($this->stream->isWritable());
     $this->assertFalse($this->stream->isSeekable());
     $this->assertThrows('Jivoo\\Http\\Message\\StreamException', function () {
         $this->stream->read(5);
     });
     $this->assertThrows('Jivoo\\Http\\Message\\StreamException', function () {
         $this->stream->seek(5);
     });
     $this->assertThrows('Jivoo\\Http\\Message\\StreamException', function () {
         $this->stream->tell();
     });
     $this->assertThrows('Jivoo\\Http\\Message\\StreamException', function () {
         $this->stream->write('foo');
     });
 }