예제 #1
0
파일: StreamTest.php 프로젝트: kaiwa/http
 /**
  * Method to test __toString().
  *
  * @return void
  *
  * @covers Asika\Http\Stream::__toString
  */
 public function test__toString()
 {
     $message = 'foo bar';
     $this->instance->write($message);
     $this->assertEquals($message, (string) $this->instance);
     // Not readable should return empty string
     $this->createTempFile();
     file_put_contents($this->tmpnam, 'FOO BAR');
     $stream = new Stream($this->tmpnam, 'w');
     $this->assertEquals('', $stream->__toString());
 }
예제 #2
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');
 }