Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit c249bd1

Browse files
committed
Merge branch 'hotfix/82'
Close #87 Fixes #82
2 parents e654167 + f39479d commit c249bd1

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ All notable changes to this project will be documented in this file, in reverse
3030
Previously, several simply passed non-string input on verbatim, others
3131
normalized the input, and a few correctly raised the exceptions. Behavior is
3232
now consistent across each.
33+
- [#87](https://github.com/zendframework/zend-diactoros/pull/87) fixes
34+
`UploadedFile` to ensure that `moveTo()` works correctly in non-SAPI
35+
environments when the file provided to the constructor is a path.
3336

3437
## 1.1.2 - 2015-07-12
3538

src/UploadedFile.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ private function writeFile($path)
223223
throw new RuntimeException('Unable to write to designated path');
224224
}
225225

226-
$this->stream->rewind();
227-
while (! $this->stream->eof()) {
228-
fwrite($handle, $this->stream->read(4096));
226+
$stream = $this->getStream();
227+
$stream->rewind();
228+
while (! $stream->eof()) {
229+
fwrite($handle, $stream->read(4096));
229230
}
230231

231232
fclose($handle);

test/UploadedFileTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,20 @@ public function testGetStreamRaisesExceptionWhenErrorStatusPresent($status)
270270
$this->setExpectedException('RuntimeException', 'upload error');
271271
$stream = $uploadedFile->getStream();
272272
}
273+
274+
/**
275+
* @group 82
276+
*/
277+
public function testMoveToCreatesStreamIfOnlyAFilenameWasProvided()
278+
{
279+
$this->tmpFile = tempnam(sys_get_temp_dir(), 'DIA');
280+
281+
$uploadedFile = new UploadedFile(__FILE__, 100, UPLOAD_ERR_OK, basename(__FILE__), 'text/plain');
282+
$uploadedFile->moveTo($this->tmpFile);
283+
284+
$original = file_get_contents(__FILE__);
285+
$test = file_get_contents($this->tmpFile);
286+
287+
$this->assertEquals($original, $test);
288+
}
273289
}

0 commit comments

Comments
 (0)