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');
}
}
|