|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace React\Tests\Http; |
| 4 | + |
| 5 | +use React\Http\Response; |
| 6 | +use React\Http\UploadedFile; |
| 7 | +use React\Stream\ThroughStream; |
| 8 | +use RingCentral\Psr7\BufferStream; |
| 9 | + |
| 10 | +class UploadedFileTest extends TestCase |
| 11 | +{ |
| 12 | + public function failtyErrorProvider() |
| 13 | + { |
| 14 | + return array( |
| 15 | + array('a'), |
| 16 | + array(null), |
| 17 | + array(-1), |
| 18 | + array(9), |
| 19 | + ); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * @dataProvider failtyErrorProvider |
| 24 | + * @expectedException \InvalidArgumentException |
| 25 | + * @expectedExceptionMessage Invalid error code, must be an UPLOAD_ERR_* constant |
| 26 | + */ |
| 27 | + public function testFailtyError($error) |
| 28 | + { |
| 29 | + $stream = new BufferStream(); |
| 30 | + new UploadedFile($stream, 0, $error, 'foo.bar', 'foo/bar'); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @expectedException \RuntimeException |
| 35 | + * @expectedExceptionMessage Not implemented |
| 36 | + */ |
| 37 | + public function testNoMoveFile() |
| 38 | + { |
| 39 | + $stream = new BufferStream(); |
| 40 | + $uploadedFile = new UploadedFile($stream, 0, UPLOAD_ERR_OK, 'foo.bar', 'foo/bar'); |
| 41 | + $uploadedFile->moveTo('bar.foo'); |
| 42 | + } |
| 43 | + |
| 44 | + public function testGetters() |
| 45 | + { |
| 46 | + $stream = new BufferStream(); |
| 47 | + $uploadedFile = new UploadedFile($stream, 0, UPLOAD_ERR_OK, 'foo.bar', 'foo/bar'); |
| 48 | + self::assertSame($stream, $uploadedFile->getStream()); |
| 49 | + self::assertSame(0, $uploadedFile->getSize()); |
| 50 | + self::assertSame(UPLOAD_ERR_OK, $uploadedFile->getError()); |
| 51 | + self::assertSame('foo.bar', $uploadedFile->getClientFilename()); |
| 52 | + self::assertSame('foo/bar', $uploadedFile->getClientMediaType()); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @expectedException \RuntimeException |
| 57 | + * @expectedExceptionMessage Cannot retrieve stream due to upload error |
| 58 | + */ |
| 59 | + public function testGetStreamOnFailedUpload() |
| 60 | + { |
| 61 | + $stream = new BufferStream(); |
| 62 | + $uploadedFile = new UploadedFile($stream, 0, UPLOAD_ERR_NO_FILE, 'foo.bar', 'foo/bar'); |
| 63 | + $uploadedFile->getStream(); |
| 64 | + } |
| 65 | +} |
0 commit comments