the middle of the idiots
This commit is contained in:
		
							
								
								
									
										95
									
								
								qwen/php/vendor/slim/psr7/tests/Assets/HeaderStack.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								qwen/php/vendor/slim/psr7/tests/Assets/HeaderStack.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,95 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This is a direct copy of zend-diactoros/test/TestAsset/Functions.php and is used to override
 | 
			
		||||
 * header() and headers_sent() so we can test that they do the right thing.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Assets;
 | 
			
		||||
 | 
			
		||||
use function strpos;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Zend Framework (http://framework.zend.com/)
 | 
			
		||||
 *
 | 
			
		||||
 * This file exists to allow overriding the various output-related functions
 | 
			
		||||
 * in order to test what happens during the `Server::listen()` cycle.
 | 
			
		||||
 *
 | 
			
		||||
 * These functions include:
 | 
			
		||||
 *
 | 
			
		||||
 * - headers_sent(): we want to always return false so that headers will be
 | 
			
		||||
 *   emitted, and we can test to see their values.
 | 
			
		||||
 * - header(): we want to aggregate calls to this function.
 | 
			
		||||
 *
 | 
			
		||||
 * The HeaderStack class then aggregates that information for us, and the test
 | 
			
		||||
 * harness resets the values pre and post test.
 | 
			
		||||
 *
 | 
			
		||||
 * @see       http://github.com/zendframework/zend-diactoros for the canonical source repository
 | 
			
		||||
 * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
 | 
			
		||||
 * @license   https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class HeaderStack
 | 
			
		||||
{
 | 
			
		||||
    private static array $data = [];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Reset state
 | 
			
		||||
     */
 | 
			
		||||
    public static function reset()
 | 
			
		||||
    {
 | 
			
		||||
        self::$data = [];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Push a header on the stack
 | 
			
		||||
     *
 | 
			
		||||
     * @param string[] $header
 | 
			
		||||
     */
 | 
			
		||||
    public static function push(array $header)
 | 
			
		||||
    {
 | 
			
		||||
        self::$data[] = $header;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Return the current header stack
 | 
			
		||||
     *
 | 
			
		||||
     * @return string[][]
 | 
			
		||||
     */
 | 
			
		||||
    public static function stack(): array
 | 
			
		||||
    {
 | 
			
		||||
        return self::$data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Verify if there's a header line on the stack
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $header
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public static function has($header): bool
 | 
			
		||||
    {
 | 
			
		||||
        foreach (self::$data as $item) {
 | 
			
		||||
            if ($item['header'] === $header) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remove occurrences of $header
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $header
 | 
			
		||||
     */
 | 
			
		||||
    public static function remove($header): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (self::$data as $key => $item) {
 | 
			
		||||
            if (false !== strpos($item['header'], "$header:")) {
 | 
			
		||||
                unset(self::$data[$key]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										422
									
								
								qwen/php/vendor/slim/psr7/tests/BodyTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										422
									
								
								qwen/php/vendor/slim/psr7/tests/BodyTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,422 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
 | 
			
		||||
use function fclose;
 | 
			
		||||
use function feof;
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function fread;
 | 
			
		||||
use function fseek;
 | 
			
		||||
use function ftell;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function is_array;
 | 
			
		||||
use function is_resource;
 | 
			
		||||
use function mb_strlen;
 | 
			
		||||
use function rewind;
 | 
			
		||||
use function substr;
 | 
			
		||||
 | 
			
		||||
class BodyTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    // @codingStandardsIgnoreStart
 | 
			
		||||
    protected string $text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
 | 
			
		||||
    // @codingStandardsIgnoreEnd
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var resource
 | 
			
		||||
     */
 | 
			
		||||
    protected $stream;
 | 
			
		||||
 | 
			
		||||
    protected function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        if (is_resource($this->stream) === true) {
 | 
			
		||||
            fclose($this->stream);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $mode
 | 
			
		||||
     *
 | 
			
		||||
     * @return resource
 | 
			
		||||
     */
 | 
			
		||||
    public function resourceFactory(string $mode = 'r+')
 | 
			
		||||
    {
 | 
			
		||||
        $stream = fopen('php://temp', $mode);
 | 
			
		||||
        fwrite($stream, $this->text);
 | 
			
		||||
        rewind($stream);
 | 
			
		||||
 | 
			
		||||
        return $stream;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructorAttachesStream()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($this->stream, $bodyStream->getValue($body));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructorInvalidStream()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = 'foo';
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetMetadata()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue(is_array($body->getMetadata()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetMetadataKey()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('php://temp', $body->getMetadata('uri'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetMetadataKeyNotFound()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($body->getMetadata('foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDetach()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodyMetadata = new ReflectionProperty($body, 'meta');
 | 
			
		||||
        $bodyMetadata->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodyReadable = new ReflectionProperty($body, 'readable');
 | 
			
		||||
        $bodyReadable->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodyWritable = new ReflectionProperty($body, 'writable');
 | 
			
		||||
        $bodyWritable->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodySeekable = new ReflectionProperty($body, 'seekable');
 | 
			
		||||
        $bodySeekable->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $result = $body->detach();
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($this->stream, $result);
 | 
			
		||||
        $this->assertNull($bodyStream->getValue($body));
 | 
			
		||||
        $this->assertNull($bodyMetadata->getValue($body));
 | 
			
		||||
        $this->assertNull($bodyReadable->getValue($body));
 | 
			
		||||
        $this->assertNull($bodyWritable->getValue($body));
 | 
			
		||||
        $this->assertNull($bodySeekable->getValue($body));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToStringAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($this->text, (string) $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToStringAttachedRewindsFirst()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($this->text, (string) $body);
 | 
			
		||||
        $this->assertEquals($this->text, (string) $body);
 | 
			
		||||
        $this->assertEquals($this->text, (string) $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToStringDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
        $bodyStream->setValue($body, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', (string) $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testClose()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->close();
 | 
			
		||||
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($bodyStream->getValue($body));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetSizeAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(mb_strlen($this->text), $body->getSize());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetSizeDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
        $bodyStream->setValue($body, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($body->getSize());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testTellAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        fseek($this->stream, 10);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(10, $body->tell());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testTellDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
        $bodyStream->setValue($body, null);
 | 
			
		||||
 | 
			
		||||
        $body->tell();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testEofAttachedFalse()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        fseek($this->stream, 10);
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->eof());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testEofAttachedTrue()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        while (feof($this->stream) === false) {
 | 
			
		||||
            fread($this->stream, 1024);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($body->eof());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testEofDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
        $bodyStream->setValue($body, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($body->eof());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function isReadableAttachedTrue()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($body->isReadable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function isReadableAttachedFalse()
 | 
			
		||||
    {
 | 
			
		||||
        $stream = fopen('php://temp', 'w');
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->isReadable());
 | 
			
		||||
        fclose($stream);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsReadableDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->isReadable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function isWritableAttachedTrue()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($body->isWritable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function isWritableAttachedFalse()
 | 
			
		||||
    {
 | 
			
		||||
        $stream = fopen('php://temp', 'r');
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->isWritable());
 | 
			
		||||
        fclose($stream);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsWritableDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->isWritable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function isSeekableAttachedTrue()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($body->isSeekable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO: Is seekable is false when attached... how?
 | 
			
		||||
 | 
			
		||||
    public function testIsSeekableDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->isSeekable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSeekAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->seek(10);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(10, ftell($this->stream));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSeekDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $body->seek(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRewindAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        fseek($this->stream, 10);
 | 
			
		||||
        $body->rewind();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(0, ftell($this->stream));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRewindDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $body->rewind();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReadAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(substr($this->text, 0, 10), $body->read(10));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReadDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $body->read(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWriteAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        while (feof($this->stream) === false) {
 | 
			
		||||
            fread($this->stream, 1024);
 | 
			
		||||
        }
 | 
			
		||||
        $body->write('foo');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($this->text . 'foo', (string) $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWriteDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $body->write('foo');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetContentsAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        fseek($this->stream, 10);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(substr($this->text, 10), $body->getContents());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetContentsDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $body->getContents();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										283
									
								
								qwen/php/vendor/slim/psr7/tests/CookiesTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										283
									
								
								qwen/php/vendor/slim/psr7/tests/CookiesTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,283 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use ReflectionClass;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use Slim\Psr7\Cookies;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
use function gmdate;
 | 
			
		||||
use function json_decode;
 | 
			
		||||
use function strtotime;
 | 
			
		||||
use function time;
 | 
			
		||||
 | 
			
		||||
class CookiesTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testConstructor()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies([
 | 
			
		||||
            'test' => 'Works',
 | 
			
		||||
        ]);
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'requestCookies');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $this->assertNotEmpty($prop->getValue($cookies)['test']);
 | 
			
		||||
        $this->assertEquals('Works', $prop->getValue($cookies)['test']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetDefaults()
 | 
			
		||||
    {
 | 
			
		||||
        $defaults = [
 | 
			
		||||
            'value' => 'toast',
 | 
			
		||||
            'domain' => null,
 | 
			
		||||
            'hostonly' => null,
 | 
			
		||||
            'path' => null,
 | 
			
		||||
            'expires' => null,
 | 
			
		||||
            'secure' => true,
 | 
			
		||||
            'httponly' => true,
 | 
			
		||||
            'samesite' => null
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'defaults');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $origDefaults = $prop->getValue($cookies);
 | 
			
		||||
 | 
			
		||||
        $cookies->setDefaults($defaults);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($defaults, $prop->getValue($cookies));
 | 
			
		||||
        $this->assertNotEquals($origDefaults, $prop->getValue($cookies));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetCookieValues()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $cookies->set('foo', 'bar');
 | 
			
		||||
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'responseCookies');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $expectedValue = [
 | 
			
		||||
            'foo' => [
 | 
			
		||||
                'value' => 'bar',
 | 
			
		||||
                'domain' => null,
 | 
			
		||||
                'hostonly' => null,
 | 
			
		||||
                'path' => null,
 | 
			
		||||
                'expires' => null,
 | 
			
		||||
                'secure' => false,
 | 
			
		||||
                'httponly' => false,
 | 
			
		||||
                'samesite' => null
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedValue, $prop->getValue($cookies));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetCookieValuesContainDefaults()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $defaults = [
 | 
			
		||||
            'value' => 'toast',
 | 
			
		||||
            'domain' => null,
 | 
			
		||||
            'hostonly' => null,
 | 
			
		||||
            'path' => null,
 | 
			
		||||
            'expires' => null,
 | 
			
		||||
            'secure' => true,
 | 
			
		||||
            'httponly' => true,
 | 
			
		||||
            'samesite' => 'lax'
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $cookies->setDefaults($defaults);
 | 
			
		||||
        $cookies->set('foo', 'bar');
 | 
			
		||||
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'responseCookies');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $expectedValue = [
 | 
			
		||||
            'foo' => [
 | 
			
		||||
                'value' => 'bar',
 | 
			
		||||
                'domain' => null,
 | 
			
		||||
                'hostonly' => null,
 | 
			
		||||
                'path' => null,
 | 
			
		||||
                'expires' => null,
 | 
			
		||||
                'secure' => true,
 | 
			
		||||
                'httponly' => true,
 | 
			
		||||
                'samesite' => 'lax'
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedValue, $prop->getValue($cookies));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetCookieValuesCanOverrideDefaults()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $defaults = [
 | 
			
		||||
            'value' => 'toast',
 | 
			
		||||
            'domain' => null,
 | 
			
		||||
            'hostonly' => null,
 | 
			
		||||
            'path' => null,
 | 
			
		||||
            'expires' => null,
 | 
			
		||||
            'secure' => true,
 | 
			
		||||
            'httponly' => true,
 | 
			
		||||
            'samesite' => 'lax'
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $cookies->setDefaults($defaults);
 | 
			
		||||
        $cookies->set('foo', ['value' => 'bar', 'secure' => false, 'samesite' => 'strict']);
 | 
			
		||||
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'responseCookies');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $expectedValue = [
 | 
			
		||||
            'foo' => [
 | 
			
		||||
                'value' => 'bar',
 | 
			
		||||
                'domain' => null,
 | 
			
		||||
                'hostonly' => null,
 | 
			
		||||
                'path' => null,
 | 
			
		||||
                'expires' => null,
 | 
			
		||||
                'secure' => false,
 | 
			
		||||
                'httponly' => true,
 | 
			
		||||
                'samesite' => 'strict'
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedValue, $prop->getValue($cookies));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetSameSiteCookieValuesAreCaseInsensitive()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $defaults = [
 | 
			
		||||
            'value' => 'bacon',
 | 
			
		||||
            'samesite' => 'lax'
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $cookies->setDefaults($defaults);
 | 
			
		||||
        $cookies->set('breakfast', ['samesite' => 'StricT']);
 | 
			
		||||
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'responseCookies');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $expectedValue = [
 | 
			
		||||
            'breakfast' => [
 | 
			
		||||
                'value' => 'bacon',
 | 
			
		||||
                'domain' => null,
 | 
			
		||||
                'hostonly' => null,
 | 
			
		||||
                'path' => null,
 | 
			
		||||
                'expires' => null,
 | 
			
		||||
                'secure' => false,
 | 
			
		||||
                'httponly' => false,
 | 
			
		||||
                'samesite' => 'StricT',
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedValue, $prop->getValue($cookies));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGet()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies(['foo' => 'bar', 'baz' => null]);
 | 
			
		||||
        $this->assertEquals('bar', $cookies->get('foo'));
 | 
			
		||||
        $this->assertNull($cookies->get('baz', 'defaultValue'));
 | 
			
		||||
        $this->assertNull($cookies->get('missing'));
 | 
			
		||||
        $this->assertEquals('defaultValue', $cookies->get('missing', 'defaultValue'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testParseHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = Cookies::parseHeader('foo=bar; name=Josh');
 | 
			
		||||
        $this->assertEquals('bar', $cookies['foo']);
 | 
			
		||||
        $this->assertEquals('Josh', $cookies['name']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testParseHeaderWithJsonArray()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = Cookies::parseHeader('foo=bar; testarray=["someVar1","someVar2","someVar3"]');
 | 
			
		||||
        $this->assertEquals('bar', $cookies['foo']);
 | 
			
		||||
        $this->assertContains('someVar3', json_decode($cookies['testarray']));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToHeaders()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $cookies->set('test', 'Works');
 | 
			
		||||
        $cookies->set('test_array', ['value' => 'bar', 'domain' => 'example.com']);
 | 
			
		||||
        $this->assertEquals('test=Works', $cookies->toHeaders()[0]);
 | 
			
		||||
        $this->assertEquals('test_array=bar; domain=example.com', $cookies->toHeaders()[1]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $class = new ReflectionClass($cookies);
 | 
			
		||||
        $method = $class->getMethod('toHeader');
 | 
			
		||||
        $method->setAccessible(true);
 | 
			
		||||
        $properties = [
 | 
			
		||||
            'name' => 'test',
 | 
			
		||||
            'properties' => [
 | 
			
		||||
                'value' => 'Works'
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
        $time = time();
 | 
			
		||||
        $formattedDate = gmdate('D, d-M-Y H:i:s e', $time);
 | 
			
		||||
        $propertiesComplex = [
 | 
			
		||||
            'name' => 'test_complex',
 | 
			
		||||
            'properties' => [
 | 
			
		||||
                'value' => 'Works',
 | 
			
		||||
                'domain' => 'example.com',
 | 
			
		||||
                'expires' => $time,
 | 
			
		||||
                'path' => '/',
 | 
			
		||||
                'secure' => true,
 | 
			
		||||
                'hostonly' => true,
 | 
			
		||||
                'httponly' => true,
 | 
			
		||||
                'samesite' => 'lax'
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
        $stringDate = '2016-01-01 12:00:00';
 | 
			
		||||
        $formattedStringDate = gmdate('D, d-M-Y H:i:s e', strtotime($stringDate));
 | 
			
		||||
        $propertiesStringDate = [
 | 
			
		||||
            'name' => 'test_date',
 | 
			
		||||
            'properties' => [
 | 
			
		||||
                'value' => 'Works',
 | 
			
		||||
                'expires' => $stringDate,
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
        $cookie = $method->invokeArgs($cookies, $properties);
 | 
			
		||||
        $cookieComplex = $method->invokeArgs($cookies, $propertiesComplex);
 | 
			
		||||
        $cookieStringDate = $method->invokeArgs($cookies, $propertiesStringDate);
 | 
			
		||||
        $this->assertEquals('test=Works', $cookie);
 | 
			
		||||
        $this->assertEquals(
 | 
			
		||||
            'test_complex=Works; domain=example.com; path=/; expires='
 | 
			
		||||
            . $formattedDate . '; secure; HostOnly; HttpOnly; SameSite=lax',
 | 
			
		||||
            $cookieComplex
 | 
			
		||||
        );
 | 
			
		||||
        $this->assertEquals('test_date=Works; expires=' . $formattedStringDate, $cookieStringDate);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testParseHeaderException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        Cookies::parseHeader(new stdClass());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetSameSiteNoneToHeaders()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $cookies->set('foo', ['value' => 'bar', 'samesite' => 'None']);
 | 
			
		||||
        $this->assertEquals('foo=bar; SameSite=None', $cookies->toHeaders()[0]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										48
									
								
								qwen/php/vendor/slim/psr7/tests/EnvironmentTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								qwen/php/vendor/slim/psr7/tests/EnvironmentTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
 | 
			
		||||
class EnvironmentTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testMock()
 | 
			
		||||
    {
 | 
			
		||||
        $env = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => '/foo/bar/index.php',
 | 
			
		||||
            'REQUEST_URI' => '/foo/bar?abc=123',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/foo/bar/index.php', $env['SCRIPT_NAME']);
 | 
			
		||||
        $this->assertEquals('/foo/bar?abc=123', $env['REQUEST_URI']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testMockHttps()
 | 
			
		||||
    {
 | 
			
		||||
        $env = Environment::mock([
 | 
			
		||||
            'HTTPS' => 'on'
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('on', $env['HTTPS']);
 | 
			
		||||
        $this->assertEquals(443, $env['SERVER_PORT']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testMockRequestScheme()
 | 
			
		||||
    {
 | 
			
		||||
        $env = Environment::mock([
 | 
			
		||||
            'REQUEST_SCHEME' => 'https'
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('https', $env['REQUEST_SCHEME']);
 | 
			
		||||
        $this->assertEquals(443, $env['SERVER_PORT']);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										42
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/RequestFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/RequestFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
<?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 Interop\Http\Factory\RequestFactoryTestCase;
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use Slim\Psr7\Factory\RequestFactory;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
class RequestFactoryTest extends RequestFactoryTestCase
 | 
			
		||||
{
 | 
			
		||||
    protected function createRequestFactory(): RequestFactory
 | 
			
		||||
    {
 | 
			
		||||
        return new RequestFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function createUri($uri): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        return (new UriFactory())->createUri($uri);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateRequestThrowsExceptionWithInvalidUri()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Parameter 2 of RequestFactory::createRequest() must be a string' .
 | 
			
		||||
                                      ' or a compatible UriInterface.');
 | 
			
		||||
 | 
			
		||||
        $factory = $this->createRequestFactory();
 | 
			
		||||
 | 
			
		||||
        $factory->createRequest('GET', new stdClass());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										42
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/ResponseFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/ResponseFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
<?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 Interop\Http\Factory\ResponseFactoryTestCase;
 | 
			
		||||
use Psr\Http\Message\ResponseInterface;
 | 
			
		||||
use Slim\Psr7\Factory\ResponseFactory;
 | 
			
		||||
 | 
			
		||||
class ResponseFactoryTest extends ResponseFactoryTestCase
 | 
			
		||||
{
 | 
			
		||||
    protected function createResponseFactory(): ResponseFactory
 | 
			
		||||
    {
 | 
			
		||||
        return new ResponseFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function assertResponseCodeAndReasonPhrase(ResponseInterface $response, int $code, string $reasonPhrase)
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertInstanceOf(ResponseInterface::class, $response);
 | 
			
		||||
        $this->assertSame($code, $response->getStatusCode());
 | 
			
		||||
        $this->assertSame($reasonPhrase, $response->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider dataCodes
 | 
			
		||||
     *
 | 
			
		||||
     * @param int $code
 | 
			
		||||
     */
 | 
			
		||||
    public function testCreateResponseWithReasonPhrase(int $code)
 | 
			
		||||
    {
 | 
			
		||||
        $response = $this->factory->createResponse($code, 'Reason');
 | 
			
		||||
        $this->assertResponse($response, $code);
 | 
			
		||||
        $this->assertResponseCodeAndReasonPhrase($response, $code, 'Reason');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										208
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/ServerRequestFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										208
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/ServerRequestFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,208 @@
 | 
			
		||||
<?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 Interop\Http\Factory\ServerRequestFactoryTestCase;
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use ReflectionClass;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
use Slim\Psr7\Factory\ServerRequestFactory;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
use function microtime;
 | 
			
		||||
use function time;
 | 
			
		||||
 | 
			
		||||
class ServerRequestFactoryTest extends ServerRequestFactoryTestCase
 | 
			
		||||
{
 | 
			
		||||
    protected function createServerRequestFactory(): ServerRequestFactory
 | 
			
		||||
    {
 | 
			
		||||
        return new ServerRequestFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function createUri($uri): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        return (new UriFactory())->createUri($uri);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetProtocolVersion()
 | 
			
		||||
    {
 | 
			
		||||
        $env = Environment::mock(['SERVER_PROTOCOL' => 'HTTP/1.0']);
 | 
			
		||||
        $request = $this->createServerRequestFactory()->createServerRequest('GET', '', $env);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('1.0', $request->getProtocolVersion());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobals()
 | 
			
		||||
    {
 | 
			
		||||
        $GLOBALS['getallheaders_return'] = [
 | 
			
		||||
            'ACCEPT' => 'application/json',
 | 
			
		||||
            'ACCEPT-CHARSET' => 'utf-8',
 | 
			
		||||
            'ACCEPT-LANGUAGE' => 'en-US',
 | 
			
		||||
            'CONTENT-TYPE' => 'multipart/form-data',
 | 
			
		||||
            'HOST' => 'example.com',
 | 
			
		||||
            'USER-AGENT' => 'Slim Framework',
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $_SERVER = Environment::mock([
 | 
			
		||||
            'HTTP_HOST' => 'example.com',
 | 
			
		||||
            'PHP_AUTH_PW' => 'sekrit',
 | 
			
		||||
            'PHP_AUTH_USER' => 'josh',
 | 
			
		||||
            'QUERY_STRING' => 'abc=123',
 | 
			
		||||
            'REMOTE_ADDR' => '127.0.0.1',
 | 
			
		||||
            'REQUEST_METHOD' => 'GET',
 | 
			
		||||
            'REQUEST_TIME' => time(),
 | 
			
		||||
            'REQUEST_TIME_FLOAT' => microtime(true),
 | 
			
		||||
            'REQUEST_URI' => '/foo/bar',
 | 
			
		||||
            'SCRIPT_NAME' => '/index.php',
 | 
			
		||||
            'SERVER_NAME' => 'localhost',
 | 
			
		||||
            'SERVER_PORT' => 8080,
 | 
			
		||||
            'SERVER_PROTOCOL' => 'HTTP/1.1',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        unset($GLOBALS['getallheaders_return']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('GET', $request->getMethod());
 | 
			
		||||
        $this->assertEquals('1.1', $request->getProtocolVersion());
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('application/json', $request->getHeaderLine('Accept'));
 | 
			
		||||
        $this->assertEquals('utf-8', $request->getHeaderLine('Accept-Charset'));
 | 
			
		||||
        $this->assertEquals('en-US', $request->getHeaderLine('Accept-Language'));
 | 
			
		||||
        $this->assertEquals('multipart/form-data', $request->getHeaderLine('Content-Type'));
 | 
			
		||||
 | 
			
		||||
        $uri = $request->getUri();
 | 
			
		||||
        $this->assertEquals('josh:sekrit', $uri->getUserInfo());
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getHost());
 | 
			
		||||
        $this->assertEquals('8080', $uri->getPort());
 | 
			
		||||
        $this->assertEquals('/foo/bar', $uri->getPath());
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
        $this->assertEquals('', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithParsedBody()
 | 
			
		||||
    {
 | 
			
		||||
        $_SERVER = Environment::mock([
 | 
			
		||||
            'HTTP_CONTENT_TYPE' => 'multipart/form-data',
 | 
			
		||||
            'REQUEST_METHOD' => 'POST',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $_POST = [
 | 
			
		||||
            'def' => '456',
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        // $_POST should be placed into the parsed body
 | 
			
		||||
        $this->assertEquals($_POST, $request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsBodyPointsToPhpInput()
 | 
			
		||||
    {
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('php://input', $request->getBody()->getMetadata('uri'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsSetsACache()
 | 
			
		||||
    {
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        // ensure that the Stream's $cache property has been set for this php://input stream
 | 
			
		||||
        $stream = $request->getBody();
 | 
			
		||||
        $class = new ReflectionClass($stream);
 | 
			
		||||
        $property = $class->getProperty('cache');
 | 
			
		||||
        $property->setAccessible(true);
 | 
			
		||||
        $cacheStreamValue = $property->getValue($stream);
 | 
			
		||||
        $this->assertNotNull($cacheStreamValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithUploadedFiles()
 | 
			
		||||
    {
 | 
			
		||||
        $_SERVER = Environment::mock([
 | 
			
		||||
            'HTTP_CONTENT_TYPE' => 'multipart/form-data',
 | 
			
		||||
            'REQUEST_METHOD' => 'POST',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $_FILES = [
 | 
			
		||||
            'uploaded_file' => [
 | 
			
		||||
                'name' => [
 | 
			
		||||
                    0 => 'foo.jpg',
 | 
			
		||||
                    1 => 'bar.jpg',
 | 
			
		||||
                ],
 | 
			
		||||
 | 
			
		||||
                'type' => [
 | 
			
		||||
                    0 => 'image/jpeg',
 | 
			
		||||
                    1 => 'image/jpeg',
 | 
			
		||||
                ],
 | 
			
		||||
 | 
			
		||||
                'tmp_name' => [
 | 
			
		||||
                    0 => '/tmp/phpUA3XUw',
 | 
			
		||||
                    1 => '/tmp/phpXUFS0x',
 | 
			
		||||
                ],
 | 
			
		||||
 | 
			
		||||
                'error' => [
 | 
			
		||||
                    0 => 0,
 | 
			
		||||
                    1 => 0,
 | 
			
		||||
                ],
 | 
			
		||||
 | 
			
		||||
                'size' => [
 | 
			
		||||
                    0 => 358708,
 | 
			
		||||
                    1 => 236162,
 | 
			
		||||
                ],
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        // $_FILES should be mapped to an array of UploadedFile objects
 | 
			
		||||
        $uploadedFiles = $request->getUploadedFiles();
 | 
			
		||||
        $this->assertCount(1, $uploadedFiles);
 | 
			
		||||
        $this->assertArrayHasKey('uploaded_file', $uploadedFiles);
 | 
			
		||||
        $this->assertInstanceOf(UploadedFile::class, $uploadedFiles['uploaded_file'][0]);
 | 
			
		||||
        $this->assertInstanceOf(UploadedFile::class, $uploadedFiles['uploaded_file'][1]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsParsesBodyWithFragmentedContentType()
 | 
			
		||||
    {
 | 
			
		||||
        $_SERVER = Environment::mock([
 | 
			
		||||
            'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded;charset=utf-8',
 | 
			
		||||
            'REQUEST_METHOD' => 'POST',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $_POST = [
 | 
			
		||||
            'def' => '456',
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($_POST, $request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateServerRequestWithNullAsUri()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $env = Environment::mock();
 | 
			
		||||
        $this->createServerRequestFactory()->createServerRequest('GET', null, $env);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateServerRequestWithInvalidUriObject()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $env = Environment::mock();
 | 
			
		||||
        $this->createServerRequestFactory()->createServerRequest('GET', new stdClass(), $env);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										66
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/StreamFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/StreamFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
<?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 Interop\Http\Factory\StreamFactoryTestCase;
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\Factory\StreamFactory;
 | 
			
		||||
 | 
			
		||||
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');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										114
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/UploadedFileFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/UploadedFileFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,114 @@
 | 
			
		||||
<?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 Interop\Http\Factory\UploadedFileFactoryTestCase;
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Prophecy\PhpUnit\ProphecyTrait;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Slim\Psr7\Factory\StreamFactory;
 | 
			
		||||
use Slim\Psr7\Factory\UploadedFileFactory;
 | 
			
		||||
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function rewind;
 | 
			
		||||
use function sys_get_temp_dir;
 | 
			
		||||
use function tempnam;
 | 
			
		||||
 | 
			
		||||
class UploadedFileFactoryTest extends UploadedFileFactoryTestCase
 | 
			
		||||
{
 | 
			
		||||
    use ProphecyTrait;
 | 
			
		||||
 | 
			
		||||
    protected function createUploadedFileFactory(): UploadedFileFactory
 | 
			
		||||
    {
 | 
			
		||||
        return new UploadedFileFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function createStream($content): StreamInterface
 | 
			
		||||
    {
 | 
			
		||||
        $file = tempnam(sys_get_temp_dir(), 'Slim_Http_UploadedFileTest_');
 | 
			
		||||
        $resource = fopen($file, 'r+');
 | 
			
		||||
        fwrite($resource, $content);
 | 
			
		||||
        rewind($resource);
 | 
			
		||||
 | 
			
		||||
        return (new StreamFactory())->createStreamFromResource($resource);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Prophesize a `\Psr\Http\Message\StreamInterface` with a `getMetadata` method prophecy.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $argKey Argument for the method prophecy.
 | 
			
		||||
     * @param mixed $returnValue Return value of the `getMetadata` method.
 | 
			
		||||
     *
 | 
			
		||||
     * @return StreamInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected function prophesizeStreamInterfaceWithGetMetadataMethod(string $argKey, $returnValue): StreamInterface
 | 
			
		||||
    {
 | 
			
		||||
        $streamProphecy = $this->prophesize(StreamInterface::class);
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy
 | 
			
		||||
            ->getMetadata($argKey)
 | 
			
		||||
            ->willReturn($returnValue)
 | 
			
		||||
            ->shouldBeCalled();
 | 
			
		||||
 | 
			
		||||
        /** @var StreamInterface $stream */
 | 
			
		||||
        $stream = $streamProphecy->reveal();
 | 
			
		||||
 | 
			
		||||
        return $stream;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateUploadedFileWithInvalidUri()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('File is not readable.');
 | 
			
		||||
 | 
			
		||||
        // Prophesize a `\Psr\Http\Message\StreamInterface` with a `getMetadata` method prophecy.
 | 
			
		||||
        $streamProphecy = $this->prophesize(StreamInterface::class);
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy
 | 
			
		||||
            ->getMetadata('uri')
 | 
			
		||||
            ->willReturn(null)
 | 
			
		||||
            ->shouldBeCalled();
 | 
			
		||||
 | 
			
		||||
        /** @var StreamInterface $stream */
 | 
			
		||||
        $stream = $streamProphecy->reveal();
 | 
			
		||||
 | 
			
		||||
        $this->factory->createUploadedFile($stream);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateUploadedFileWithNonReadableFile()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('File is not readable.');
 | 
			
		||||
 | 
			
		||||
        // Prophesize a `\Psr\Http\Message\StreamInterface` with a `getMetadata` and `isReadable` method prophecies.
 | 
			
		||||
        $streamProphecy = $this->prophesize(StreamInterface::class);
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy
 | 
			
		||||
            ->getMetadata('uri')
 | 
			
		||||
            ->willReturn('non-readable')
 | 
			
		||||
            ->shouldBeCalled();
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy
 | 
			
		||||
            ->isReadable()
 | 
			
		||||
            ->willReturn(false)
 | 
			
		||||
            ->shouldBeCalled();
 | 
			
		||||
 | 
			
		||||
        /** @var StreamInterface $stream */
 | 
			
		||||
        $stream = $streamProphecy->reveal();
 | 
			
		||||
 | 
			
		||||
        $this->factory->createUploadedFile($stream);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										243
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/UriFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										243
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/UriFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,243 @@
 | 
			
		||||
<?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 Interop\Http\Factory\UriFactoryTestCase;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
 | 
			
		||||
class UriFactoryTest extends UriFactoryTestCase
 | 
			
		||||
{
 | 
			
		||||
    protected function createUriFactory(): UriFactory
 | 
			
		||||
    {
 | 
			
		||||
        return new UriFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAuthorityWithUsername()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://josh@example.com/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh@example.com', $uri->getAuthority());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAuthority()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://example.com/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getAuthority());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAuthorityWithNonStandardPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://example.com:400/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('example.com:400', $uri->getAuthority());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetUserInfoWithUsernameAndPassword()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://josh:sekrit@example.com:443/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh:sekrit', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetUserInfoWithUsernameAndPasswordEncodesCorrectly()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this
 | 
			
		||||
            ->createUriFactory()
 | 
			
		||||
            ->createUri('https://bob@example.com:pass:word@example.com:443/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bob%40example.com:pass%3Aword', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetUserInfoWithUsername()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('http://josh@example.com/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetUserInfoNone()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://example.com/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromString()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://example.com:8080/foo/bar?abc=123');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('https', $uri->getScheme());
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getHost());
 | 
			
		||||
        $this->assertEquals('8080', $uri->getPort());
 | 
			
		||||
        $this->assertEquals('/foo/bar', $uri->getPath());
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobals()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => '/index.php',
 | 
			
		||||
            'REQUEST_URI' => '/foo/bar?baz=1',
 | 
			
		||||
            'PHP_AUTH_USER' => 'josh',
 | 
			
		||||
            'PHP_AUTH_PW' => 'sekrit',
 | 
			
		||||
            'QUERY_STRING' => 'abc=123',
 | 
			
		||||
            'HTTP_HOST' => 'example.com:8080',
 | 
			
		||||
            'SERVER_PORT' => 8080,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh:sekrit', $uri->getUserInfo());
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getHost());
 | 
			
		||||
        $this->assertEquals('8080', $uri->getPort());
 | 
			
		||||
        $this->assertEquals('/foo/bar', $uri->getPath());
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
        $this->assertEquals('', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithHttps()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock(
 | 
			
		||||
            [
 | 
			
		||||
                'HTTPS' => 'on',
 | 
			
		||||
                'HTTP_HOST' => 'example.com'
 | 
			
		||||
            ]
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        // Make the 'SERVER_PORT' empty as we want to test if the default server port gets set correctly.
 | 
			
		||||
        $globals['SERVER_PORT'] = '';
 | 
			
		||||
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('https', $uri->getScheme());
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getHost());
 | 
			
		||||
 | 
			
		||||
        // The port is expected to be NULL as the server port is the default standard (443 in case of https).
 | 
			
		||||
        $this->assertNull($uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsUsesServerNameAsHostIfHostHeaderIsNotPresent()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock([
 | 
			
		||||
            'SERVER_NAME' => 'example.com',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getHost());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalWithIPv6HostNoPort()
 | 
			
		||||
    {
 | 
			
		||||
        $environment = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => '/index.php',
 | 
			
		||||
            'REQUEST_URI' => '/foo/bar',
 | 
			
		||||
            'PHP_AUTH_USER' => 'josh',
 | 
			
		||||
            'PHP_AUTH_PW' => 'sekrit',
 | 
			
		||||
            'QUERY_STRING' => 'abc=123',
 | 
			
		||||
            'HTTP_HOST' => '[2001:db8::1]',
 | 
			
		||||
            'REMOTE_ADDR' => '2001:db8::1',
 | 
			
		||||
            'SERVER_PORT' => 8080,
 | 
			
		||||
        ]);
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($environment);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh:sekrit', $uri->getUserInfo());
 | 
			
		||||
        $this->assertEquals('[2001:db8::1]', $uri->getHost());
 | 
			
		||||
        $this->assertEquals('8080', $uri->getPort());
 | 
			
		||||
        $this->assertEquals('/foo/bar', $uri->getPath());
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
        $this->assertEquals('', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithIPv6HostWithPort()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => '/index.php',
 | 
			
		||||
            'REQUEST_URI' => '/foo/bar',
 | 
			
		||||
            'PHP_AUTH_USER' => 'josh',
 | 
			
		||||
            'PHP_AUTH_PW' => 'sekrit',
 | 
			
		||||
            'QUERY_STRING' => 'abc=123',
 | 
			
		||||
            'HTTP_HOST' => '[2001:db8::1]:8080',
 | 
			
		||||
            'REMOTE_ADDR' => '2001:db8::1',
 | 
			
		||||
            'SERVER_PORT' => 8080,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh:sekrit', $uri->getUserInfo());
 | 
			
		||||
        $this->assertEquals('[2001:db8::1]', $uri->getHost());
 | 
			
		||||
        $this->assertEquals('8080', $uri->getPort());
 | 
			
		||||
        $this->assertEquals('/foo/bar', $uri->getPath());
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
        $this->assertEquals('', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithBasePathContainingSpace()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => "/f'oo bar/index.php",
 | 
			
		||||
            'REQUEST_URI' => "/f%27oo%20bar/baz",
 | 
			
		||||
        ]);
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/f%27oo%20bar/baz', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathWhenBaseRootIsEmpty()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => '/index.php',
 | 
			
		||||
            'REQUEST_URI' => '/bar',
 | 
			
		||||
        ]);
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('http://localhost/test', (string) $uri->withPath('test'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * When the URL is /foo/index.php/bar/baz, we need the baseURL to be
 | 
			
		||||
     * /foo/index.php so that routing works correctly.
 | 
			
		||||
     *
 | 
			
		||||
     * @ticket 1639 as a fix to 1590 broke this.
 | 
			
		||||
     */
 | 
			
		||||
    public function testRequestURIContainsIndexDotPhp()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals(
 | 
			
		||||
            Environment::mock(
 | 
			
		||||
                [
 | 
			
		||||
                    'SCRIPT_NAME' => '/foo/index.php',
 | 
			
		||||
                    'REQUEST_URI' => '/foo/index.php/bar/baz',
 | 
			
		||||
                ]
 | 
			
		||||
            )
 | 
			
		||||
        );
 | 
			
		||||
        $this->assertSame('/foo/index.php/bar/baz', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRequestURICanContainParams()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals(
 | 
			
		||||
            Environment::mock(
 | 
			
		||||
                [
 | 
			
		||||
                    'REQUEST_URI' => '/foo?abc=123',
 | 
			
		||||
                ]
 | 
			
		||||
            )
 | 
			
		||||
        );
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testUriDistinguishZeroFromEmptyString()
 | 
			
		||||
    {
 | 
			
		||||
        $expected = 'https://0:0@0:1/0?0#0';
 | 
			
		||||
        $this->assertSame($expected, (string) $this->createUriFactory()->createUri($expected));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										61
									
								
								qwen/php/vendor/slim/psr7/tests/HeaderTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								qwen/php/vendor/slim/psr7/tests/HeaderTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Slim\Psr7\Header;
 | 
			
		||||
 | 
			
		||||
class HeaderTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Instantiate a default header.
 | 
			
		||||
     *
 | 
			
		||||
     * @return Header
 | 
			
		||||
     */
 | 
			
		||||
    protected function headerFactory(): Header
 | 
			
		||||
    {
 | 
			
		||||
        $originalName = 'ACCEPT';
 | 
			
		||||
        $normalizedName = 'accept';
 | 
			
		||||
        $values = ['application/json'];
 | 
			
		||||
 | 
			
		||||
        return new Header($originalName, $normalizedName, $values);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetOriginalName(): void
 | 
			
		||||
    {
 | 
			
		||||
        $header = $this->headerFactory();
 | 
			
		||||
        $this->assertEquals('ACCEPT', $header->getOriginalName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetNormalizedName(): void
 | 
			
		||||
    {
 | 
			
		||||
        $header = $this->headerFactory();
 | 
			
		||||
        $this->assertEquals('accept', $header->getNormalizedName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAddValue(): void
 | 
			
		||||
    {
 | 
			
		||||
        $header = $this->headerFactory();
 | 
			
		||||
        $header2 = $header->addValue('text/html');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $header->getValues());
 | 
			
		||||
        $this->assertSame($header2, $header);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAddValuesString(): void
 | 
			
		||||
    {
 | 
			
		||||
        $header = $this->headerFactory();
 | 
			
		||||
        $header2 = $header->addValues('text/html');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $header->getValues());
 | 
			
		||||
        $this->assertSame($header2, $header);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										288
									
								
								qwen/php/vendor/slim/psr7/tests/HeadersTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										288
									
								
								qwen/php/vendor/slim/psr7/tests/HeadersTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,288 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
use function base64_encode;
 | 
			
		||||
 | 
			
		||||
class HeadersTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testCreateFromGlobals()
 | 
			
		||||
    {
 | 
			
		||||
        $GLOBALS['getallheaders_return'] = [
 | 
			
		||||
            'HTTP_ACCEPT' => 'application/json',
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $headers = Headers::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        unset($GLOBALS['getallheaders_return']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['accept' => ['application/json']], $headers->getHeaders());
 | 
			
		||||
        $this->assertEquals(['ACCEPT' => ['application/json']], $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsUsesEmptyArrayIfGetAllHeadersReturnsFalse()
 | 
			
		||||
    {
 | 
			
		||||
        $GLOBALS['getallheaders_return'] = false;
 | 
			
		||||
 | 
			
		||||
        $headers = Headers::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        unset($GLOBALS['getallheaders_return']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals([], $headers->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAddHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Accept' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $headers->addHeader('Accept', 'text/html');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $headers->getHeader('Accept'));
 | 
			
		||||
        $this->assertEquals(['accept' => ['application/json', 'text/html']], $headers->getHeaders());
 | 
			
		||||
        $this->assertEquals(['Accept' => ['application/json', 'text/html']], $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAddHeaderValueEmptyArray()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('Header', []);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRemoveHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Accept' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $headers->removeHeader('Accept');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals([], $headers->getHeader('Accept'));
 | 
			
		||||
        $this->assertEquals([], $headers->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @doesNotPerformAssertions
 | 
			
		||||
     */
 | 
			
		||||
    public function testRemoveHeaderByIncompatibleStringWithRFC()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->removeHeader('<incompatible with RFC>');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Accept' => ['application/json', 'text/html'],
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $headers->getHeader('accept'));
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $headers->getHeader('Accept'));
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $headers->getHeader('HTTP_ACCEPT'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeaderReturnsValidatedAndTrimedHeaderDefaultValue()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['application/json'], $headers->getHeader('accept', ' application/json'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeaderThrowsExceptionWithInvalidDefaultArgument()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers([]);
 | 
			
		||||
 | 
			
		||||
        $headers->getHeader('accept', new stdClass());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Content-Length' => 0,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $headers->setHeader('Content-Length', 100);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame(['100'], $headers->getHeader('Content-Length'));
 | 
			
		||||
        $this->assertEquals(['content-length' => ['100']], $headers->getHeaders());
 | 
			
		||||
        $this->assertEquals(['Content-Length' => ['100']], $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetHeaderPreservesOriginalCaseIfHeaderAlreadyExists()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'CONTENT-LENGTH' => 0,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $headers->setHeader('Content-Length', 100);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['content-length' => ['100']], $headers->getHeaders());
 | 
			
		||||
        $this->assertEquals(['CONTENT-LENGTH' => ['100']], $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetHeaders()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Content-Length' => 0,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $headers->setHeaders([
 | 
			
		||||
            'Accept' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['accept' => ['application/json']], $headers->getHeaders());
 | 
			
		||||
        $this->assertEquals(['Accept' => ['application/json']], $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHasHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Accept' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($headers->hasHeader('accept'));
 | 
			
		||||
        $this->assertTrue($headers->hasHeader('Accept'));
 | 
			
		||||
        $this->assertTrue($headers->hasHeader('HTTP_ACCEPT'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeaders()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'HTTP_ACCEPT' => 'text/html',
 | 
			
		||||
            'HTTP_CONTENT_TYPE' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $expectedNormalizedHeaders = [
 | 
			
		||||
            'accept' => ['text/html'],
 | 
			
		||||
            'content-type' => ['application/json'],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedNormalizedHeaders, $headers->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeadersPreservesOriginalCase()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'HTTP_ACCEPT' => 'text/html',
 | 
			
		||||
            'HTTP_CONTENT_TYPE' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $expectedOriginalHeaders = [
 | 
			
		||||
            'ACCEPT' => ['text/html'],
 | 
			
		||||
            'CONTENT-TYPE' => ['application/json'],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedOriginalHeaders, $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testParseAuthorizationHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $expectedValue = 'Basic ' . base64_encode('user:password');
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers(['Authorization' => $expectedValue]);
 | 
			
		||||
        $this->assertEquals([$expectedValue], $headers->getHeader('Authorization'));
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers([], ['REDIRECT_HTTP_AUTHORIZATION' => 'cookie']);
 | 
			
		||||
        $this->assertEquals(['cookie'], $headers->getHeader('Authorization'));
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers([], ['PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'password']);
 | 
			
		||||
        $this->assertEquals([$expectedValue], $headers->getHeader('Authorization'));
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers([], ['PHP_AUTH_DIGEST' => 'digest']);
 | 
			
		||||
        $this->assertEquals(['digest'], $headers->getHeader('Authorization'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider provideInvalidHeaderNames
 | 
			
		||||
     */
 | 
			
		||||
    public function testWithInvalidHeaderName($headerName): void
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
 | 
			
		||||
        $this->expectException(\InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $headers->setHeader($headerName, 'foo');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function provideInvalidHeaderNames(): array
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            [[]],
 | 
			
		||||
            [false],
 | 
			
		||||
            [new \stdClass()],
 | 
			
		||||
            ["Content-Type\r\n\r\n"],
 | 
			
		||||
            ["Content-Type\r\n"],
 | 
			
		||||
            ["Content-Type\n"],
 | 
			
		||||
            ["\r\nContent-Type"],
 | 
			
		||||
            ["\nContent-Type"],
 | 
			
		||||
            ["\n"],
 | 
			
		||||
            ["\r\n"],
 | 
			
		||||
            ["\t"],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider provideInvalidHeaderValues
 | 
			
		||||
     */
 | 
			
		||||
    public function testSetInvalidHeaderValue($headerValue)
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
 | 
			
		||||
        $this->expectException(\InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $headers->setHeader('Content-Type', $headerValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function provideInvalidHeaderValues(): array
 | 
			
		||||
    {
 | 
			
		||||
        // Explicit tests for newlines as the most common exploit vector.
 | 
			
		||||
        $tests = [
 | 
			
		||||
            ["new\nline"],
 | 
			
		||||
            ["new\r\nline"],
 | 
			
		||||
            ["new\rline"],
 | 
			
		||||
            ["new\r\n line"],
 | 
			
		||||
            ["newline\n"],
 | 
			
		||||
            ["\nnewline"],
 | 
			
		||||
            ["newline\r\n"],
 | 
			
		||||
            ["\n\rnewline"],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        for ($i = 0; $i <= 0xff; $i++) {
 | 
			
		||||
            if (\chr($i) == "\t") {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            if (\chr($i) == " ") {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            if ($i >= 0x21 && $i <= 0x7e) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            if ($i >= 0x80) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $tests[] = ["foo" . \chr($i) . "bar"];
 | 
			
		||||
            $tests[] = ["foo" . \chr($i)];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $tests;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										57
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/BaseTestFactories.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/BaseTestFactories.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
			
		||||
<?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 Psr\Http\Message\UriInterface;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function is_resource;
 | 
			
		||||
 | 
			
		||||
trait BaseTestFactories
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $uri
 | 
			
		||||
     * @return UriInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected function buildUri($uri): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        return (new UriFactory())->createUri($uri);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param $data
 | 
			
		||||
     * @return Stream
 | 
			
		||||
     */
 | 
			
		||||
    protected function buildStream($data): Stream
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_resource($data)) {
 | 
			
		||||
            $h = fopen('php://temp', 'w+');
 | 
			
		||||
            fwrite($h, $data);
 | 
			
		||||
 | 
			
		||||
            $data = $h;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new Stream($data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param $data
 | 
			
		||||
     * @return UploadedFile
 | 
			
		||||
     */
 | 
			
		||||
    protected function buildUploadableFile($data): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        return new UploadedFile($this->buildStream($data));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										36
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/RequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/RequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
<?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 Http\Psr7Test\RequestIntegrationTest;
 | 
			
		||||
use Psr\Http\Message\RequestInterface;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Request;
 | 
			
		||||
 | 
			
		||||
class RequestTest extends RequestIntegrationTest
 | 
			
		||||
{
 | 
			
		||||
    use BaseTestFactories;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return RequestInterface that is used in the tests
 | 
			
		||||
     */
 | 
			
		||||
    public function createSubject(): RequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        return new Request(
 | 
			
		||||
            'GET',
 | 
			
		||||
            $this->buildUri('/'),
 | 
			
		||||
            new Headers(),
 | 
			
		||||
            [],
 | 
			
		||||
            [],
 | 
			
		||||
            $this->buildStream('')
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										27
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/ResponseTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/ResponseTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
<?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 Http\Psr7Test\ResponseIntegrationTest;
 | 
			
		||||
use Slim\Psr7\Response;
 | 
			
		||||
 | 
			
		||||
class ResponseTest extends ResponseIntegrationTest
 | 
			
		||||
{
 | 
			
		||||
    use BaseTestFactories;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Response that is used in the tests
 | 
			
		||||
     */
 | 
			
		||||
    public function createSubject(): Response
 | 
			
		||||
    {
 | 
			
		||||
        return new Response();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/ServerRequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/ServerRequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
<?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 Http\Psr7Test\ServerRequestIntegrationTest;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Request;
 | 
			
		||||
 | 
			
		||||
class ServerRequestTest extends ServerRequestIntegrationTest
 | 
			
		||||
{
 | 
			
		||||
    use BaseTestFactories;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Request
 | 
			
		||||
     */
 | 
			
		||||
    public function createSubject(): Request
 | 
			
		||||
    {
 | 
			
		||||
        return new Request(
 | 
			
		||||
            'GET',
 | 
			
		||||
            $this->buildUri('/'),
 | 
			
		||||
            new Headers(),
 | 
			
		||||
            $_COOKIE,
 | 
			
		||||
            $_SERVER,
 | 
			
		||||
            $this->buildStream('')
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										46
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/StreamTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/StreamTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
<?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 Http\Psr7Test\StreamIntegrationTest;
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function is_resource;
 | 
			
		||||
use function is_string;
 | 
			
		||||
 | 
			
		||||
class StreamTest extends StreamIntegrationTest
 | 
			
		||||
{
 | 
			
		||||
    use BaseTestFactories;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string|resource|StreamInterface $data
 | 
			
		||||
     *
 | 
			
		||||
     * @return StreamInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function createStream($data)
 | 
			
		||||
    {
 | 
			
		||||
        if ($data instanceof StreamInterface) {
 | 
			
		||||
            return $data;
 | 
			
		||||
        } elseif (is_resource($data)) {
 | 
			
		||||
            return new Stream($data);
 | 
			
		||||
        } elseif (is_string($data)) {
 | 
			
		||||
            $s = fopen('php://temp', 'w+');
 | 
			
		||||
            fwrite($s, $data);
 | 
			
		||||
            return new Stream($s);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        throw new InvalidArgumentException();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										51
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/UploadedFileTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/UploadedFileTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
<?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 Http\Psr7Test\UploadedFileIntegrationTest;
 | 
			
		||||
use Psr\Http\Message\UploadedFileInterface;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
 | 
			
		||||
use function sys_get_temp_dir;
 | 
			
		||||
use function tempnam;
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/UriTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/UriTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
<?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 Http\Psr7Test\UriIntegrationTest;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
 | 
			
		||||
class UriTest extends UriIntegrationTest
 | 
			
		||||
{
 | 
			
		||||
    use BaseTestFactories;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $uri
 | 
			
		||||
     *
 | 
			
		||||
     * @return UriInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function createUri($uri): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        return (new UriFactory())->createUri($uri);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										186
									
								
								qwen/php/vendor/slim/psr7/tests/MessageTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										186
									
								
								qwen/php/vendor/slim/psr7/tests/MessageTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,186 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\MockObject\MockObject;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
use Slim\Tests\Psr7\Mocks\MessageStub;
 | 
			
		||||
 | 
			
		||||
class MessageTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testGetProtocolVersion()
 | 
			
		||||
    {
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->protocolVersion = '1.0';
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('1.0', $message->getProtocolVersion());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithProtocolVersion()
 | 
			
		||||
    {
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $clone = $message->withProtocolVersion('1.0');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('1.0', $clone->protocolVersion);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithProtocolVersionInvalidThrowsException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->withProtocolVersion('3.0');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeaders()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'two');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'three');
 | 
			
		||||
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
 | 
			
		||||
        $shouldBe = [
 | 
			
		||||
            'X-Foo' => [
 | 
			
		||||
                'one',
 | 
			
		||||
                'two',
 | 
			
		||||
                'three',
 | 
			
		||||
            ],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($shouldBe, $message->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHasHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($message->hasHeader('X-Foo'));
 | 
			
		||||
        $this->assertFalse($message->hasHeader('X-Bar'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeaderLine()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'two');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'three');
 | 
			
		||||
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('one,two,three', $message->getHeaderLine('X-Foo'));
 | 
			
		||||
        $this->assertEquals('', $message->getHeaderLine('X-Bar'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'two');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'three');
 | 
			
		||||
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['one', 'two', 'three'], $message->getHeader('X-Foo'));
 | 
			
		||||
        $this->assertEquals([], $message->getHeader('X-Bar'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
        $clone = $message->withHeader('X-Foo', 'bar');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bar', $clone->getHeaderLine('X-Foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithAddedHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
        $clone = $message->withAddedHeader('X-Foo', 'two');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('one,two', $clone->getHeaderLine('X-Foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithoutHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $headers->addHeader('X-Bar', 'two');
 | 
			
		||||
        $response = new MessageStub();
 | 
			
		||||
        $response->headers = $headers;
 | 
			
		||||
        $clone = $response->withoutHeader('X-Foo');
 | 
			
		||||
        $shouldBe = [
 | 
			
		||||
            'X-Bar' => ['two'],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($shouldBe, $clone->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @doesNotPerformAssertions
 | 
			
		||||
     */
 | 
			
		||||
    public function testWithoutHeaderByIncompatibleStringWithRFC()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $response = new MessageStub();
 | 
			
		||||
        $response->headers = $headers;
 | 
			
		||||
        $response->withoutHeader('<incompatible with RFC');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetBody()
 | 
			
		||||
    {
 | 
			
		||||
        $body = $this->getBody();
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->body = $body;
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($body, $message->getBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithBody()
 | 
			
		||||
    {
 | 
			
		||||
        $body = $this->getBody();
 | 
			
		||||
        $body2 = $this->getBody();
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->body = $body;
 | 
			
		||||
        $clone = $message->withBody($body2);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($body, $message->body);
 | 
			
		||||
        $this->assertSame($body2, $clone->body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return MockObject|Stream
 | 
			
		||||
     */
 | 
			
		||||
    protected function getBody()
 | 
			
		||||
    {
 | 
			
		||||
        return $this
 | 
			
		||||
            ->getMockBuilder(Stream::class)
 | 
			
		||||
            ->disableOriginalConstructor()
 | 
			
		||||
            ->getMock();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										37
									
								
								qwen/php/vendor/slim/psr7/tests/Mocks/MessageStub.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								qwen/php/vendor/slim/psr7/tests/Mocks/MessageStub.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
<?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\Mocks;
 | 
			
		||||
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Slim\Psr7\Interfaces\HeadersInterface;
 | 
			
		||||
use Slim\Psr7\Message;
 | 
			
		||||
 | 
			
		||||
class MessageStub extends Message
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Protocol version
 | 
			
		||||
     */
 | 
			
		||||
    public string $protocolVersion;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Headers
 | 
			
		||||
     *
 | 
			
		||||
     * @var HeadersInterface
 | 
			
		||||
     */
 | 
			
		||||
    public $headers;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Body object
 | 
			
		||||
     *
 | 
			
		||||
     * @var StreamInterface
 | 
			
		||||
     */
 | 
			
		||||
    public $body;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										159
									
								
								qwen/php/vendor/slim/psr7/tests/NonBufferedBodyTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										159
									
								
								qwen/php/vendor/slim/psr7/tests/NonBufferedBodyTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,159 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\NonBufferedBody;
 | 
			
		||||
use Slim\Psr7\Response;
 | 
			
		||||
use Slim\Tests\Psr7\Assets\HeaderStack;
 | 
			
		||||
 | 
			
		||||
use function ob_get_clean;
 | 
			
		||||
use function ob_get_level;
 | 
			
		||||
use function ob_start;
 | 
			
		||||
use function strlen;
 | 
			
		||||
 | 
			
		||||
class NonBufferedBodyTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    protected function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        HeaderStack::reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        HeaderStack::reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testTheStreamContract()
 | 
			
		||||
    {
 | 
			
		||||
        $body = new NonBufferedBody();
 | 
			
		||||
        self::assertSame('', (string) $body, 'Casting to string returns no data, since the class does not store any');
 | 
			
		||||
        self::assertNull($body->detach(), 'Returns null since there is no such underlying stream');
 | 
			
		||||
        self::assertNull($body->getSize(), 'Current size is undefined');
 | 
			
		||||
        self::assertSame(0, $body->tell(), 'Pointer is considered to be at position 0 to conform');
 | 
			
		||||
        self::assertTrue($body->eof(), 'Always considered to be at EOF');
 | 
			
		||||
        self::assertFalse($body->isSeekable(), 'Cannot seek');
 | 
			
		||||
        self::assertTrue($body->isWritable(), 'Body is writable');
 | 
			
		||||
        self::assertFalse($body->isReadable(), 'Body is not readable');
 | 
			
		||||
        self::assertSame('', $body->getContents(), 'Data cannot be retrieved once written');
 | 
			
		||||
        self::assertNull($body->getMetadata(), 'Metadata mechanism is not implemented');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWrite()
 | 
			
		||||
    {
 | 
			
		||||
        $ob_initial_level = ob_get_level();
 | 
			
		||||
 | 
			
		||||
        // Start output buffering.
 | 
			
		||||
        ob_start();
 | 
			
		||||
 | 
			
		||||
        // Start output buffering again to test the while-loop in the `write()`
 | 
			
		||||
        // method that calls `ob_get_clean()` as long as the ob level is bigger
 | 
			
		||||
        // than 0.
 | 
			
		||||
        ob_start();
 | 
			
		||||
        echo 'buffer content: ';
 | 
			
		||||
 | 
			
		||||
        // Set the ob level shift that should be applied in the `ob_get_level()`
 | 
			
		||||
        // function override. That way, the `write()` method would only flush
 | 
			
		||||
        // the second ob, not the first one. We will add the initial ob level
 | 
			
		||||
        // because phpunit may have started ob too.
 | 
			
		||||
        $GLOBALS['ob_get_level_shift'] = -($ob_initial_level + 1);
 | 
			
		||||
 | 
			
		||||
        $body = new NonBufferedBody();
 | 
			
		||||
        $length0 = $body->write('hello ');
 | 
			
		||||
        $length1 = $body->write('world');
 | 
			
		||||
 | 
			
		||||
        unset($GLOBALS['ob_get_level_shift']);
 | 
			
		||||
        $contents = ob_get_clean();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(strlen('buffer content: ') + strlen('hello '), $length0);
 | 
			
		||||
        $this->assertEquals(strlen('world'), $length1);
 | 
			
		||||
        $this->assertEquals('buffer content: hello world', $contents);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithHeader()
 | 
			
		||||
    {
 | 
			
		||||
        (new Response())
 | 
			
		||||
            ->withBody(new NonBufferedBody())
 | 
			
		||||
            ->withHeader('Foo', 'Bar');
 | 
			
		||||
 | 
			
		||||
        self::assertSame([
 | 
			
		||||
            [
 | 
			
		||||
                'header' => 'Foo: Bar',
 | 
			
		||||
                'replace' => true,
 | 
			
		||||
                'status_code' => null
 | 
			
		||||
            ]
 | 
			
		||||
        ], HeaderStack::stack());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithAddedHeader()
 | 
			
		||||
    {
 | 
			
		||||
        (new Response())
 | 
			
		||||
            ->withBody(new NonBufferedBody())
 | 
			
		||||
            ->withHeader('Foo', 'Bar')
 | 
			
		||||
            ->withAddedHeader('Foo', 'Baz');
 | 
			
		||||
 | 
			
		||||
        self::assertSame([
 | 
			
		||||
            [
 | 
			
		||||
                'header' => 'Foo: Bar',
 | 
			
		||||
                'replace' => true,
 | 
			
		||||
                'status_code' => null
 | 
			
		||||
            ],
 | 
			
		||||
            [
 | 
			
		||||
                'header' => 'Foo: Bar,Baz',
 | 
			
		||||
                'replace' => true,
 | 
			
		||||
                'status_code' => null
 | 
			
		||||
            ]
 | 
			
		||||
        ], HeaderStack::stack());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithoutHeader()
 | 
			
		||||
    {
 | 
			
		||||
        (new Response())
 | 
			
		||||
            ->withBody(new NonBufferedBody())
 | 
			
		||||
            ->withHeader('Foo', 'Bar')
 | 
			
		||||
            ->withoutHeader('Foo');
 | 
			
		||||
 | 
			
		||||
        self::assertSame([], HeaderStack::stack());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCloseThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('A NonBufferedBody is not closable.');
 | 
			
		||||
 | 
			
		||||
        (new NonBufferedBody())->close();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSeekThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('A NonBufferedBody is not seekable.');
 | 
			
		||||
 | 
			
		||||
        (new NonBufferedBody())->seek(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRewindThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('A NonBufferedBody is not rewindable.');
 | 
			
		||||
 | 
			
		||||
        (new NonBufferedBody())->rewind();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReadThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('A NonBufferedBody is not readable.');
 | 
			
		||||
 | 
			
		||||
        (new NonBufferedBody())->read(10);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										458
									
								
								qwen/php/vendor/slim/psr7/tests/RequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										458
									
								
								qwen/php/vendor/slim/psr7/tests/RequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,458 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
use Slim\Psr7\Factory\StreamFactory;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Request;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
use Slim\Psr7\Uri;
 | 
			
		||||
 | 
			
		||||
use function property_exists;
 | 
			
		||||
use function sprintf;
 | 
			
		||||
 | 
			
		||||
class RequestTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function requestFactory($envData = []): Request
 | 
			
		||||
    {
 | 
			
		||||
        $env = Environment::mock($envData);
 | 
			
		||||
 | 
			
		||||
        $uri = (new UriFactory())->createUri('https://example.com:443/foo/bar?abc=123');
 | 
			
		||||
        $headers = Headers::createFromGlobals($env);
 | 
			
		||||
        $cookies = [
 | 
			
		||||
            'user' => 'john',
 | 
			
		||||
            'id' => '123',
 | 
			
		||||
        ];
 | 
			
		||||
        $serverParams = $env;
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $uploadedFiles = UploadedFile::createFromGlobals($env);
 | 
			
		||||
        $request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body, $uploadedFiles);
 | 
			
		||||
 | 
			
		||||
        return $request;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDisableSetter()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $request->foo = 'bar';
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse(property_exists($request, 'foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAddsHostHeaderFromUri()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $this->assertEquals('example.com', $request->getHeaderLine('Host'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetMethod()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('GET', $this->requestFactory()->getMethod());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithMethod()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory()->withMethod('PUT');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('PUT', $request->getMethod());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithMethodCaseSensitive()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory()->withMethod('pOsT');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('pOsT', $request->getMethod());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithAllAllowedCharactersMethod()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory()->withMethod("!#$%&'*+.^_`|~09AZ-");
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals("!#$%&'*+.^_`|~09AZ-", $request->getMethod());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithMethodInvalid()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->requestFactory()->withMethod('B@R');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateRequestWithInvalidMethodString()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $uri = (new UriFactory())->createUri('https://example.com:443/foo/bar?abc=123');
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
 | 
			
		||||
        new Request('B@R', $uri, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateRequestWithInvalidMethodOther()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $uri = (new UriFactory())->createUri('https://example.com:443/foo/bar?abc=123');
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
 | 
			
		||||
        new Request(10, $uri, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetRequestTarget()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('/foo/bar?abc=123', $this->requestFactory()->getRequestTarget());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetRequestTargetAlreadySet()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'requestTarget');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, '/foo/bar?abc=123');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/foo/bar?abc=123', $request->getRequestTarget());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetRequestTargetIfNoUri()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'uri');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/', $request->getRequestTarget());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithRequestTarget()
 | 
			
		||||
    {
 | 
			
		||||
        $clone = $this->requestFactory()->withRequestTarget('/test?user=1');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/test?user=1', $clone->getRequestTarget());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithRequestTargetThatHasSpaces()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->requestFactory()->withRequestTarget('/test/m ore/stuff?user=1');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetUri()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = (new UriFactory())->createUri('https://example.com:443/foo/bar?abc=123');
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($uri, $request->getUri());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUri()
 | 
			
		||||
    {
 | 
			
		||||
        // Uris
 | 
			
		||||
        $uri1 = (new UriFactory())->createUri('https://example.com:443/foo/bar?abc=123');
 | 
			
		||||
        $uri2 = (new UriFactory())->createUri('https://example2.com:443/test?xyz=123');
 | 
			
		||||
 | 
			
		||||
        // Request
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $request = new Request('GET', $uri1, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
        $clone = $request->withUri($uri2);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($uri2, $clone->getUri());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUriPreservesHost()
 | 
			
		||||
    {
 | 
			
		||||
        // When `$preserveHost` is set to `true`, this method interacts with
 | 
			
		||||
        // the Host header in the following ways:
 | 
			
		||||
 | 
			
		||||
        // - If the Host header is missing or empty, and the new URI contains
 | 
			
		||||
        //   a host component, this method MUST update the Host header in the returned
 | 
			
		||||
        //   request.
 | 
			
		||||
        $uri1 = (new UriFactory())->createUri('');
 | 
			
		||||
        $uri2 = (new UriFactory())->createUri('http://example2.com/test');
 | 
			
		||||
 | 
			
		||||
        // Request
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $request = new Request('GET', $uri1, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
 | 
			
		||||
        $clone = $request->withUri($uri2, true);
 | 
			
		||||
        $this->assertSame('example2.com', $clone->getHeaderLine('Host'));
 | 
			
		||||
 | 
			
		||||
        // - If the Host header is missing or empty, and the new URI does not contain a
 | 
			
		||||
        //   host component, this method MUST NOT update the Host header in the returned
 | 
			
		||||
        //   request.
 | 
			
		||||
        $uri3 = (new UriFactory())->createUri('');
 | 
			
		||||
 | 
			
		||||
        $clone = $request->withUri($uri3, true);
 | 
			
		||||
        $this->assertSame('', $clone->getHeaderLine('Host'));
 | 
			
		||||
 | 
			
		||||
        // - If a Host header is present and non-empty, this method MUST NOT update
 | 
			
		||||
        //   the Host header in the returned request.
 | 
			
		||||
        $request = $request->withHeader('Host', 'example.com');
 | 
			
		||||
        $clone = $request->withUri($uri2, true);
 | 
			
		||||
        $this->assertSame('example.com', $clone->getHeaderLine('Host'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetCookieParams()
 | 
			
		||||
    {
 | 
			
		||||
        $shouldBe = [
 | 
			
		||||
            'user' => 'john',
 | 
			
		||||
            'id' => '123',
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($shouldBe, $this->requestFactory()->getCookieParams());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithCookieParams()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $clone = $request->withCookieParams(['type' => 'framework']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['type' => 'framework'], $clone->getCookieParams());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetQueryParams()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals(['abc' => '123'], $this->requestFactory()->getQueryParams());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetQueryParamsAlreadySet()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'queryParams');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['foo' => 'bar'], $request->getQueryParams());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryParams()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $clone = $request->withQueryParams(['foo' => 'bar']);
 | 
			
		||||
        $cloneUri = $clone->getUri();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('abc=123', $cloneUri->getQuery()); // <-- Unchanged
 | 
			
		||||
        $this->assertEquals(['foo' => 'bar'], $clone->getQueryParams()); // <-- Changed
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryParamsEmptyArray()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $clone = $request->withQueryParams([]);
 | 
			
		||||
        $cloneUri = $clone->getUri();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('abc=123', $cloneUri->getQuery()); // <-- Unchanged
 | 
			
		||||
        $this->assertEquals([], $clone->getQueryParams()); // <-- Changed
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetQueryParamsWithoutUri()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'uri');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals([], $request->getQueryParams());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUploadedFiles()
 | 
			
		||||
    {
 | 
			
		||||
        $files = [new UploadedFile('foo.txt'), new UploadedFile('bar.txt')];
 | 
			
		||||
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prevUploaded = $request->getUploadedFiles();
 | 
			
		||||
        $clone = $request->withUploadedFiles($files);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($prevUploaded, $request->getUploadedFiles());
 | 
			
		||||
        $this->assertEquals($files, $clone->getUploadedFiles());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetServerParams()
 | 
			
		||||
    {
 | 
			
		||||
        $mockEnv = Environment::mock(["HTTP_AUTHORIZATION" => "test"]);
 | 
			
		||||
        $request = $this->requestFactory(["HTTP_AUTHORIZATION" => "test"]);
 | 
			
		||||
 | 
			
		||||
        $serverParams = $request->getServerParams();
 | 
			
		||||
        foreach ($serverParams as $key => $value) {
 | 
			
		||||
            if ($key == 'REQUEST_TIME' || $key == 'REQUEST_TIME_FLOAT') {
 | 
			
		||||
                $this->assertGreaterThanOrEqual(
 | 
			
		||||
                    $mockEnv[$key],
 | 
			
		||||
                    $value,
 | 
			
		||||
                    sprintf("%s value of %s was less than expected value of %s", $key, $value, $mockEnv[$key])
 | 
			
		||||
                );
 | 
			
		||||
            } else {
 | 
			
		||||
                $this->assertEquals(
 | 
			
		||||
                    $mockEnv[$key],
 | 
			
		||||
                    $value,
 | 
			
		||||
                    sprintf("%s value of %s did not equal expected value of %s", $key, $value, $mockEnv[$key])
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAttributes()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $attrProp = new ReflectionProperty($request, 'attributes');
 | 
			
		||||
        $attrProp->setAccessible(true);
 | 
			
		||||
        $attrProp->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['foo' => 'bar'], $request->getAttributes());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAttribute()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $attrProp = new ReflectionProperty($request, 'attributes');
 | 
			
		||||
        $attrProp->setAccessible(true);
 | 
			
		||||
        $attrProp->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bar', $request->getAttribute('foo'));
 | 
			
		||||
        $this->assertNull($request->getAttribute('bar'));
 | 
			
		||||
        $this->assertEquals(2, $request->getAttribute('bar', 2));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithAttribute()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $attrProp = new ReflectionProperty($request, 'attributes');
 | 
			
		||||
        $attrProp->setAccessible(true);
 | 
			
		||||
        $attrProp->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
        $clone = $request->withAttribute('test', '123');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('123', $clone->getAttribute('test'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithoutAttribute()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $attrProp = new ReflectionProperty($request, 'attributes');
 | 
			
		||||
        $attrProp->setAccessible(true);
 | 
			
		||||
        $attrProp->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
        $clone = $request->withoutAttribute('foo');
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($clone->getAttribute('foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetParsedBodyWhenAlreadyParsed()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'parsedBody');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['foo' => 'bar'], $request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetParsedBodyWhenBodyDoesNotExist()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'body');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithParsedBody()
 | 
			
		||||
    {
 | 
			
		||||
        $clone = $this->requestFactory()->withParsedBody(['xyz' => '123']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['xyz' => '123'], $clone->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithParsedBodyEmptyArray()
 | 
			
		||||
    {
 | 
			
		||||
        $method = 'GET';
 | 
			
		||||
        $uri = new Uri('https', 'example.com', 443, '/foo/bar', 'abc=123', '', '');
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->setHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf8');
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $body->write('foo=bar');
 | 
			
		||||
        $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
 | 
			
		||||
        $clone = $request->withParsedBody([]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals([], $clone->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithParsedBodyNull()
 | 
			
		||||
    {
 | 
			
		||||
        $method = 'GET';
 | 
			
		||||
        $uri = new Uri('https', 'example.com', 443, '/foo/bar', 'abc=123', '', '');
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->setHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf8');
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $body->write('foo=bar');
 | 
			
		||||
        $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
 | 
			
		||||
        $clone = $request->withParsedBody(null);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($clone->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetParsedBodyReturnsNullWhenThereIsNoBodyData()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory(['REQUEST_METHOD' => 'POST']);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetParsedBodyReturnsNullWhenThereIsNoMediaTypeParserRegistered()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory([
 | 
			
		||||
            'REQUEST_METHOD' => 'POST',
 | 
			
		||||
            'CONTENT_TYPE' => 'text/csv',
 | 
			
		||||
        ]);
 | 
			
		||||
        $request->getBody()->write('foo,bar,baz');
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithParsedBodyInvalid()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->requestFactory()->withParsedBody(2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithParsedBodyInvalidFalseValue()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->requestFactory()->withParsedBody(false);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										191
									
								
								qwen/php/vendor/slim/psr7/tests/ResponseTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										191
									
								
								qwen/php/vendor/slim/psr7/tests/ResponseTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,191 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Response;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function property_exists;
 | 
			
		||||
 | 
			
		||||
class ResponseTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testConstructorWithDefaultArgs()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
 | 
			
		||||
        $headersReflection = new ReflectionProperty($response, 'headers');
 | 
			
		||||
        $headersReflection->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodyReflection = new ReflectionProperty($response, 'body');
 | 
			
		||||
        $bodyReflection->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(200, $response->getStatusCode());
 | 
			
		||||
        $this->assertInstanceOf(Headers::class, $headersReflection->getValue($response));
 | 
			
		||||
        $this->assertInstanceOf(Stream::class, $bodyReflection->getValue($response));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructorWithCustomArgs()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $body = new Stream(fopen('php://temp', 'r+'));
 | 
			
		||||
        $response = new Response(404, $headers, $body);
 | 
			
		||||
 | 
			
		||||
        $headersReflection = new ReflectionProperty($response, 'headers');
 | 
			
		||||
        $headersReflection->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodyReflection = new ReflectionProperty($response, 'body');
 | 
			
		||||
        $bodyReflection->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(404, $response->getStatusCode());
 | 
			
		||||
        $this->assertSame($headers, $headersReflection->getValue($response));
 | 
			
		||||
        $this->assertSame($body, $bodyReflection->getValue($response));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDeepCopyClone()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $body = new Stream(fopen('php://temp', 'r+'));
 | 
			
		||||
        $response = new Response(404, $headers, $body);
 | 
			
		||||
        $clone = clone $response;
 | 
			
		||||
 | 
			
		||||
        $headersReflection = new ReflectionProperty($response, 'headers');
 | 
			
		||||
        $headersReflection->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(404, $clone->getStatusCode());
 | 
			
		||||
        $this->assertEquals('1.1', $clone->getProtocolVersion());
 | 
			
		||||
        $this->assertNotSame($headers, $headersReflection->getValue($clone));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDisableSetter()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response->foo = 'bar';
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse(property_exists($response, 'foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetStatusCode()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $responseStatus = new ReflectionProperty($response, 'status');
 | 
			
		||||
        $responseStatus->setAccessible(true);
 | 
			
		||||
        $responseStatus->setValue($response, 404);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(404, $response->getStatusCode());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithStatus()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $clone = $response->withStatus(302);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(302, $clone->getStatusCode());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithStatusInvalidStatusCodeThrowsException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response->withStatus(800);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithStatusInvalidReasonPhraseThrowsException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Response reason phrase must be a string');
 | 
			
		||||
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response->withStatus(200, null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithStatusEmptyReasonPhrase()
 | 
			
		||||
    {
 | 
			
		||||
        $responseWithNoMessage = new Response(310);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $responseWithNoMessage->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReasonPhraseContainsCarriageReturn()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Reason phrase contains one of the following prohibited characters: \r \n');
 | 
			
		||||
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response = $response->withStatus(404, "Not Found\r");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReasonPhraseContainsLineFeed()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Reason phrase contains one of the following prohibited characters: \r \n');
 | 
			
		||||
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response = $response->withStatus(404, "Not Found\n");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithStatusValidReasonPhraseObject()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response = $response->withStatus(200, new StringableTestObject('Slim OK'));
 | 
			
		||||
        $this->assertEquals('Slim OK', $response->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetReasonPhrase()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response(404);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('Not Found', $response->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testEmptyReasonPhraseForUnrecognisedCode()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response = $response->withStatus(199);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame('', $response->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetReasonPhraseForUnrecognisedCode()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response = $response->withStatus(199, 'Random Message');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('Random Message', $response->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetCustomReasonPhrase()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $clone = $response->withStatus(200, 'Custom Phrase');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('Custom Phrase', $clone->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testResponseHeadersDoNotContainAuthorizationHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $_SERVER = Environment::mock(
 | 
			
		||||
            [
 | 
			
		||||
                'PHP_AUTH_USER' => 'foo'
 | 
			
		||||
            ]
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $this->assertEmpty($response->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										284
									
								
								qwen/php/vendor/slim/psr7/tests/StreamTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										284
									
								
								qwen/php/vendor/slim/psr7/tests/StreamTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,284 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Prophecy\PhpUnit\ProphecyTrait;
 | 
			
		||||
use ReflectionException;
 | 
			
		||||
use ReflectionMethod;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function popen;
 | 
			
		||||
use function stream_get_contents;
 | 
			
		||||
use function trim;
 | 
			
		||||
 | 
			
		||||
class StreamTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    use ProphecyTrait;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var resource pipe stream file handle
 | 
			
		||||
     */
 | 
			
		||||
    private $pipeFh;
 | 
			
		||||
 | 
			
		||||
    private Stream $pipeStream;
 | 
			
		||||
 | 
			
		||||
    public function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->pipeFh != null) {
 | 
			
		||||
            // prevent broken pipe error message
 | 
			
		||||
            stream_get_contents($this->pipeFh);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsPipe()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($this->pipeStream->isPipe());
 | 
			
		||||
 | 
			
		||||
        $this->pipeStream->detach();
 | 
			
		||||
        $this->assertFalse($this->pipeStream->isPipe());
 | 
			
		||||
 | 
			
		||||
        $fhFile = fopen(__FILE__, 'r');
 | 
			
		||||
        $fileStream = new Stream($fhFile);
 | 
			
		||||
        $this->assertFalse($fileStream->isPipe());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsPipeReadable()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($this->pipeStream->isReadable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testPipeIsNotSeekable()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($this->pipeStream->isSeekable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCannotSeekPipe()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->pipeStream->seek(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCannotTellPipe()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->pipeStream->tell();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCannotRewindPipe()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->pipeStream->rewind();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testPipeGetSizeYieldsNull()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($this->pipeStream->getSize());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testClosePipe()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        // prevent broken pipe error message
 | 
			
		||||
        stream_get_contents($this->pipeFh);
 | 
			
		||||
 | 
			
		||||
        $this->pipeStream->close();
 | 
			
		||||
        $this->pipeFh = null;
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($this->pipeStream->isPipe());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testPipeToString()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
        $content = trim((string) $this->pipeStream);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame('12', $content);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConvertsToStringPartiallyReadNonSeekableStream()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
        $head = $this->pipeStream->read(1);
 | 
			
		||||
        $tail = trim((string) $this->pipeStream);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame('1', $head);
 | 
			
		||||
        $this->assertSame('2', $tail);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testPipeGetContents()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $contents = trim($this->pipeStream->getContents());
 | 
			
		||||
        $this->assertSame('12', $contents);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsWriteable()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'w');
 | 
			
		||||
        $stream = new Stream($resource);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(13, $stream->write('Hello, world!'));
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($stream->isWritable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsReadable()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'r');
 | 
			
		||||
        $stream = new Stream($resource);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($stream->isReadable());
 | 
			
		||||
        $this->assertFalse($stream->isWritable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsWritableAndReadable()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'w+');
 | 
			
		||||
        $stream = new Stream($resource);
 | 
			
		||||
 | 
			
		||||
        $stream->write('Hello, world!');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('Hello, world!', $stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($stream->isWritable());
 | 
			
		||||
        $this->assertTrue($stream->isReadable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Test that a call to the protected method `attach` would invoke `detach`.
 | 
			
		||||
     *
 | 
			
		||||
     * @throws ReflectionException
 | 
			
		||||
     */
 | 
			
		||||
    public function testAttachAgain()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $streamProphecy = $this->prophesize(Stream::class);
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy->detach()->shouldBeCalled();
 | 
			
		||||
 | 
			
		||||
        /** @var Stream $stream */
 | 
			
		||||
        $stream = $streamProphecy->reveal();
 | 
			
		||||
 | 
			
		||||
        $streamProperty = new ReflectionProperty(Stream::class, 'stream');
 | 
			
		||||
        $streamProperty->setAccessible(true);
 | 
			
		||||
        $streamProperty->setValue($stream, $this->pipeFh);
 | 
			
		||||
 | 
			
		||||
        $attachMethod = new ReflectionMethod(Stream::class, 'attach');
 | 
			
		||||
        $attachMethod->setAccessible(true);
 | 
			
		||||
        $attachMethod->invoke($stream, $this->pipeFh);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetMetaDataReturnsNullIfStreamIsDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'rw+');
 | 
			
		||||
        $stream = new Stream($resource);
 | 
			
		||||
        $stream->detach();
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($stream->getMetadata());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function openPipeStream()
 | 
			
		||||
    {
 | 
			
		||||
        $this->pipeFh = popen('echo 12', 'r');
 | 
			
		||||
        $this->pipeStream = new Stream($this->pipeFh);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReadOnlyCachedStreamsAreDisallowed()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'w+');
 | 
			
		||||
        $cache =  new Stream(fopen('php://temp', 'r'));
 | 
			
		||||
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Cache stream must be seekable and writable');
 | 
			
		||||
        new Stream($resource, $cache);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testNonSeekableCachedStreamsAreDisallowed()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'w+');
 | 
			
		||||
        $cache =  new Stream(fopen('php://output', 'w'));
 | 
			
		||||
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Cache stream must be seekable and writable');
 | 
			
		||||
 | 
			
		||||
        new Stream($resource, $cache);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCachedStreamsGetsContentFromTheCache()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = popen('echo HelloWorld', 'r');
 | 
			
		||||
        $stream = new Stream($resource, new Stream(fopen('php://temp', 'w+')));
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals("HelloWorld\n", $stream->getContents());
 | 
			
		||||
        $this->assertEquals("HelloWorld\n", $stream->getContents());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCachedStreamsFillsCacheOnRead()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('data://,0', 'r');
 | 
			
		||||
        $stream = new Stream($resource, new Stream(fopen('php://temp', 'w+')));
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals("0", $stream->read(100));
 | 
			
		||||
        $this->assertEquals("0", $stream->__toString());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDetachingStreamDropsCache()
 | 
			
		||||
    {
 | 
			
		||||
        $cache = new Stream(fopen('php://temp', 'w+'));
 | 
			
		||||
        $resource = fopen('data://,foo', 'r');
 | 
			
		||||
        $stream = new Stream($resource, $cache);
 | 
			
		||||
 | 
			
		||||
        $stream->detach();
 | 
			
		||||
 | 
			
		||||
        $cacheProperty = new ReflectionProperty(Stream::class, 'cache');
 | 
			
		||||
        $cacheProperty->setAccessible(true);
 | 
			
		||||
        $finishedProperty = new ReflectionProperty(Stream::class, 'finished');
 | 
			
		||||
        $finishedProperty->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($cacheProperty->getValue($stream));
 | 
			
		||||
        $this->assertFalse($finishedProperty->getValue($stream));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCachedStreamsRewindIfFinishedOnToString()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('data://,foo', 'r');
 | 
			
		||||
 | 
			
		||||
        $stream = new Stream($resource, new Stream(fopen('php://temp', 'w+')));
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('foo', (string)$stream);
 | 
			
		||||
        $this->assertEquals('foo', (string)$stream);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										23
									
								
								qwen/php/vendor/slim/psr7/tests/StringableTestObject.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								qwen/php/vendor/slim/psr7/tests/StringableTestObject.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
final class StringableTestObject implements \Stringable
 | 
			
		||||
{
 | 
			
		||||
    public function __construct(private string $value)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function __toString(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->value;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										676
									
								
								qwen/php/vendor/slim/psr7/tests/UploadedFileTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										676
									
								
								qwen/php/vendor/slim/psr7/tests/UploadedFileTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,676 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Prophecy\PhpUnit\ProphecyTrait;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Psr\Http\Message\UploadedFileInterface;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
use Slim\Psr7\Factory\StreamFactory;
 | 
			
		||||
use Slim\Psr7\Factory\UploadedFileFactory;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
 | 
			
		||||
use function call_user_func;
 | 
			
		||||
use function fclose;
 | 
			
		||||
use function file_exists;
 | 
			
		||||
use function file_get_contents;
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function microtime;
 | 
			
		||||
use function ob_get_clean;
 | 
			
		||||
use function ob_start;
 | 
			
		||||
use function strlen;
 | 
			
		||||
use function sys_get_temp_dir;
 | 
			
		||||
use function uniqid;
 | 
			
		||||
use function unlink;
 | 
			
		||||
use function version_compare;
 | 
			
		||||
 | 
			
		||||
use const DIRECTORY_SEPARATOR;
 | 
			
		||||
use const UPLOAD_ERR_CANT_WRITE;
 | 
			
		||||
use const UPLOAD_ERR_OK;
 | 
			
		||||
 | 
			
		||||
class UploadedFileTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    use ProphecyTrait;
 | 
			
		||||
 | 
			
		||||
    private static string $filename = './phpUxcOty';
 | 
			
		||||
 | 
			
		||||
    private static array $tmpFiles = ['./phpUxcOty'];
 | 
			
		||||
 | 
			
		||||
    public static function setUpBeforeClass(): void
 | 
			
		||||
    {
 | 
			
		||||
        $fh = fopen(self::$filename, "w");
 | 
			
		||||
        fwrite($fh, "12345678");
 | 
			
		||||
        fclose($fh);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function tearDownAfterClass(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (self::$tmpFiles as $filename) {
 | 
			
		||||
            if (file_exists($filename)) {
 | 
			
		||||
                unlink($filename);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        if (isset($GLOBALS['is_uploaded_file_return'])) {
 | 
			
		||||
            unset($GLOBALS['is_uploaded_file_return']);
 | 
			
		||||
        }
 | 
			
		||||
        if (isset($GLOBALS['copy_return'])) {
 | 
			
		||||
            unset($GLOBALS['copy_return']);
 | 
			
		||||
        }
 | 
			
		||||
        if (isset($GLOBALS['rename_return'])) {
 | 
			
		||||
            unset($GLOBALS['rename_return']);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generateNewTmpFile(): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        $filename = './php' . microtime();
 | 
			
		||||
 | 
			
		||||
        $fh = fopen($filename, "w");
 | 
			
		||||
        fwrite($fh, "12345678");
 | 
			
		||||
        fclose($fh);
 | 
			
		||||
 | 
			
		||||
        self::$tmpFiles[] = $filename;
 | 
			
		||||
 | 
			
		||||
        return new UploadedFile($filename);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array $input    The input array to parse.
 | 
			
		||||
     * @param array $expected The expected normalized output.
 | 
			
		||||
     *
 | 
			
		||||
     * @dataProvider providerCreateFromGlobals
 | 
			
		||||
     */
 | 
			
		||||
    public function testCreateFromGlobalsFromFilesSuperglobal(array $input, array $expected)
 | 
			
		||||
    {
 | 
			
		||||
        $_FILES = $input;
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = UploadedFile::createFromGlobals(Environment::mock());
 | 
			
		||||
        $this->assertEquals($expected, $uploadedFile);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array $input The input array to parse.
 | 
			
		||||
     *
 | 
			
		||||
     * @dataProvider providerCreateFromGlobals
 | 
			
		||||
     */
 | 
			
		||||
    public function testCreateFromGlobalsFromUserData(array $input)
 | 
			
		||||
    {
 | 
			
		||||
        //If slim.files provided - it will return what was provided
 | 
			
		||||
        $userData['slim.files'] = $input;
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = UploadedFile::createFromGlobals(Environment::mock($userData));
 | 
			
		||||
        $this->assertEquals($input, $uploadedFile);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithoutFile()
 | 
			
		||||
    {
 | 
			
		||||
        unset($_FILES);
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = UploadedFile::createFromGlobals(Environment::mock());
 | 
			
		||||
        $this->assertEquals([], $uploadedFile);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructor(): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        $attr = [
 | 
			
		||||
            'tmp_name' => self::$filename,
 | 
			
		||||
            'name' => 'my-avatar.txt',
 | 
			
		||||
            'size' => 8,
 | 
			
		||||
            'type' => 'text/plain',
 | 
			
		||||
            'error' => 0,
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = new UploadedFile(
 | 
			
		||||
            $attr['tmp_name'],
 | 
			
		||||
            $attr['name'],
 | 
			
		||||
            $attr['type'],
 | 
			
		||||
            $attr['size'],
 | 
			
		||||
            $attr['error'],
 | 
			
		||||
            false
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($attr['name'], $uploadedFile->getClientFilename());
 | 
			
		||||
        $this->assertEquals($attr['type'], $uploadedFile->getClientMediaType());
 | 
			
		||||
        $this->assertEquals($attr['size'], $uploadedFile->getSize());
 | 
			
		||||
        $this->assertEquals($attr['error'], $uploadedFile->getError());
 | 
			
		||||
        $this->assertEquals($attr['tmp_name'], $uploadedFile->getFilePath());
 | 
			
		||||
 | 
			
		||||
        return $uploadedFile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructorSapi(): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        $attr = [
 | 
			
		||||
            'tmp_name' => self::$filename,
 | 
			
		||||
            'name' => 'my-avatar.txt',
 | 
			
		||||
            'size' => 8,
 | 
			
		||||
            'type' => 'text/plain',
 | 
			
		||||
            'error' => 0,
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = new UploadedFile(
 | 
			
		||||
            $attr['tmp_name'],
 | 
			
		||||
            $attr['name'],
 | 
			
		||||
            $attr['type'],
 | 
			
		||||
            $attr['size'],
 | 
			
		||||
            $attr['error'],
 | 
			
		||||
            true
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($attr['name'], $uploadedFile->getClientFilename());
 | 
			
		||||
        $this->assertEquals($attr['type'], $uploadedFile->getClientMediaType());
 | 
			
		||||
        $this->assertEquals($attr['size'], $uploadedFile->getSize());
 | 
			
		||||
        $this->assertEquals($attr['error'], $uploadedFile->getError());
 | 
			
		||||
        $this->assertEquals($attr['tmp_name'], $uploadedFile->getFilePath());
 | 
			
		||||
 | 
			
		||||
        return $uploadedFile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testConstructor
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     * @return UploadedFile
 | 
			
		||||
     */
 | 
			
		||||
    public function testGetStream(UploadedFile $uploadedFile): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        $stream = $uploadedFile->getStream();
 | 
			
		||||
        $this->assertEquals(true, $uploadedFile->getStream() instanceof Stream);
 | 
			
		||||
        $stream->close();
 | 
			
		||||
 | 
			
		||||
        return $uploadedFile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testConstructor
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveToNotWritable(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = 'some_random_dir' . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testConstructor
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     * @return UploadedFile
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveTo(UploadedFile $uploadedFile): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
 | 
			
		||||
        $this->assertFileExists($path);
 | 
			
		||||
 | 
			
		||||
        unlink($path);
 | 
			
		||||
 | 
			
		||||
        return $uploadedFile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testMoveToRenameFailure()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessageMatches('/^Error moving uploaded file .* to .*$/');
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = $this->generateNewTmpFile();
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
 | 
			
		||||
        $GLOBALS['rename_return'] = false;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testConstructorSapi
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveToSapiNonUploadedFile(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testConstructorSapi
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveToSapiMoveUploadedFileFails(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessageMatches('~Error moving uploaded file.*~');
 | 
			
		||||
 | 
			
		||||
        $GLOBALS['is_uploaded_file_return'] = true;
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testMoveTo
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveToCannotBeDoneTwice(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
        $this->assertFileExists($path);
 | 
			
		||||
        unlink($path);
 | 
			
		||||
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This test must run after testMoveTo
 | 
			
		||||
     *
 | 
			
		||||
     * @depends testConstructor
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveToAgain(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This test must run after testMoveTo
 | 
			
		||||
     *
 | 
			
		||||
     * @depends testConstructor
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMovedStream(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $uploadedFile->getStream();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testMoveToStream()
 | 
			
		||||
    {
 | 
			
		||||
        $uploadedFile = $this->generateNewTmpFile();
 | 
			
		||||
 | 
			
		||||
        $fileProperty = new ReflectionProperty($uploadedFile, 'file');
 | 
			
		||||
        $fileProperty->setAccessible(true);
 | 
			
		||||
        $fileName = $fileProperty->getValue($uploadedFile);
 | 
			
		||||
 | 
			
		||||
        $contents = file_get_contents($fileName);
 | 
			
		||||
 | 
			
		||||
        ob_start();
 | 
			
		||||
        $uploadedFile->moveTo('php://output');
 | 
			
		||||
        $movedFileContents = ob_get_clean();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($contents, $movedFileContents);
 | 
			
		||||
        $this->assertFileDoesNotExist($fileName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testMoveToStreamCopyFailure()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Error moving uploaded file  to php://output');
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = $this->generateNewTmpFile();
 | 
			
		||||
 | 
			
		||||
        $GLOBALS['copy_return'] = false;
 | 
			
		||||
        $uploadedFile->moveTo('php://output');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testFileUploadWithTempStream()
 | 
			
		||||
    {
 | 
			
		||||
        $streamFactory = function (...$args) {
 | 
			
		||||
            return (new StreamFactory())->createStream(...$args);
 | 
			
		||||
        };
 | 
			
		||||
        $uploadedFileFactory = function (...$args) {
 | 
			
		||||
            return (new UploadedFileFactory())->createUploadedFile(...$args);
 | 
			
		||||
        };
 | 
			
		||||
        $this->runFileUploadWithTempStreamTest($streamFactory, $uploadedFileFactory);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This test sequence has been inspired by UploadedFileFactoryTestCase from http-interop/http-factory-tests package.
 | 
			
		||||
     *
 | 
			
		||||
     * @param callable $streamFactory
 | 
			
		||||
     * @param callable $uploadedFileFactory
 | 
			
		||||
     */
 | 
			
		||||
    private function runFileUploadWithTempStreamTest(callable $streamFactory, callable $uploadedFileFactory)
 | 
			
		||||
    {
 | 
			
		||||
        $content = 'this is your capitan speaking';
 | 
			
		||||
        $error = UPLOAD_ERR_OK;
 | 
			
		||||
        $clientFilename = 'test.txt';
 | 
			
		||||
        $clientMediaType = 'text/plain';
 | 
			
		||||
 | 
			
		||||
        $stream = call_user_func($streamFactory, $content);
 | 
			
		||||
        $file = call_user_func(
 | 
			
		||||
            $uploadedFileFactory,
 | 
			
		||||
            $stream,
 | 
			
		||||
            strlen($content),
 | 
			
		||||
            $error,
 | 
			
		||||
            $clientFilename,
 | 
			
		||||
            $clientMediaType
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->assertInstanceOf(UploadedFileInterface::class, $file);
 | 
			
		||||
        $this->assertSame($content, (string)$file->getStream());
 | 
			
		||||
        $this->assertSame(strlen($content), $file->getSize());
 | 
			
		||||
        $this->assertSame($error, $file->getError());
 | 
			
		||||
        $this->assertSame($clientFilename, $file->getClientFilename());
 | 
			
		||||
        $this->assertSame($clientMediaType, $file->getClientMediaType());
 | 
			
		||||
        $this->assertSame($stream->getMetadata('uri'), $file->getFilePath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateUploadedFileWithInvalidArguments()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        new UploadedFile(42); // a random value that is neither a string nor an instance of StreamInterface
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateUploadedFileWithInvalidUri()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $streamProphecy = $this->prophesize(StreamInterface::class);
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy
 | 
			
		||||
            ->getMetadata('uri')
 | 
			
		||||
            ->willReturn(null)
 | 
			
		||||
            ->shouldBeCalled();
 | 
			
		||||
        $stream = $streamProphecy->reveal();
 | 
			
		||||
 | 
			
		||||
        // Test with a StreamInterface that returns `null`
 | 
			
		||||
        // when `$stream->getMetadata('uri')` is called (which is an invalid case).
 | 
			
		||||
        new UploadedFile($stream);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function providerCreateFromGlobals(): array
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            // no nest: <input name="avatar" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                // $_FILES array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatar' => [
 | 
			
		||||
                        'tmp_name' => 'phpUxcOty',
 | 
			
		||||
                        'name' => 'my-avatar.png',
 | 
			
		||||
                        'size' => 90996,
 | 
			
		||||
                        'type' => 'image/png',
 | 
			
		||||
                        'error' => 0,
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatar' => new UploadedFile('phpUxcOty', 'my-avatar.png', 'image/png', 90996, UPLOAD_ERR_OK, true)
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
            // no nest, with error: <input name="avatar" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                // $_FILES array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatar' => [
 | 
			
		||||
                        'tmp_name' => 'phpUxcOty',
 | 
			
		||||
                        'name' => 'my-avatar.png',
 | 
			
		||||
                        'size' => 90996,
 | 
			
		||||
                        'type' => 'image/png',
 | 
			
		||||
                        'error' => 7,
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatar' => new UploadedFile(
 | 
			
		||||
                        'phpUxcOty',
 | 
			
		||||
                        'my-avatar.png',
 | 
			
		||||
                        'image/png',
 | 
			
		||||
                        90996,
 | 
			
		||||
                        UPLOAD_ERR_CANT_WRITE,
 | 
			
		||||
                        true
 | 
			
		||||
                    )
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
 | 
			
		||||
            // array of files: <input name="avatars[]" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                // $_FILES array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatars' => [
 | 
			
		||||
                        'tmp_name' => [
 | 
			
		||||
                            0 => __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                            1 => __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'name' => [
 | 
			
		||||
                            0 => 'file0.txt',
 | 
			
		||||
                            1 => 'file1.html',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'type' => [
 | 
			
		||||
                            0 => 'text/plain',
 | 
			
		||||
                            1 => 'text/html',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'error' => [
 | 
			
		||||
                            0 => 0,
 | 
			
		||||
                            1 => 0
 | 
			
		||||
                        ],
 | 
			
		||||
                        'size' => [
 | 
			
		||||
                            0 => 0,
 | 
			
		||||
                            1 => 0
 | 
			
		||||
                        ]
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatars' => [
 | 
			
		||||
                        0 => new UploadedFile(
 | 
			
		||||
                            __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                            'file0.txt',
 | 
			
		||||
                            'text/plain',
 | 
			
		||||
                            null,
 | 
			
		||||
                            UPLOAD_ERR_OK,
 | 
			
		||||
                            true
 | 
			
		||||
                        ),
 | 
			
		||||
                        1 => new UploadedFile(
 | 
			
		||||
                            __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
 | 
			
		||||
                            'file1.html',
 | 
			
		||||
                            'text/html',
 | 
			
		||||
                            null,
 | 
			
		||||
                            UPLOAD_ERR_OK,
 | 
			
		||||
                            true
 | 
			
		||||
                        ),
 | 
			
		||||
                    ],
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
            // array of files as multidimensional array: <input name="avatars[]" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                // $_FILES array
 | 
			
		||||
                [
 | 
			
		||||
                    [
 | 
			
		||||
                        'avatars' => [
 | 
			
		||||
                            'tmp_name' => [
 | 
			
		||||
                                0 => __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                                1 => __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
 | 
			
		||||
                            ],
 | 
			
		||||
                            'name' => [
 | 
			
		||||
                                0 => 'file0.txt',
 | 
			
		||||
                                1 => 'file1.html',
 | 
			
		||||
                            ],
 | 
			
		||||
                            'type' => [
 | 
			
		||||
                                0 => 'text/plain',
 | 
			
		||||
                                1 => 'text/html',
 | 
			
		||||
                            ],
 | 
			
		||||
                            'size' => [
 | 
			
		||||
                                0 => 0,
 | 
			
		||||
                                1 => 0,
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    0 =>
 | 
			
		||||
                        [
 | 
			
		||||
                            'avatars' =>
 | 
			
		||||
                                [
 | 
			
		||||
                                    'tmp_name' => [],
 | 
			
		||||
                                    'name' => [],
 | 
			
		||||
                                    'type' => [],
 | 
			
		||||
                                    'size' => [],
 | 
			
		||||
                                ],
 | 
			
		||||
                        ],
 | 
			
		||||
                ],
 | 
			
		||||
            ],
 | 
			
		||||
            // single nested file: <input name="details[avatar]" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                // $_FILES array
 | 
			
		||||
                [
 | 
			
		||||
                    'details' => [
 | 
			
		||||
                        'tmp_name' => [
 | 
			
		||||
                            'avatar' => __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'name' => [
 | 
			
		||||
                            'avatar' => 'file0.txt',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'type' => [
 | 
			
		||||
                            'avatar' => 'text/plain',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'error' => [
 | 
			
		||||
                            'avatar' => 0,
 | 
			
		||||
                        ],
 | 
			
		||||
                        'size' => [
 | 
			
		||||
                            'avatar' => 0,
 | 
			
		||||
                        ],
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    'details' => [
 | 
			
		||||
                        'avatar' => new UploadedFile(
 | 
			
		||||
                            __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                            'file0.txt',
 | 
			
		||||
                            'text/plain',
 | 
			
		||||
                            null,
 | 
			
		||||
                            UPLOAD_ERR_OK,
 | 
			
		||||
                            true
 | 
			
		||||
                        ),
 | 
			
		||||
                    ],
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
            // nested array of files: <input name="files[details][avatar][]" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                [
 | 
			
		||||
                    'files' => [
 | 
			
		||||
                        'tmp_name' => [
 | 
			
		||||
                            'details' => [
 | 
			
		||||
                                'avatar' => [
 | 
			
		||||
                                    0 => __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                                    1 => __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
 | 
			
		||||
                                ],
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                        'name' => [
 | 
			
		||||
                            'details' => [
 | 
			
		||||
                                'avatar' => [
 | 
			
		||||
                                    0 => 'file0.txt',
 | 
			
		||||
                                    1 => 'file1.html',
 | 
			
		||||
                                ],
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                        'type' => [
 | 
			
		||||
                            'details' => [
 | 
			
		||||
                                'avatar' => [
 | 
			
		||||
                                    0 => 'text/plain',
 | 
			
		||||
                                    1 => 'text/html',
 | 
			
		||||
                                ],
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                        'error' => [
 | 
			
		||||
                            'details' => [
 | 
			
		||||
                                'avatar' => [
 | 
			
		||||
                                    0 => 0,
 | 
			
		||||
                                    1 => 0
 | 
			
		||||
                                ],
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                        'size' => [
 | 
			
		||||
                            'details' => [
 | 
			
		||||
                                'avatar' => [
 | 
			
		||||
                                    0 => 0,
 | 
			
		||||
                                    1 => 0
 | 
			
		||||
                                ],
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    'files' => [
 | 
			
		||||
                        'details' => [
 | 
			
		||||
                            'avatar' => [
 | 
			
		||||
                                0 => new UploadedFile(
 | 
			
		||||
                                    __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                                    'file0.txt',
 | 
			
		||||
                                    'text/plain',
 | 
			
		||||
                                    null,
 | 
			
		||||
                                    UPLOAD_ERR_OK,
 | 
			
		||||
                                    true
 | 
			
		||||
                                ),
 | 
			
		||||
                                1 => new UploadedFile(
 | 
			
		||||
                                    __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
 | 
			
		||||
                                    'file1.html',
 | 
			
		||||
                                    'text/html',
 | 
			
		||||
                                    null,
 | 
			
		||||
                                    UPLOAD_ERR_OK,
 | 
			
		||||
                                    true
 | 
			
		||||
                                ),
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                    ],
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										383
									
								
								qwen/php/vendor/slim/psr7/tests/UriTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										383
									
								
								qwen/php/vendor/slim/psr7/tests/UriTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,383 @@
 | 
			
		||||
<?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;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Slim\Psr7\Uri;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
class UriTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function uriFactory(): Uri
 | 
			
		||||
    {
 | 
			
		||||
        $scheme = 'https';
 | 
			
		||||
        $host = 'example.com';
 | 
			
		||||
        $port = 443;
 | 
			
		||||
        $path = '/foo/bar';
 | 
			
		||||
        $query = 'abc=123';
 | 
			
		||||
        $fragment = 'section3';
 | 
			
		||||
        $user = 'josh';
 | 
			
		||||
        $password = 'sekrit';
 | 
			
		||||
 | 
			
		||||
        return new Uri($scheme, $host, $port, $path, $query, $fragment, $user, $password);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSupportOtherSchemes()
 | 
			
		||||
    {
 | 
			
		||||
        $wsUri = new class ('ws', 'example.com') extends Uri {
 | 
			
		||||
            public const SUPPORTED_SCHEMES = [
 | 
			
		||||
                'ws' => 80,
 | 
			
		||||
                'wss' => 443,
 | 
			
		||||
            ];
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('ws', $wsUri->getScheme());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetScheme()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('https', $this->uriFactory()->getScheme());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithScheme()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withScheme('http');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('http', $uri->getScheme());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithSchemeRemovesSuffix()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withScheme('http://');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('http', $uri->getScheme());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithSchemeEmpty()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withScheme('');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getScheme());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithSchemeInvalid()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessageMatches('/^Uri scheme must be one of:.*$/');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withScheme('ftp');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithSchemeInvalidType()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Uri scheme must be a string');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withScheme([]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAuthorityWithUsernameAndPassword()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('josh:sekrit@example.com', $this->uriFactory()->getAuthority());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUserInfo()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withUserInfo('bob', 'pass');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bob:pass', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUserInfoEncodesCorrectly()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withUserInfo('bob@example.com', 'pass:word');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bob%40example.com:pass%3Aword', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUserInfoRemovesPassword()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withUserInfo('bob');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bob', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUserInfoRemovesInfo()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withUserInfo('bob', 'password');
 | 
			
		||||
        $uri = $uri->withUserInfo('');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHost()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('example.com', $this->uriFactory()->getHost());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithHost()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withHost('slimframework.com');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('slimframework.com', $uri->getHost());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithHostValidObject()
 | 
			
		||||
    {
 | 
			
		||||
        $mock = new StringableTestObject('host.test');
 | 
			
		||||
 | 
			
		||||
        $uri = $this->uriFactory()->withHost($mock);
 | 
			
		||||
        $this->assertEquals('host.test', $uri->getHost());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithHostInvalidObject()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Uri host must be a string');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withHost(new stdClass());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testFilterHost()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = new Uri('http', '2001:db8::1');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('[2001:db8::1]', $uri->getHost());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetPortWithSchemeAndNonDefaultPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = new Uri('https', 'www.example.com', 4000);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(4000, $uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetPortWithSchemeAndDefaultPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uriHttp = new Uri('http', 'www.example.com', 80);
 | 
			
		||||
        $uriHttps = new Uri('https', 'www.example.com', 443);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($uriHttp->getPort());
 | 
			
		||||
        $this->assertNull($uriHttps->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetPortWithoutSchemeAndPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = new Uri('', 'www.example.com');
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetPortWithSchemeWithoutPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = new Uri('http', 'www.example.com');
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPort(8000);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(8000, $uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPortNull()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPort(null);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(null, $uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPortInvalidInt()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withPort(70000);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPortInvalidString()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withPort('Foo');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPortIntegerAsString()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPort("199");
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(199, $uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetPath()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('/foo/bar', $this->uriFactory()->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPath()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPath('/new');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/new', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathWithoutPrefix()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPath('new');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('new', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathEmptyValue()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPath('');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathUrlEncodesInput()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPath('/includes?/new');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/includes%3F/new', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathDoesNotDoubleEncodeInput()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPath('/include%25s/new');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/include%25s/new', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathInvalidType()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Uri path must be a string');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withPath(['foo']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetQuery()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('abc=123', $this->uriFactory()->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQuery()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withQuery('xyz=123');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('xyz=123', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryRemovesPrefix()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withQuery('?xyz=123');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('xyz=123', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryEmpty()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withQuery('');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryValidObject()
 | 
			
		||||
    {
 | 
			
		||||
        $mock = new StringableTestObject('xyz=123');
 | 
			
		||||
 | 
			
		||||
        $uri = $this->uriFactory()->withQuery($mock);
 | 
			
		||||
        $this->assertEquals('xyz=123', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testFilterQuery()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withQuery('?foobar=%match');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('foobar=%25match', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryInvalidType()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Uri query must be a string');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withQuery(['foo']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetFragment()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('section3', $this->uriFactory()->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragment()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withFragment('other-fragment');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('other-fragment', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragmentRemovesPrefix()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withFragment('#other-fragment');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('other-fragment', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragmentEmpty()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withFragment('');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragmentValidObject()
 | 
			
		||||
    {
 | 
			
		||||
        $mock = new StringableTestObject('other-fragment');
 | 
			
		||||
 | 
			
		||||
        $uri = $this->uriFactory()->withFragment($mock);
 | 
			
		||||
        $this->assertEquals('other-fragment', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragmentUrlEncode()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withFragment('^a');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('%5Ea', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragmentInvalidType()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Uri fragment must be a string');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withFragment(['foo']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToString()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('https://josh:sekrit@example.com/foo/bar?abc=123#section3', (string) $uri);
 | 
			
		||||
 | 
			
		||||
        $uri = $uri->withPath('bar');
 | 
			
		||||
        $this->assertEquals('https://josh:sekrit@example.com/bar?abc=123#section3', (string) $uri);
 | 
			
		||||
 | 
			
		||||
        $uri = $uri->withPath('/bar');
 | 
			
		||||
        $this->assertEquals('https://josh:sekrit@example.com/bar?abc=123#section3', (string) $uri);
 | 
			
		||||
 | 
			
		||||
        $uri = $uri->withScheme('')->withHost('')->withPort(null)->withUserInfo('')->withPath('//bar');
 | 
			
		||||
        $this->assertEquals('/bar?abc=123#section3', (string) $uri);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										99
									
								
								qwen/php/vendor/slim/psr7/tests/bootstrap.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								qwen/php/vendor/slim/psr7/tests/bootstrap.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,99 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
use AdrianSuter\Autoload\Override\Override;
 | 
			
		||||
use Slim\Psr7\Factory;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Message;
 | 
			
		||||
use Slim\Psr7\NonBufferedBody;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
use Slim\Tests\Psr7\Assets\HeaderStack;
 | 
			
		||||
 | 
			
		||||
$classLoader = require __DIR__ . '/../vendor/autoload.php';
 | 
			
		||||
 | 
			
		||||
Override::apply($classLoader, [
 | 
			
		||||
    Headers::class => [
 | 
			
		||||
        'getallheaders' => function () {
 | 
			
		||||
            if (array_key_exists('getallheaders_return', $GLOBALS)) {
 | 
			
		||||
                return $GLOBALS['getallheaders_return'];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return getallheaders();
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    Message::class => [
 | 
			
		||||
        'header' => function (string $string, bool $replace = true, ?int $statusCode = null): void {
 | 
			
		||||
            HeaderStack::push(
 | 
			
		||||
                [
 | 
			
		||||
                    'header'      => $string,
 | 
			
		||||
                    'replace'     => $replace,
 | 
			
		||||
                    'status_code' => $statusCode,
 | 
			
		||||
                ]
 | 
			
		||||
            );
 | 
			
		||||
        },
 | 
			
		||||
        'header_remove' => function ($name = null): void {
 | 
			
		||||
            HeaderStack::remove($name);
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    NonBufferedBody::class => [
 | 
			
		||||
        'ob_get_level' => function (): int {
 | 
			
		||||
            if (isset($GLOBALS['ob_get_level_shift'])) {
 | 
			
		||||
                return ob_get_level() + $GLOBALS['ob_get_level_shift'];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return ob_get_level();
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    UploadedFile::class => [
 | 
			
		||||
        'copy' => function (string $source, string $destination, $context = null): bool {
 | 
			
		||||
            if (isset($GLOBALS['copy_return'])) {
 | 
			
		||||
                return $GLOBALS['copy_return'];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if ($context === null) {
 | 
			
		||||
                return copy($source, $destination);
 | 
			
		||||
            }
 | 
			
		||||
            return copy($source, $destination, $context);
 | 
			
		||||
        },
 | 
			
		||||
        'is_uploaded_file' => function (string $filename): bool {
 | 
			
		||||
            if (isset($GLOBALS['is_uploaded_file_return'])) {
 | 
			
		||||
                return $GLOBALS['is_uploaded_file_return'];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return is_uploaded_file($filename);
 | 
			
		||||
        },
 | 
			
		||||
        'rename' => function (string $oldName, string $newName, $context = null): bool {
 | 
			
		||||
            if (isset($GLOBALS['rename_return'])) {
 | 
			
		||||
                return $GLOBALS['rename_return'];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if ($context === null) {
 | 
			
		||||
                return rename($oldName, $newName);
 | 
			
		||||
            }
 | 
			
		||||
            return rename($oldName, $newName, $context = null);
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    Factory\StreamFactory::class => [
 | 
			
		||||
        'fopen' => function (string $filename, string $mode) {
 | 
			
		||||
            if (isset($GLOBALS['fopen_return'])) {
 | 
			
		||||
                return isset($GLOBALS['fopen_return']);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return fopen($filename, $mode);
 | 
			
		||||
        },
 | 
			
		||||
        'is_readable' => function (string $filename) {
 | 
			
		||||
            if ($filename === 'non-readable') {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return is_readable($filename);
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
]);
 | 
			
		||||
		Reference in New Issue
	
	Block a user