File: StreamFactoryTest.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 (71 lines) | stat: -rw-r--r-- 2,019 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?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\Factory;

use PHPUnit\Framework\TestCase as StreamFactoryTestCase;
//use Interop\Http\Factory\StreamFactoryTestCase;
use InvalidArgumentException;
use RuntimeException;
use Slim\Psr7\Factory\StreamFactory;

/**
 * @group excluded
 */
#[\PHPUnit\Framework\Attributes\Group('excluded')]
class StreamFactoryTest extends StreamFactoryTestCase
{
    public function tearDown(): void
    {
        if (isset($GLOBALS['fopen_return'])) {
            unset($GLOBALS['fopen_return']);
        }
    }

    protected function createStreamFactory(): StreamFactory
    {
        return new StreamFactory();
    }

    public function testCreateStreamThrowsRuntimeException()
    {
        $this->expectException(RuntimeException::class);
        $this->expectExceptionMessage('StreamFactory::createStream() could not open temporary file stream.');

        $GLOBALS['fopen_return'] = false;

        $factory = $this->createStreamFactory();

        $factory->createStream();
    }

    public function testCreateStreamFromFileThrowsRuntimeException()
    {
        $this->expectException(RuntimeException::class);
        $this->expectExceptionMessage('StreamFactory::createStreamFromFile() could not create resource'
                                      . ' from file `non-readable`');

        $GLOBALS['fopen_return'] = false;

        $factory = $this->createStreamFactory();

        $factory->createStreamFromFile('non-readable');
    }

    public function testCreateStreamFromResourceThrowsRuntimeException()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Parameter 1 of StreamFactory::createStreamFromResource() must be a resource.');

        $factory = $this->createStreamFactory();

        $factory->createStreamFromResource('not-resource');
    }
}