‪TYPO3CMS  10.4
UploadedFileFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\StreamInterface;
21 use Psr\Http\Message\UploadedFileFactoryInterface;
22 use Psr\Http\Message\UploadedFileInterface;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪UploadedFileFactoryTest extends UnitTestCase
30 {
35  {
36  $factory = new ‪UploadedFileFactory();
37  self::assertInstanceOf(UploadedFileFactoryInterface::class, $factory);
38  }
39 
43  public function ‪testCreateUploadedFile()
44  {
45  $streamProphecy = $this->prophesize(StreamInterface::class);
46  $factory = new ‪UploadedFileFactory();
47  $uploadedFile = $factory->createUploadedFile($streamProphecy->reveal(), 0);
48 
49  self::assertInstanceOf(UploadedFileInterface::class, $uploadedFile);
50  self::assertSame(UPLOAD_ERR_OK, $uploadedFile->getError());
51  self::assertNull($uploadedFile->getClientFileName());
52  self::assertNull($uploadedFile->getClientMediaType());
53  }
54 
59  {
60  $streamProphecy = $this->prophesize(StreamInterface::class);
61  $factory = new ‪UploadedFileFactory();
62  $uploadedFile = $factory->createUploadedFile($streamProphecy->reveal(), 0, UPLOAD_ERR_NO_FILE, 'filename.html', 'text/html');
63 
64  self::assertInstanceOf(UploadedFileInterface::class, $uploadedFile);
65  self::assertSame(UPLOAD_ERR_NO_FILE, $uploadedFile->getError());
66  self::assertSame('filename.html', $uploadedFile->getClientFileName());
67  self::assertSame('text/html', $uploadedFile->getClientMediaType());
68  }
69 
74  {
75  $streamProphecy = $this->prophesize(StreamInterface::class);
76  $streamProphecy->getSize()->willReturn(5);
77 
78  $factory = new ‪UploadedFileFactory();
79  $uploadedFile = $factory->createUploadedFile($streamProphecy->reveal());
80 
81  self::assertSame(5, $uploadedFile->getSize());
82  }
83 
88  {
89  $this->expectException(\InvalidArgumentException::class);
90  $this->expectExceptionCode(1566823423);
91 
92  $streamProphecy = $this->prophesize(StreamInterface::class);
93  $streamProphecy->getSize()->willReturn(null);
94 
95  $factory = new ‪UploadedFileFactory();
96  $uploadedFile = $factory->createUploadedFile($streamProphecy->reveal());
97 
98  self::assertSame(3, $uploadedFile->getSize());
99  }
100 }
‪TYPO3\CMS\Core\Tests\Unit\Http\UploadedFileFactoryTest\implementsPsr17FactoryInterface
‪implementsPsr17FactoryInterface()
Definition: UploadedFileFactoryTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\Http\UploadedFileFactoryTest\testCreateUploadedFileWithParams
‪testCreateUploadedFileWithParams()
Definition: UploadedFileFactoryTest.php:58
‪TYPO3\CMS\Core\Http\UploadedFileFactory
Definition: UploadedFileFactory.php:28
‪TYPO3\CMS\Core\Tests\Unit\Http
Definition: ApplicationTypeTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Http\UploadedFileFactoryTest\testCreateUploadedFileCreateSizeFromStreamSize
‪testCreateUploadedFileCreateSizeFromStreamSize()
Definition: UploadedFileFactoryTest.php:73
‪TYPO3\CMS\Core\Tests\Unit\Http\UploadedFileFactoryTest\testCreateUploadedFile
‪testCreateUploadedFile()
Definition: UploadedFileFactoryTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Http\UploadedFileFactoryTest\testCreateUploadedFileThrowsExceptionWhenStreamSizeCanNotBeDetermined
‪testCreateUploadedFileThrowsExceptionWhenStreamSizeCanNotBeDetermined()
Definition: UploadedFileFactoryTest.php:87
‪TYPO3\CMS\Core\Tests\Unit\Http\UploadedFileFactoryTest
Definition: UploadedFileFactoryTest.php:30