UploadedFileFactoryTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 5.0.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Http;
  17. use Cake\Http\UploadedFileFactory;
  18. use Cake\TestSuite\TestCase;
  19. use Laminas\Diactoros\Stream;
  20. /**
  21. * Test case for the uploaded file factory.
  22. */
  23. class UploadedFileFactoryTest extends TestCase
  24. {
  25. protected UploadedFileFactory $factory;
  26. protected string $filename = TMP . 'uploadedfile-factory-file-test.txt';
  27. protected function setUp(): void
  28. {
  29. parent::setUp();
  30. $this->factory = new UploadedFileFactory();
  31. }
  32. protected function tearDown(): void
  33. {
  34. parent::tearDown();
  35. // phpcs:disable
  36. @unlink($this->filename);
  37. // phpcs:enable
  38. }
  39. public function testCreateStreamResource(): void
  40. {
  41. file_put_contents($this->filename, 'it works');
  42. $stream = new Stream($this->filename);
  43. $uploadedFile = $this->factory->createUploadedFile($stream, null, UPLOAD_ERR_OK, 'my-name');
  44. $this->assertSame('my-name', $uploadedFile->getClientFilename());
  45. $this->assertSame($stream, $uploadedFile->getStream());
  46. }
  47. }