File: UploadedFileTest.php

package info (click to toggle)
php-slim-psr7 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 656 kB
  • sloc: php: 5,274; makefile: 17; sh: 11; xml: 10
file content (56 lines) | stat: -rw-r--r-- 1,374 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

/**
 * Slim Framework (https://slimframework.com)
 *
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 */

declare(strict_types=1);

namespace Slim\Tests\Psr7\Integration;

use PHPUnit\Framework\TestCase as UploadedFileIntegrationTest;
//use Http\Psr7Test\UploadedFileIntegrationTest;
use Psr\Http\Message\UploadedFileInterface;
use Slim\Psr7\UploadedFile;

use function sys_get_temp_dir;
use function tempnam;

/**
 * @group excluded
 */
#[\PHPUnit\Framework\Attributes\Group('excluded')]
class UploadedFileTest extends UploadedFileIntegrationTest
{
    use BaseTestFactories;

    protected string $tempFilename;

    /**
     * @return UploadedFileInterface
     */
    public function createSubject()
    {
        $this->tempFilename = tempnam(sys_get_temp_dir(), 'Slim_Http_UploadedFileTest_');
        if (!$this->tempFilename) {
            throw new \RuntimeException("Unable to create temporary file");
        }
        file_put_contents($this->tempFilename, '12345');

        return new UploadedFile(
            $this->tempFilename,
            basename($this->tempFilename),
            'text/plain',
            (int)filesize($this->tempFilename)
        );
    }

    protected function tearDown(): void
    {
        if (is_file($this->tempFilename)) {
            unlink($this->tempFilename);
        }
    }
}