/** * Method to test write(). * * @return void * * @covers Asika\Http\Stream::write */ public function testWrite() { $this->createTempFile(); $resource = fopen($this->tmpnam, Stream::MODE_READ_WRITE_RESET); $stream = new Stream($resource); $stream->write('flower'); $this->assertEquals('flower', file_get_contents($this->tmpnam)); $stream->write(' bloom'); $this->assertEquals('flower bloom', file_get_contents($this->tmpnam)); $stream->seek(4); $stream->write('test'); $this->assertEquals('flowtestloom', file_get_contents($this->tmpnam)); }
/** * 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'); }