pax_global_header00006660000000000000000000000064134317451630014521gustar00rootroot0000000000000052 comment=c3bb79ca4a276df57364ff45bf2f619f769ded4a psr7-integration-tests-master/000077500000000000000000000000001343174516300167325ustar00rootroot00000000000000psr7-integration-tests-master/CHANGELOG.md000066400000000000000000000000151343174516300205370ustar00rootroot00000000000000# Change Log psr7-integration-tests-master/LICENSE000066400000000000000000000020721343174516300177400ustar00rootroot00000000000000Copyright (c) 2015-2016 PHP HTTP Team 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. psr7-integration-tests-master/README.md000066400000000000000000000040141343174516300202100ustar00rootroot00000000000000# HTTP Message [![Total Downloads](https://img.shields.io/packagist/dt/php-http/psr7-integration-tests.svg?style=flat-square)](https://packagist.org/packages/php-http/psr7-integration-tests) **Test PSR7 implementations against the specification.** ## Status | PSR7 Implementation | Status | | ------------------- |:-------------:| | Guzzle | [![Guzzle](https://travis-matrix-badges.herokuapp.com/repos/php-http/psr7-integration-tests/branches/master/1)](https://travis-ci.org/php-http/psr7-integration-tests) | | Zend | [![Zend](https://travis-matrix-badges.herokuapp.com/repos/php-http/psr7-integration-tests/branches/master/2)](https://travis-ci.org/php-http/psr7-integration-tests) | | Slim | [![Slim](https://travis-matrix-badges.herokuapp.com/repos/php-http/psr7-integration-tests/branches/master/3)](https://travis-ci.org/php-http/psr7-integration-tests) | | Nyholm | [![Nyholm](https://travis-matrix-badges.herokuapp.com/repos/php-http/psr7-integration-tests/branches/master/4)](https://travis-ci.org/php-http/psr7-integration-tests) | | RingCentral | [![RingCentral](https://travis-matrix-badges.herokuapp.com/repos/php-http/psr7-integration-tests/branches/master/5)](https://travis-ci.org/php-http/psr7-integration-tests) | ## Install Via Composer ``` bash $ composer require --dev php-http/psr7-integration-tests ``` ## Documentation Please see the [official documentation](http://docs.php-http.org/en/latest). ## Testing ``` bash $ composer test ``` It is also possible to exclude tests that require a live internet connection: ``` bash $ composer test -- --exclude-group internet ``` ## Contributing Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html). ## Security If you discover any security related issues, please contact us at [security@php-http.org](mailto:security@php-http.org). ## License The MIT License (MIT). Please see [License File](LICENSE) for more information. psr7-integration-tests-master/composer.json000066400000000000000000000020121343174516300214470ustar00rootroot00000000000000{ "name": "php-http/psr7-integration-tests", "description": "Test suite for PSR7", "keywords": [ "test", "psr-7" ], "homepage": "http://php-http.org", "license": "MIT", "authors": [ { "name": "Tobias Nyholm", "email": "tobias.nyholm@gmail.com" } ], "require": { "php": "^5.5 || ^7.0", "phpunit/phpunit": "^5.4 || ^6.0 || ^7.0", "psr/http-message": "^1.0" }, "require-dev": { "guzzlehttp/psr7": "^1.4", "nyholm/psr7": "^1.0", "ringcentral/psr7": "^1.2", "slim/psr7": "dev-master", "zendframework/zend-diactoros": "^2.1" }, "extra": { "branch-alias": { "dev-master": "1.0-dev" } }, "autoload": { "psr-4": { "Http\\Psr7Test\\": "src/" } }, "autoload-dev": { "psr-4": { "Http\\Psr7Test\\Tests\\": "tests/" } }, "scripts": { "test": "phpunit" } } psr7-integration-tests-master/src/000077500000000000000000000000001343174516300175215ustar00rootroot00000000000000psr7-integration-tests-master/src/BaseTest.php000066400000000000000000000072711343174516300217530ustar00rootroot00000000000000 */ abstract class BaseTest extends TestCase { protected function assertNotSameObject($a, $b) { $this->assertFalse($a === $b, 'Object does not have different references.'); } protected function buildUri($uri) { if (defined('URI_FACTORY')) { $factoryClass = URI_FACTORY; $factory = new $factoryClass(); if ($factory instanceof \Http\Message\UriFactory) { return $factory->createUri($uri); } if ($factory instanceof \Psr\Http\Message\UriFactoryInterface) { if ($uri instanceof UriInterface) { return $uri; } return $factory->createUri($uri); } throw new \RuntimeException('Constant "URI_FACTORY" must be a reference to a Http\Message\UriFactory or \Psr\Http\Message\UriFactoryInterface'); } if (class_exists(GuzzleUri::class)) { return new GuzzleUri($uri); } if (class_exists(SlimUri::class)) { return SlimUri::createFromString($uri); } if (class_exists(ZendUri::class)) { return new ZendUri($uri); } throw new \RuntimeException('Could not create URI. Check your config'); } protected function buildStream($data) { if (defined('STREAM_FACTORY')) { $factoryClass = STREAM_FACTORY; $factory = new $factoryClass(); if ($factory instanceof \Http\Message\StreamFactory) { return $factory->createStream($data); } if ($factory instanceof \Psr\Http\Message\StreamFactoryInterface) { if (is_string($data)) { return $factory->createStream($data); } else { return $factory->createStreamFromResource($data); } } throw new \RuntimeException('Constant "STREAM_FACTORY" must be a reference to a Http\Message\StreamFactory or \Psr\Http\Message\StreamFactoryInterface'); } if (class_exists(GuzzleStream::class)) { return \GuzzleHttp\Psr7\stream_for($data); } if (class_exists(ZendStream::class)) { return new ZendStream($data); } throw new \RuntimeException('Could not create Stream. Check your config'); } protected function buildUploadableFile($data) { if (defined('UPLOADED_FILE_FACTORY')) { $factoryClass = UPLOADED_FILE_FACTORY; $factory = new $factoryClass(); if (!$factory instanceof \Psr\Http\Message\UploadedFileFactoryInterface) { throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a Psr\Http\Message\UploadedFileFactoryInterface'); } $stream = $this->buildStream($data); return $factory->createUploadedFile($stream); } if (class_exists(GuzzleUploadedFile::class)) { return new GuzzleUploadedFile($data, strlen($data), 0); } if (class_exists(ZendUploadedFile::class)) { return new ZendUploadedFile($data, strlen($data), 0); } throw new \RuntimeException('Could not create Stream. Check your config'); } } psr7-integration-tests-master/src/MessageTrait.php000066400000000000000000000222441343174516300226260ustar00rootroot00000000000000 */ trait MessageTrait { /** * @return MessageInterface */ abstract protected function getMessage(); public function testProtocolVersion() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $initialMessage = $this->getMessage(); $original = clone $initialMessage; $message = $initialMessage->withProtocolVersion('1.0'); $this->assertNotSameObject($initialMessage, $message); $this->assertEquals($initialMessage, $original, 'Message object MUST not be mutated'); $this->assertSame('1.0', $message->getProtocolVersion()); } public function testGetHeaders() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $initialMessage = $this->getMessage(); $original = clone $initialMessage; $message = $initialMessage ->withAddedHeader('content-type', 'text/html') ->withAddedHeader('content-type', 'text/plain'); $this->assertEquals($initialMessage, $original, 'Message object MUST not be mutated'); $headers = $message->getHeaders(); $this->assertTrue(isset($headers['content-type'])); $this->assertCount(2, $headers['content-type']); $this->assertContains('text/html', $headers['content-type']); $this->assertContains('text/plain', $headers['content-type']); } public function testHasHeader() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $message = $this->getMessage()->withAddedHeader('content-type', 'text/html'); $this->assertTrue($message->hasHeader('content-type')); $this->assertTrue($message->hasHeader('Content-Type')); $this->assertTrue($message->hasHeader('ConTent-Type')); } public function testGetHeader() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $message = $this->getMessage()->withAddedHeader('content-type', 'text/html'); $message = $message->withAddedHeader('content-type', 'text/plain'); $this->assertCount(2, $message->getHeader('content-type')); $this->assertCount(2, $message->getHeader('Content-Type')); $this->assertCount(2, $message->getHeader('CONTENT-TYPE')); $emptyHeader = $message->getHeader('Bar'); $this->assertCount(0, $emptyHeader); $this->assertInternalType('array', $emptyHeader); } public function testGetHeaderLine() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $message = $this->getMessage()->withAddedHeader('content-type', 'text/html'); $message = $message->withAddedHeader('content-type', 'text/plain'); $this->assertRegExp('|text/html, ?text/plain|', $message->getHeaderLine('content-type')); $this->assertRegExp('|text/html, ?text/plain|', $message->getHeaderLine('Content-Type')); $this->assertRegExp('|text/html, ?text/plain|', $message->getHeaderLine('CONTENT-TYPE')); $this->assertSame('', $message->getHeaderLine('Bar')); } public function testWithHeader() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $initialMessage = $this->getMessage(); $original = clone $initialMessage; $message = $initialMessage->withHeader('content-type', 'text/html'); $this->assertNotSameObject($initialMessage, $message); $this->assertEquals($initialMessage, $original, 'Message object MUST not be mutated'); $this->assertEquals('text/html', $message->getHeaderLine('content-type')); $message = $initialMessage->withHeader('content-type', 'text/plain'); $this->assertEquals('text/plain', $message->getHeaderLine('content-type')); $message = $initialMessage->withHeader('Content-TYPE', 'text/script'); $this->assertEquals('text/script', $message->getHeaderLine('content-type')); $message = $initialMessage->withHeader('x-foo', ['bar', 'baz']); $this->assertRegExp('|bar, ?baz|', $message->getHeaderLine('x-foo')); $message = $initialMessage->withHeader('Bar', ''); $this->assertTrue($message->hasHeader('Bar')); $this->assertSame([''], $message->getHeader('Bar')); } /** * @dataProvider getInvalidHeaderArguments */ public function testWithHeaderInvalidArguments($name, $value) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->expectException(\InvalidArgumentException::class); $initialMessage = $this->getMessage(); $initialMessage->withHeader($name, $value); } public function getInvalidHeaderArguments() { return [ [[], 'foo'], ['foo', []], ['', ''], ['foo', false], [false, 'foo'], ['foo', new \stdClass()], [new \stdClass(), 'foo'], ]; } public function testWithAddedHeader() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $message = $this->getMessage()->withAddedHeader('content-type', 'text/html'); $message = $message->withAddedHeader('CONTENT-type', 'text/plain'); $this->assertRegExp('|text/html, ?text/plain|', $message->getHeaderLine('content-type')); $this->assertRegExp('|text/html, ?text/plain|', $message->getHeaderLine('Content-Type')); } /** * @dataProvider getInvalidHeaderArguments */ public function testWithAddedHeaderInvalidArguments($name, $value) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->expectException(\InvalidArgumentException::class); $initialMessage = $this->getMessage(); $initialMessage->withAddedHeader($name, $value); } /** * Make sure we maintain headers when we add array values. */ public function testWithAddedHeaderArrayValue() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $message = $this->getMessage()->withAddedHeader('content-type', 'text/html'); $message = $message->withAddedHeader('content-type', ['text/plain', 'application/json']); $headerLine = $message->getHeaderLine('content-type'); $this->assertRegExp('|text/html|', $headerLine); $this->assertRegExp('|text/plain|', $headerLine); $this->assertRegExp('|application/json|', $headerLine); } /** * Make sure we maintain headers when we add array values with keys. */ public function testWithAddedHeaderArrayValueAndKeys() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $message = $this->getMessage()->withAddedHeader('content-type', ['foo' => 'text/html']); $message = $message->withAddedHeader('content-type', ['foo' => 'text/plain', 'bar' => 'application/json']); $headerLine = $message->getHeaderLine('content-type'); $this->assertRegExp('|text/html|', $headerLine); $this->assertRegExp('|text/plain|', $headerLine); $this->assertRegExp('|application/json|', $headerLine); } public function testWithoutHeader() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $message = $this->getMessage()->withAddedHeader('content-type', 'text/html'); $message = $message->withAddedHeader('Age', '0'); $message = $message->withAddedHeader('X-Foo', 'bar'); $headers = $message->getHeaders(); $headerCount = count($headers); $this->assertTrue(isset($headers['Age'])); // Remove a header $message = $message->withoutHeader('age'); $headers = $message->getHeaders(); $this->assertCount($headerCount - 1, $headers); $this->assertFalse(isset($headers['Age'])); } public function testBody() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $initialMessage = $this->getMessage(); $original = clone $initialMessage; $stream = $this->buildStream('foo'); $message = $initialMessage->withBody($stream); $this->assertNotSameObject($initialMessage, $message); $this->assertEquals($initialMessage, $original, 'Message object MUST not be mutated'); $this->assertEquals($stream, $message->getBody()); } } psr7-integration-tests-master/src/RequestIntegrationTest.php000066400000000000000000000120161343174516300247260ustar00rootroot00000000000000 */ abstract class RequestIntegrationTest extends BaseTest { use MessageTrait; /** * @var array with functionName => reason */ protected $skippedTests = []; /** * @var RequestInterface */ private $request; /** * @return RequestInterface that is used in the tests */ abstract public function createSubject(); protected function setUp() { $this->request = $this->createSubject(); } protected function getMessage() { return $this->request; } public function testRequestTarget() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $original = clone $this->request; $this->assertEquals('/', $this->request->getRequestTarget()); $request = $this->request->withRequestTarget('*'); $this->assertNotSameObject($this->request, $request); $this->assertEquals($this->request, $original, 'Request object MUST not be mutated'); $this->assertEquals('*', $request->getRequestTarget()); } public function testMethod() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->assertEquals('GET', $this->request->getMethod()); $original = clone $this->request; $request = $this->request->withMethod('POST'); $this->assertNotSameObject($this->request, $request); $this->assertEquals($this->request, $original, 'Request object MUST not be mutated'); $this->assertEquals('POST', $request->getMethod()); $request = $this->request->withMethod('head'); $this->assertEquals('head', $request->getMethod()); } /** * @dataProvider getInvalidMethods */ public function testMethodWithInvalidArguments($method) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->expectException(\InvalidArgumentException::class); $this->request->withMethod($method); } public function getInvalidMethods() { return [ [null], [1], [1.01], [false], [['foo']], [new \stdClass()], ]; } public function testUri() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $original = clone $this->request; $this->assertInstanceOf(UriInterface::class, $this->request->getUri()); $uri = $this->buildUri('http://www.foo.com/bar'); $request = $this->request->withUri($uri); $this->assertNotSameObject($this->request, $request); $this->assertEquals($this->request, $original, 'Request object MUST not be mutated'); $this->assertEquals('www.foo.com', $request->getHeaderLine('host')); $this->assertInstanceOf(UriInterface::class, $request->getUri()); $this->assertEquals('http://www.foo.com/bar', (string) $request->getUri()); $request = $request->withUri($this->buildUri('/foobar')); $this->assertNotSameObject($this->request, $request); $this->assertEquals($this->request, $original, 'Request object MUST not be mutated'); $this->assertEquals('www.foo.com', $request->getHeaderLine('host'), 'If the URI does not contain a host component, any pre-existing Host header MUST be carried over to the returned request.'); $this->assertEquals('/foobar', (string) $request->getUri()); } public function testUriPreserveHost_NoHost_Host() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $request = $this->request->withUri($this->buildUri('http://www.foo.com/bar'), true); $this->assertEquals('www.foo.com', $request->getHeaderLine('host')); } public function testUriPreserveHost_NoHost_NoHost() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $host = $this->request->getHeaderLine('host'); $request = $this->request->withUri($this->buildUri('/bar'), true); $this->assertEquals($host, $request->getHeaderLine('host')); } public function testUriPreserveHost_Host_Host() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $request = $this->request->withUri($this->buildUri('http://www.foo.com/bar')); $host = $request->getHeaderLine('host'); $request2 = $request->withUri($this->buildUri('http://www.bar.com/foo'), true); $this->assertEquals($host, $request2->getHeaderLine('host')); } } psr7-integration-tests-master/src/ResponseIntegrationTest.php000066400000000000000000000042101343174516300250710ustar00rootroot00000000000000 */ abstract class ResponseIntegrationTest extends BaseTest { use MessageTrait; /** * @var array with functionName => reason */ protected $skippedTests = []; /** * @var ResponseInterface */ private $response; /** * @return ResponseInterface that is used in the tests */ abstract public function createSubject(); protected function setUp() { $this->response = $this->createSubject(); } protected function getMessage() { return $this->response; } public function testStatusCode() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $original = clone $this->response; $response = $this->response->withStatus(204); $this->assertNotSameObject($this->response, $response); $this->assertEquals($this->response, $original, 'Response MUST not be mutated'); $this->assertSame(204, $response->getStatusCode()); } /** * @dataProvider getInvalidStatusCodeArguments */ public function testStatusCodeInvalidArgument($statusCode) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->expectException(\InvalidArgumentException::class); $this->response->withStatus($statusCode); } public function getInvalidStatusCodeArguments() { return [ [true], ['foobar'], [99], [600], [200.34], [new \stdClass()], ]; } public function testReasonPhrase() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $response = $this->response->withStatus(204, 'Foobar'); $this->assertSame(204, $response->getStatusCode()); $this->assertEquals('Foobar', $response->getReasonPhrase()); } } psr7-integration-tests-master/src/ServerRequestIntegrationTest.php000066400000000000000000000130751343174516300261230ustar00rootroot00000000000000 */ abstract class ServerRequestIntegrationTest extends BaseTest { /** * @var array with functionName => reason */ protected $skippedTests = []; /** * @var ServerRequestInterface */ private $serverRequest; /** * @return ServerRequestInterface that is used in the tests */ abstract public function createSubject(); protected function setUp() { $this->serverRequest = $this->createSubject(); } public function testGetServerParams() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->assertEquals($_SERVER, $this->serverRequest->getServerParams()); } public function testGetCookieParams() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->assertEquals($_COOKIE, $this->serverRequest->getCookieParams()); } public function testWithCookieParams() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $orgCookie = $_COOKIE; $new = $this->serverRequest->withCookieParams(['foo' => 'bar']); $this->assertEquals($orgCookie, $this->serverRequest->getCookieParams(), 'Super global $_COOKIE MUST NOT change.'); $this->assertNotEquals($orgCookie, $new->getCookieParams()); $this->assertArrayHasKey('foo', $new->getCookieParams()); } public function testGetQueryParams() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $new = $this->serverRequest->withQueryParams(['foo' => 'bar']); $this->assertEmpty($this->serverRequest->getQueryParams(), 'withQueryParams MUST be immutable'); $this->assertArrayHasKey('foo', $new->getQueryParams()); } public function testGetUploadedFiles() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $file = $this->buildUploadableFile('foo'); $new = $this->serverRequest->withUploadedFiles([$file]); $this->assertEmpty($this->serverRequest->getUploadedFiles(), 'withUploadedFiles MUST be immutable'); $files = $new->getUploadedFiles(); $this->assertCount(1, $files); $this->assertEquals($file, $files[0]); } /** * @dataProvider validParsedBodyParams */ public function testGetParsedBody($value) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $new = $this->serverRequest->withParsedBody($value); $this->assertNull($this->serverRequest->getParsedBody(), 'withParsedBody MUST be immutable'); $this->assertEquals($value, $new->getParsedBody()); } public function validParsedBodyParams() { return [ [null], [new \stdClass()], [['foo' => 'bar', 'baz']], ]; } /** * @dataProvider invalidParsedBodyParams * @expectedException \InvalidArgumentException */ public function testGetParsedBodyInvalid($value) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $new = $this->serverRequest->withParsedBody($value); $this->assertNull($this->serverRequest->getParsedBody(), 'withParsedBody MUST be immutable'); $this->assertEquals($value, $new->getParsedBody()); } public function invalidParsedBodyParams() { return [ [4711], [47.11], ['foobar'], [true], ]; } public function testGetAttributes() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $new = $this->serverRequest->withAttribute('foo', 'bar'); $oldAttributes = $this->serverRequest->getAttributes(); $this->assertInternalType('array', $oldAttributes, 'getAttributes MUST return an array'); $this->assertEmpty($oldAttributes, 'withAttribute MUST be immutable'); $this->assertEquals(['foo' => 'bar'], $new->getAttributes()); $new = $new->withAttribute('baz', 'biz'); $this->assertEquals(['foo' => 'bar', 'baz' => 'biz'], $new->getAttributes()); } public function testGetAttribute() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $new = $this->serverRequest->withAttribute('foo', 'bar'); $this->assertEquals('bar', $new->getAttribute('foo')); $this->assertEquals('baz', $new->getAttribute('not found', 'baz')); $this->assertNull($new->getAttribute('not found')); } public function testWithoutAttribute() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $with = $this->serverRequest->withAttribute('foo', 'bar'); $without = $with->withoutAttribute('foo'); $this->assertEquals('bar', $with->getAttribute('foo'), 'withoutAttribute MUST be immutable'); $this->assertNull($without->getAttribute('foo')); } } psr7-integration-tests-master/src/StreamIntegrationTest.php000066400000000000000000000214731343174516300245400ustar00rootroot00000000000000 */ abstract class StreamIntegrationTest extends BaseTest { /** * @var array with functionName => reason */ protected $skippedTests = []; /** * @param string|resource|StreamInterface $data * * @return StreamInterface */ abstract public function createStream($data); public function testToStringReadOnlyStreams() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen(__FILE__, 'r'); $stream = $this->createStream($resource); // Make sure this does not throw exception $content = (string) $stream; $this->assertNotEmpty($content, 'You MUST be able to convert a read only stream to string'); } public function testToStringRewindStreamBeforeToString() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); fseek($resource, 3); $stream = $this->createStream($resource); $content = (string) $stream; $this->assertEquals('abcdef', $content); } public function testClose() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); $stream = $this->createStream($resource); $this->assertTrue(is_resource($resource)); $stream->close(); $this->assertFalse(is_resource($resource)); } public function testDetach() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abc'); $stream = $this->createStream($resource); $this->assertEquals($resource, $stream->detach()); } public function testGetSize() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abc'); $stream = $this->createStream($resource); $this->assertEquals(3, $stream->getSize()); } public function testTell() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); $stream = $this->createStream($resource); $this->assertSame(6, $stream->tell()); $stream->seek(0); $this->assertSame(0, $stream->tell()); $stream->seek(3); $this->assertSame(3, $stream->tell()); $stream->seek(6); $this->assertSame(6, $stream->tell()); } public function testEof() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); $stream = $this->createStream($resource); $stream->seek(0); $this->assertFalse($stream->eof()); $stream->read(20); $stream->read(10); $this->assertTrue($stream->eof()); } public function testIsSeekable() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); $stream = $this->createStream($resource); $this->assertTrue($stream->isSeekable()); } /** * @group internet */ public function testIsNotSeekable() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; $resource = fopen($url, 'r'); $stream = $this->createStream($resource); $this->assertFalse($stream->isSeekable()); } public function testIsWritable() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); $stream = $this->createStream($resource); $this->assertTrue($stream->isWritable()); } /** * @group internet */ public function testIsNotWritable() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; $resource = fopen($url, 'r'); $stream = $this->createStream($resource); $this->assertFalse($stream->isWritable()); } public function testIsReadable() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); $stream = $this->createStream($resource); $this->assertTrue($stream->isReadable()); } /** * @group internet */ public function testIsNotReadable() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; $resource = fopen($url, 'r'); $stream = $this->createStream($resource); $this->assertTrue($stream->isReadable()); } public function testSeek() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); $stream = $this->createStream($resource); $stream->seek(3); $this->assertEquals('def', fread($resource, 3)); } public function testRewind() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); $stream = $this->createStream($resource); $stream->rewind(); $this->assertEquals('abcdef', fread($resource, 6)); } /** * @group internet * @expectedException \RuntimeException */ public function testRewindNotSeekable() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; $resource = fopen($url, 'r'); $stream = $this->createStream($resource); $stream->rewind(); } public function testWrite() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abc'); $stream = $this->createStream($resource); $bytes = $stream->write('def'); $this->assertSame(3, $bytes); $this->assertEquals('abcdef', (string) $stream); } public function testRead() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); $stream = $this->createStream($resource); $stream->rewind(); $data = $stream->read(3); $this->assertEquals('abc', $data); $data = $stream->read(10); $this->assertEquals('def', $data); } public function testGetContents() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); $stream = $this->createStream($resource); $stream->rewind(); $stream->seek(3); $this->assertEquals('def', $stream->getContents()); $this->assertSame('', $stream->getContents()); } } psr7-integration-tests-master/src/UploadedFileIntegrationTest.php000066400000000000000000000102061343174516300256320ustar00rootroot00000000000000 */ abstract class UploadedFileIntegrationTest extends BaseTest { /** * @var array with functionName => reason */ protected $skippedTests = []; /** * @var UploadedFileInterface */ private $uploadedFile; /** * @return UploadedFileInterface that is used in the tests */ abstract public function createSubject(); public static function setUpBeforeClass() { @mkdir('.tmp'); parent::setUpBeforeClass(); } protected function setUp() { $this->uploadedFile = $this->createSubject(); } public function testGetStream() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $file = $this->createSubject(); $stream = $file->getStream(); $this->assertTrue($stream instanceof StreamInterface); } public function testGetStreamAfterMoveTo() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $file = $this->createSubject(); $this->expectException(\RuntimeException::class); $file->moveTo(sys_get_temp_dir().'/foo'); $file->getStream(); } public function testMoveToAbsolute() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $file = $this->createSubject(); $targetPath = sys_get_temp_dir().'/'.uniqid('foo', true); $this->assertFalse(is_file($targetPath)); $file->moveTo($targetPath); $this->assertTrue(is_file($targetPath)); } public function testMoveToRelative() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $file = $this->createSubject(); $targetPath = '.tmp/'.uniqid('foo', true); $this->assertFalse(is_file($targetPath)); $file->moveTo($targetPath); $this->assertTrue(is_file($targetPath)); } public function testMoveToTwice() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->expectException(\RuntimeException::class); $file = $this->createSubject(); $file->moveTo('.tmp/'.uniqid('foo', true)); $file->moveTo('.tmp/'.uniqid('foo', true)); } public function testGetSize() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $file = $this->createSubject(); $size = $file->getSize(); if ($size) { $this->assertRegExp('|^[0-9]+$|', (string) $size); } else { $this->assertNull($size); } } public function testGetError() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $file = $this->createSubject(); $this->assertEquals(UPLOAD_ERR_OK, $file->getError()); } public function testGetClientFilename() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $file = $this->createSubject(); $name = $file->getClientFilename(); if ($name) { $this->assertTrue(is_string($name)); } else { $this->assertNull($name); } } public function testGetClientMediaType() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $file = $this->createSubject(); $type = $file->getClientMediaType(); if ($type) { $this->assertTrue(is_string($type)); } else { $this->assertNull($type); } } } psr7-integration-tests-master/src/UriIntegrationTest.php000066400000000000000000000151371343174516300240440ustar00rootroot00000000000000 */ abstract class UriIntegrationTest extends BaseTest { /** * @var array with functionName => reason */ protected $skippedTests = []; /** * @param string $uri * * @return UriInterface */ abstract public function createUri($uri); public function testScheme() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $uri = $this->createUri('/'); $this->assertSame('', $uri->getScheme()); $uri = $this->createUri('https://foo.com/'); $this->assertEquals('https', $uri->getScheme()); $newUri = $uri->withScheme('http'); $this->assertNotSameObject($uri, $newUri); $this->assertEquals('http', $newUri->getScheme()); } /** * @dataProvider getInvalidSchemaArguments */ public function testWithSchemeInvalidArguments($schema) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->expectException(\InvalidArgumentException::class); $this->createUri('/')->withScheme($schema); } public function getInvalidSchemaArguments() { return [ [true], [['foobar']], [34], [new \stdClass()], ]; } public function testAuthority() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $uri = $this->createUri('/'); $this->assertEquals('', $uri->getAuthority()); $uri = $this->createUri('http://foo@bar.com:80/'); $this->assertEquals('foo@bar.com', $uri->getAuthority()); $uri = $this->createUri('http://foo@bar.com:81/'); $this->assertEquals('foo@bar.com:81', $uri->getAuthority()); $uri = $this->createUri('http://user:foo@bar.com/'); $this->assertEquals('user:foo@bar.com', $uri->getAuthority()); } public function testUserInfo() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $uri = $this->createUri('/'); $this->assertEquals('', $uri->getUserInfo()); $uri = $this->createUri('http://user:foo@bar.com/'); $this->assertEquals('user:foo', $uri->getUserInfo()); $uri = $this->createUri('http://foo@bar.com/'); $this->assertEquals('foo', $uri->getUserInfo()); } public function testHost() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $uri = $this->createUri('/'); $this->assertSame('', $uri->getHost()); $uri = $this->createUri('http://www.foo.com/'); $this->assertEquals('www.foo.com', $uri->getHost()); $uri = $this->createUri('http://FOOBAR.COM/'); $this->assertEquals('foobar.com', $uri->getHost()); } public function testPort() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $uri = $this->createUri('http://www.foo.com/'); $this->assertNull($uri->getPort()); $uri = $this->createUri('http://www.foo.com:80/'); $this->assertNull($uri->getPort()); $uri = $this->createUri('https://www.foo.com:443/'); $this->assertNull($uri->getPort()); $uri = $this->createUri('http://www.foo.com:81/'); $this->assertSame(81, $uri->getPort()); } /** * @dataProvider getPaths */ public function testPath(UriInterface $uri, $expected) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->assertSame($expected, $uri->getPath()); } public function getPaths() { return [ [$this->createUri('http://www.foo.com/'), '/'], [$this->createUri('http://www.foo.com'), ''], [$this->createUri('foo/bar'), 'foo/bar'], [$this->createUri('http://www.foo.com/foo bar'), '/foo%20bar'], [$this->createUri('http://www.foo.com/foo%20bar'), '/foo%20bar'], [$this->createUri('http://www.foo.com/foo%2fbar'), '/foo%2fbar'], ]; } /** * @dataProvider getQueries */ public function testQuery(UriInterface $uri, $expected) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->assertSame($expected, $uri->getQuery()); } public function getQueries() { return [ [$this->createUri('http://www.foo.com'), ''], [$this->createUri('http://www.foo.com?'), ''], [$this->createUri('http://www.foo.com?foo=bar'), 'foo=bar'], [$this->createUri('http://www.foo.com?foo=bar%26baz'), 'foo=bar%26baz'], [$this->createUri('http://www.foo.com?foo=bar&baz=biz'), 'foo=bar&baz=biz'], ]; } /** * @dataProvider getFragments */ public function testFragment(UriInterface $uri, $expected) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $this->assertEquals($expected, $uri->getFragment()); } public function getFragments() { return [ [$this->createUri('http://www.foo.com'), ''], [$this->createUri('http://www.foo.com#'), ''], [$this->createUri('http://www.foo.com#foo'), 'foo'], [$this->createUri('http://www.foo.com#foo%20bar'), 'foo%20bar'], ]; } public function testUriModification1() { $expected = 'https://0:0@0:1/0?0#0'; $uri = $this->createUri($expected); $this->assertInstanceOf(UriInterface::class, $uri); $this->assertSame($expected, (string) $uri); } public function testUriModification2() { $expected = 'https://0:0@0:1/0?0#0'; $uri = $this ->createUri('') ->withHost('0') ->withPort(1) ->withUserInfo('0', '0') ->withScheme('https') ->withPath('/0') ->withQuery('0') ->withFragment('0') ; $this->assertInstanceOf(UriInterface::class, $uri); $this->assertSame($expected, (string) $uri); } }