pax_global_header00006660000000000000000000000064140256535760014527gustar00rootroot0000000000000052 comment=642056c5360e8a74779cbf133afbc8aa2c174e15 http-factory-tests-0.9.0/000077500000000000000000000000001402565357600153215ustar00rootroot00000000000000http-factory-tests-0.9.0/.gitignore000066400000000000000000000000671402565357600173140ustar00rootroot00000000000000composer.phar composer.lock phpunit.xml build/ vendor/ http-factory-tests-0.9.0/LICENSE000066400000000000000000000020651402565357600163310ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2016 Woody Gilk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. http-factory-tests-0.9.0/README.md000066400000000000000000000015751402565357600166100ustar00rootroot00000000000000# Unit tests for HTTP Factory implementations To use these unit tests you need to add some config to phpunit.xml. ```xml ./vendor/http-interop/http-factory-tests/test ``` http-factory-tests-0.9.0/composer.json000066400000000000000000000011421402565357600200410ustar00rootroot00000000000000{ "name": "http-interop/http-factory-tests", "description": "Unit tests for HTTP factories", "keywords": [ "psr-7", "psr-17", "http", "factory", "test" ], "license": "MIT", "authors": [ { "name": "PHP-FIG", "homepage": "http://www.php-fig.org/" } ], "require": { "php": "^7.1 || ^8.0", "psr/http-factory": "^1.0", "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" }, "autoload": { "psr-4": { "Interop\\Http\\Factory\\": "test/" } } } http-factory-tests-0.9.0/test/000077500000000000000000000000001402565357600163005ustar00rootroot00000000000000http-factory-tests-0.9.0/test/RequestFactoryTest.php000066400000000000000000000013601402565357600226310ustar00rootroot00000000000000markTestSkipped('Request factory class name not provided'); } $factoryClass = REQUEST_FACTORY; return new $factoryClass(); } /** * {@inheritdoc} */ protected function createUri($uri) { if (!defined('URI_FACTORY')) { $this->markTestSkipped('URI factory class name not provided'); } $factoryClass = URI_FACTORY; $uriFactory = new $factoryClass(); return $uriFactory->createUri($uri); } } http-factory-tests-0.9.0/test/RequestFactoryTestCase.php000066400000000000000000000032141402565357600234250ustar00rootroot00000000000000factory = $this->createRequestFactory(); } protected function assertRequest($request, $method, $uri) { $this->assertInstanceOf(RequestInterface::class, $request); $this->assertSame($method, $request->getMethod()); $this->assertSame($uri, (string) $request->getUri()); } public function dataMethods() { return [ ['GET'], ['POST'], ['PUT'], ['DELETE'], ['OPTIONS'], ['HEAD'], ]; } /** * @dataProvider dataMethods */ public function testCreateRequest($method) { $uri = 'http://example.com/'; $request = $this->factory->createRequest($method, $uri); $this->assertRequest($request, $method, $uri); } public function testCreateRequestWithUri() { $method = 'GET'; $uri = 'http://example.com/'; $request = $this->factory->createRequest($method, $this->createUri($uri)); $this->assertRequest($request, $method, $uri); } } http-factory-tests-0.9.0/test/ResponseFactoryTest.php000066400000000000000000000006421402565357600230010ustar00rootroot00000000000000markTestSkipped('Response factory class name not provided'); } $factoryClass = RESPONSE_FACTORY; return new $factoryClass(); } } http-factory-tests-0.9.0/test/ResponseFactoryTestCase.php000066400000000000000000000020701402565357600235720ustar00rootroot00000000000000factory = $this->createResponseFactory(); } protected function assertResponse($response, $code) { $this->assertInstanceOf(ResponseInterface::class, $response); $this->assertSame($code, $response->getStatusCode()); } public function dataCodes() { return [ [200], [301], [404], [500], ]; } /** * @dataProvider dataCodes */ public function testCreateResponse($code) { $response = $this->factory->createResponse($code); $this->assertResponse($response, $code); } } http-factory-tests-0.9.0/test/ServerRequestFactoryTest.php000066400000000000000000000014271402565357600240240ustar00rootroot00000000000000markTestSkipped('Server Request factory class name not provided'); } $factoryClass = SERVER_REQUEST_FACTORY; return new $factoryClass(); } /** * {@inheritdoc} */ protected function createUri($uri) { if (!defined('URI_FACTORY')) { $this->markTestSkipped('URI factory class name not provided'); } $factoryClass = URI_FACTORY; $uriFactory = new $factoryClass(); return $uriFactory->createUri($uri); } } http-factory-tests-0.9.0/test/ServerRequestFactoryTestCase.php000066400000000000000000000111271402565357600246160ustar00rootroot00000000000000factory = $this->createServerRequestFactory(); } protected function assertServerRequest($request, $method, $uri) { $this->assertInstanceOf(ServerRequestInterface::class, $request); $this->assertSame($method, $request->getMethod()); $this->assertSame($uri, (string) $request->getUri()); } public function dataMethods() { return [ ['GET'], ['POST'], ['PUT'], ['DELETE'], ['OPTIONS'], ['HEAD'], ]; } public function dataServer() { $data = []; foreach ($this->dataMethods() as $methodData) { $data[] = [ [ 'REQUEST_METHOD' => $methodData[0], 'REQUEST_URI' => '/test', 'QUERY_STRING' => 'foo=1&bar=true', 'HTTP_HOST' => 'example.org', ] ]; } return $data; } /** * @dataProvider dataServer */ public function testCreateServerRequest($server) { $method = $server['REQUEST_METHOD']; $uri = "http://{$server['HTTP_HOST']}{$server['REQUEST_URI']}?{$server['QUERY_STRING']}"; $request = $this->factory->createServerRequest($method, $uri); $this->assertServerRequest($request, $method, $uri); } /** * @dataProvider dataServer */ public function testCreateServerRequestFromArray(array $server) { $method = $server['REQUEST_METHOD']; $uri = "http://{$server['HTTP_HOST']}{$server['REQUEST_URI']}?{$server['QUERY_STRING']}"; $request = $this->factory->createServerRequest($method, $uri, $server); $this->assertServerRequest($request, $method, $uri); } /** * @dataProvider dataServer */ public function testCreateServerRequestWithUriObject($server) { $method = $server['REQUEST_METHOD']; $uri = "http://{$server['HTTP_HOST']}{$server['REQUEST_URI']}?{$server['QUERY_STRING']}"; $request = $this->factory->createServerRequest($method, $this->createUri($uri)); $this->assertServerRequest($request, $method, $uri); } /** * @backupGlobals enabled */ public function testCreateServerRequestDoesNotReadServerSuperglobal() { $_SERVER = ['HTTP_X_FOO' => 'bar']; $server = [ 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/test', 'QUERY_STRING' => 'super=0', 'HTTP_HOST' => 'example.org', ]; $request = $this->factory->createServerRequest('PUT', '/test', $server); $serverParams = $request->getServerParams(); $this->assertNotEquals($_SERVER, $serverParams); $this->assertArrayNotHasKey('HTTP_X_FOO', $serverParams); } public function testCreateServerRequestDoesNotReadCookieSuperglobal() { $_COOKIE = ['foo' => 'bar']; $request = $this->factory->createServerRequest('POST', 'http://example.org/test'); $this->assertEmpty($request->getCookieParams()); } public function testCreateServerRequestDoesNotReadGetSuperglobal() { $_GET = ['foo' => 'bar']; $request = $this->factory->createServerRequest('POST', 'http://example.org/test'); $this->assertEmpty($request->getQueryParams()); } public function testCreateServerRequestDoesNotReadFilesSuperglobal() { $_FILES = [['name' => 'foobar.dat', 'type' => 'application/octet-stream', 'tmp_name' => '/tmp/php45sd3f', 'error' => UPLOAD_ERR_OK, 'size' => 4]]; $request = $this->factory->createServerRequest('POST', 'http://example.org/test'); $this->assertEmpty($request->getUploadedFiles()); } public function testCreateServerRequestDoesNotReadPostSuperglobal() { $_POST = ['foo' => 'bar']; $request = $this->factory->createServerRequest('POST', 'http://example.org/test'); $this->assertEmpty($request->getParsedBody()); } } http-factory-tests-0.9.0/test/StreamFactoryTest.php000066400000000000000000000006261402565357600224400ustar00rootroot00000000000000markTestSkipped('Stream factory class name not provided'); } $factoryClass = STREAM_FACTORY; return new $factoryClass(); } } http-factory-tests-0.9.0/test/StreamFactoryTestCase.php000066400000000000000000000073331402565357600232360ustar00rootroot00000000000000factory = $this->createStreamFactory(); } protected function assertStream($stream, $content) { $this->assertInstanceOf(StreamInterface::class, $stream); $this->assertSame($content, (string) $stream); } public function testCreateStreamWithoutArgument() { $stream = $this->factory->createStream(); $this->assertStream($stream, ''); } public function testCreateStreamWithEmptyString() { $string = ''; $stream = $this->factory->createStream($string); $this->assertStream($stream, $string); } public function testCreateStreamWithASCIIString() { $string = 'would you like some crumpets?'; $stream = $this->factory->createStream($string); $this->assertStream($stream, $string); } public function testCreateStreamWithMultiByteMultiLineString() { $string = "would you\r\nlike some\n\u{1F950}?"; $stream = $this->factory->createStream($string); $this->assertStream($stream, $string); } public function testCreateStreamFromFile() { $string = 'would you like some crumpets?'; $filename = $this->createTemporaryFile(); file_put_contents($filename, $string); $stream = $this->factory->createStreamFromFile($filename); $this->assertStream($stream, $string); } public function testCreateStreamFromNonExistingFile() { $filename = $this->createTemporaryFile(); unlink($filename); $this->expectException(RuntimeException::class); $stream = $this->factory->createStreamFromFile($filename); } public function testCreateStreamFromInvalidFileName() { $this->expectException(RuntimeException::class); $stream = $this->factory->createStreamFromFile(''); } public function testCreateStreamFromFileIsReadOnlyByDefault() { $string = 'would you like some crumpets?'; $filename = $this->createTemporaryFile(); $stream = $this->factory->createStreamFromFile($filename); $this->expectException(RuntimeException::class); $stream->write($string); } public function testCreateStreamFromFileWithWriteOnlyMode() { $filename = $this->createTemporaryFile(); $stream = $this->factory->createStreamFromFile($filename, 'w'); $this->expectException(RuntimeException::class); $stream->read(1); } public function testCreateStreamFromFileWithNoMode() { $filename = $this->createTemporaryFile(); $this->expectException(Exception::class); $stream = $this->factory->createStreamFromFile($filename, ''); } public function testCreateStreamFromFileWithInvalidMode() { $filename = $this->createTemporaryFile(); $this->expectException(Exception::class); $stream = $this->factory->createStreamFromFile($filename, "\u{2620}"); } public function testCreateStreamFromResource() { $string = 'would you like some crumpets?'; $resource = $this->createTemporaryResource($string); $stream = $this->factory->createStreamFromResource($resource); $this->assertStream($stream, $string); } } http-factory-tests-0.9.0/test/StreamHelper.php000066400000000000000000000013721402565357600214070ustar00rootroot00000000000000createTemporaryFile(); $resource = fopen($file, 'r+'); if ($content) { fwrite($resource, $content); rewind($resource); } return $resource; } public static function tearDownAfterClass(): void { foreach (static::$tempFiles as $tempFile) { if (is_file($tempFile)) { unlink($tempFile); } } } } http-factory-tests-0.9.0/test/UploadedFileFactoryTest.php000066400000000000000000000014031402565357600235340ustar00rootroot00000000000000markTestSkipped('Uploaded File factory class name not provided'); } $factoryClass = UPLOADED_FILE_FACTORY; return new $factoryClass(); } protected function createStream($content) { if (!defined('STREAM_FACTORY')) { $this->markTestSkipped('STREAM factory class name not provided'); } $factoryClass = STREAM_FACTORY; $uriFactory = new $factoryClass(); return $uriFactory->createStream($content); } } http-factory-tests-0.9.0/test/UploadedFileFactoryTestCase.php000066400000000000000000000043641402565357600243410ustar00rootroot00000000000000factory = $this->createUploadedFileFactory(); } protected function assertUploadedFile( $file, $content, $size = null, $error = null, $clientFilename = null, $clientMediaType = null ) { $this->assertInstanceOf(UploadedFileInterface::class, $file); $this->assertSame($content, (string) $file->getStream()); $this->assertSame($size ?: strlen($content), $file->getSize()); $this->assertSame($error ?: UPLOAD_ERR_OK, $file->getError()); $this->assertSame($clientFilename, $file->getClientFilename()); $this->assertSame($clientMediaType, $file->getClientMediaType()); } public function testCreateUploadedFileWithClientFilenameAndMediaType() { $content = 'this is your capitan speaking'; $upload = $this->createStream($content); $error = UPLOAD_ERR_OK; $clientFilename = 'test.txt'; $clientMediaType = 'text/plain'; $file = $this->factory->createUploadedFile($upload, null, $error, $clientFilename, $clientMediaType); $this->assertUploadedFile($file, $content, null, $error, $clientFilename, $clientMediaType); } public function testCreateUploadedFileWithError() { $upload = $this->createStream('foobar'); $error = UPLOAD_ERR_NO_FILE; $file = $this->factory->createUploadedFile($upload, null, $error); // Cannot use assertUploadedFile() here because the error prevents // fetching the content stream. $this->assertInstanceOf(UploadedFileInterface::class, $file); $this->assertSame($error, $file->getError()); } } http-factory-tests-0.9.0/test/UriFactoryTest.php000066400000000000000000000006041402565357600217400ustar00rootroot00000000000000markTestSkipped('URI factory class name not provided'); } $factoryClass = URI_FACTORY; return new $factoryClass(); } } http-factory-tests-0.9.0/test/UriFactoryTestCase.php000066400000000000000000000017761402565357600225470ustar00rootroot00000000000000factory = $this->createUriFactory(); } protected function assertUri($uri, $uriString) { $this->assertInstanceOf(UriInterface::class, $uri); $this->assertSame($uriString, (string) $uri); } public function testCreateUri() { $uriString = 'http://example.com/'; $uri = $this->factory->createUri($uriString); $this->assertUri($uri, $uriString); } public function testExceptionWhenUriIsInvalid() { $this->expectException(\InvalidArgumentException::class); $this->factory->createUri(':'); } }