Exemplo n.º 1
0
 /**
  * Method to test getMetadata().
  *
  * @return void
  *
  * @covers Asika\Http\Stream::getMetadata
  */
 public function testGetMetadata()
 {
     $this->createTempFile();
     $resource = fopen($this->tmpnam, Stream::MODE_READ_WRITE_FROM_BEGIN);
     $this->instance->attach($resource);
     $this->assertEquals(stream_get_meta_data($resource), $this->instance->getMetadata());
     $this->assertEquals(Stream::MODE_READ_WRITE_FROM_BEGIN, $this->instance->getMetadata('mode'));
     fclose($resource);
 }
Exemplo n.º 2
0
 /**
  * Read data from the stream.
  *
  * @param   int  $length  Read up to $length bytes from the object and return
  *                        them. Fewer than $length bytes may be returned if underlying stream
  *                        call returns fewer bytes.
  *
  * @return   string  Returns the data read from the stream, or an empty string
  *                   if no bytes are available.
  *
  * @throws \RuntimeException if an error occurs.
  */
 public function read($length)
 {
     $content = parent::read($length);
     if ($content && !$this->reachedEof) {
         $this->cache .= $content;
     }
     if ($this->eof()) {
         $this->reachedEof = true;
     }
     return $content;
 }
Exemplo n.º 3
0
 /**
  * testMoveInNotCli
  *
  * @return  void
  */
 public function testMoveInNotCli()
 {
     // Send stream
     $stream = new Stream('php://temp', 'wb+');
     $stream->write('Foo bar!');
     $upload = new UploadedFile($stream, 0, UPLOAD_ERR_OK);
     $upload->setSapi('cgi');
     $this->tmpFile = $to = sys_get_temp_dir() . '/http-' . uniqid();
     $this->assertFalse(is_file($to));
     $upload->moveTo($to);
     $this->assertTrue(is_file($to));
     $contents = file_get_contents($to);
     $this->assertEquals($stream->__toString(), $contents);
     // Send string
     $uploadFile = sys_get_temp_dir() . '/upload-' . uniqid();
     file_put_contents($uploadFile, 'Foo bar!');
     $upload = new UploadedFile($uploadFile, 0, UPLOAD_ERR_OK);
     $upload->setSapi('cgi');
     $this->tmpFile = $to = sys_get_temp_dir() . '/http-' . uniqid();
     $this->assertFalse(is_file($to));
     $this->assertExpectedException(function () use($upload, $to) {
         $upload->moveTo($to);
     }, 'RuntimeException', 'Error moving uploaded file');
 }