コード例 #1
0
 /**
  * Method to test __toString().
  *
  * @return void
  *
  * @covers \Windwalker\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() . '/windwalker-' . 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() . '/windwalker-' . uniqid();
     $this->assertFalse(is_file($to));
     $this->assertExpectedException(function () use($upload, $to) {
         $upload->moveTo($to);
     }, 'RuntimeException', 'Error moving uploaded file');
 }
コード例 #3
0
 /**
  * Method to test copyFrom().
  *
  * @return void
  *
  * @covers \Windwalker\Http\Helper\StreamHelper::copyFrom
  */
 public function testCopyFrom()
 {
     StreamHelper::copyFrom(__FILE__, $dest = new Stream('php://memory', Stream::MODE_READ_WRITE_FROM_BEGIN));
     $this->assertEquals(file_get_contents(__FILE__), $dest->__toString());
 }