From 95c3be85c9dfb20f016936f44f474e540e22b60d Mon Sep 17 00:00:00 2001 From: PJ Dietz Date: Sun, 16 Aug 2020 10:47:39 -0400 Subject: [PATCH] Create implementations for PSR-17 Response- and StreamFactoryInterface --- composer.json | 3 +- composer.lock | 526 +++++++++++++------------- phpunit.xml.dist | 17 +- src/Message/ResponseFactory.php | 27 ++ src/Message/ServerRequest.php | 2 +- src/Message/StreamFactory.php | 53 +++ tests/Message/ResponseFactoryTest.php | 44 +++ tests/Message/StreamFactoryTest.php | 95 +++++ 8 files changed, 493 insertions(+), 274 deletions(-) create mode 100644 src/Message/ResponseFactory.php create mode 100644 src/Message/StreamFactory.php create mode 100644 tests/Message/ResponseFactoryTest.php create mode 100644 tests/Message/StreamFactoryTest.php diff --git a/composer.json b/composer.json index ab39b4b..1a7446c 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "wellrested/wellrested", "description": "Simple PHP Library for RESTful APIs", - "keywords": ["rest", "restful", "api", "http", "psr7", "psr-7", "psr15", "psr-15"], + "keywords": ["rest", "restful", "api", "http", "psr7", "psr-7", "psr15", "psr-15", "psr17", "psr-17"], "homepage": "https://www.wellrested.org", "license": "MIT", "type": "library", @@ -13,6 +13,7 @@ ], "require": { "php": ">=7.2", + "psr/http-factory": "~1.0", "psr/http-message": "~1.0", "psr/http-server-handler": "~1.0", "psr/http-server-middleware": "~1.0" diff --git a/composer.lock b/composer.lock index 02cddea..6f27dbc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,60 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4d35c0aa434d9f710cd5a8a7246367d4", + "content-hash": "041c27e394aba3e5c3bf6cbe8751f845", "packages": [ + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "time": "2019-04-30T12:38:16+00:00" + }, { "name": "psr/http-message", "version": "1.0.1", @@ -314,6 +366,75 @@ ], "time": "2020-06-29T18:35:05+00:00" }, + { + "name": "composer/package-versions-deprecated", + "version": "1.10.99.1", + "source": { + "type": "git", + "url": "https://github.com/composer/package-versions-deprecated.git", + "reference": "68c9b502036e820c33445ff4d174327f6bb87486" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/68c9b502036e820c33445ff4d174327f6bb87486", + "reference": "68c9b502036e820c33445ff4d174327f6bb87486", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.1.0 || ^2.0", + "php": "^7 || ^8" + }, + "replace": { + "ocramius/package-versions": "1.10.99" + }, + "require-dev": { + "composer/composer": "^1.9.3 || ^2.0@dev", + "ext-zip": "^1.13", + "phpunit/phpunit": "^6.5 || ^7" + }, + "type": "composer-plugin", + "extra": { + "class": "PackageVersions\\Installer", + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "PackageVersions\\": "src/PackageVersions" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be" + } + ], + "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2020-08-13T12:55:41+00:00" + }, { "name": "composer/semver", "version": "1.5.1", @@ -435,16 +556,16 @@ }, { "name": "doctrine/annotations", - "version": "1.10.3", + "version": "1.10.4", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "5db60a4969eba0e0c197a19c077780aadbc43c5d" + "reference": "bfe91e31984e2ba76df1c1339681770401ec262f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/5db60a4969eba0e0c197a19c077780aadbc43c5d", - "reference": "5db60a4969eba0e0c197a19c077780aadbc43c5d", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/bfe91e31984e2ba76df1c1339681770401ec262f", + "reference": "bfe91e31984e2ba76df1c1339681770401ec262f", "shasum": "" }, "require": { @@ -454,7 +575,8 @@ }, "require-dev": { "doctrine/cache": "1.*", - "phpunit/phpunit": "^7.5" + "phpstan/phpstan": "^0.12.20", + "phpunit/phpunit": "^7.5 || ^9.1.5" }, "type": "library", "extra": { @@ -500,7 +622,7 @@ "docblock", "parser" ], - "time": "2020-05-25T17:24:27+00:00" + "time": "2020-08-10T19:35:50+00:00" }, { "name": "doctrine/instantiator", @@ -935,16 +1057,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.8.0", + "version": "v4.6.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "8c58eb4cd4f3883f82611abeac2efbc3dbed787e" + "reference": "c346bbfafe2ff60680258b631afb730d186ed864" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/8c58eb4cd4f3883f82611abeac2efbc3dbed787e", - "reference": "8c58eb4cd4f3883f82611abeac2efbc3dbed787e", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/c346bbfafe2ff60680258b631afb730d186ed864", + "reference": "c346bbfafe2ff60680258b631afb730d186ed864", "shasum": "" }, "require": { @@ -952,8 +1074,8 @@ "php": ">=7.0" }, "require-dev": { - "ircmaxell/php-yacc": "^0.0.6", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "ircmaxell/php-yacc": "0.0.5", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0" }, "bin": [ "bin/php-parse" @@ -961,7 +1083,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.8-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -983,68 +1105,7 @@ "parser", "php" ], - "time": "2020-08-09T10:23:20+00:00" - }, - { - "name": "ocramius/package-versions", - "version": "1.9.0", - "source": { - "type": "git", - "url": "https://github.com/Ocramius/PackageVersions.git", - "reference": "94c9d42a466c57f91390cdd49c81313264f49d85" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/94c9d42a466c57f91390cdd49c81313264f49d85", - "reference": "94c9d42a466c57f91390cdd49c81313264f49d85", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.1.0 || ^2.0", - "php": "^7.4.0" - }, - "require-dev": { - "composer/composer": "^1.9.3 || ^2.0@dev", - "doctrine/coding-standard": "^7.0.2", - "ext-zip": "^1.15.0", - "infection/infection": "^0.15.3", - "phpunit/phpunit": "^9.1.1", - "vimeo/psalm": "^3.9.3" - }, - "type": "composer-plugin", - "extra": { - "class": "PackageVersions\\Installer", - "branch-alias": { - "dev-master": "1.99.x-dev" - } - }, - "autoload": { - "psr-4": { - "PackageVersions\\": "src/PackageVersions" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com" - } - ], - "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", - "funding": [ - { - "url": "https://github.com/Ocramius", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/ocramius/package-versions", - "type": "tidelift" - } - ], - "time": "2020-06-22T14:15:44+00:00" + "time": "2020-07-02T17:12:47+00:00" }, { "name": "openlss/lib-array2xml", @@ -1142,29 +1203,28 @@ }, { "name": "phar-io/manifest", - "version": "2.0.1", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133" + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", "shasum": "" }, "require": { "ext-dom": "*", "ext-phar": "*", - "ext-xmlwriter": "*", - "phar-io/version": "^3.0.1", - "php": "^7.2 || ^8.0" + "phar-io/version": "^2.0", + "php": "^5.6 || ^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { @@ -1194,24 +1254,24 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "time": "2020-06-27T14:33:11+00:00" + "time": "2018-07-08T19:23:20+00:00" }, { "name": "phar-io/version", - "version": "3.0.2", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "c6bb6825def89e0a32220f88337f8ceaf1975fa0" + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/c6bb6825def89e0a32220f88337f8ceaf1975fa0", - "reference": "c6bb6825def89e0a32220f88337f8ceaf1975fa0", + "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0" + "php": "^5.6 || ^7.0" }, "type": "library", "autoload": { @@ -1241,7 +1301,7 @@ } ], "description": "Library for handling version information and constraints", - "time": "2020-06-27T14:39:04+00:00" + "time": "2018-07-08T19:19:57+00:00" }, { "name": "php-cs-fixer/diff", @@ -1345,16 +1405,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.2.0", + "version": "5.2.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "3170448f5769fe19f456173d833734e0ff1b84df" + "reference": "d870572532cd70bc3fab58f2e23ad423c8404c44" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/3170448f5769fe19f456173d833734e0ff1b84df", - "reference": "3170448f5769fe19f456173d833734e0ff1b84df", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d870572532cd70bc3fab58f2e23ad423c8404c44", + "reference": "d870572532cd70bc3fab58f2e23ad423c8404c44", "shasum": "" }, "require": { @@ -1393,7 +1453,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2020-07-20T20:05:34+00:00" + "time": "2020-08-15T11:14:08+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -1553,35 +1613,32 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.1.2", + "version": "8.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "5210f9269e44e6d34419cb92242ef11aee9351ac" + "reference": "ca6647ffddd2add025ab3f21644a441d7c146cdc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/5210f9269e44e6d34419cb92242ef11aee9351ac", - "reference": "5210f9269e44e6d34419cb92242ef11aee9351ac", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ca6647ffddd2add025ab3f21644a441d7c146cdc", + "reference": "ca6647ffddd2add025ab3f21644a441d7c146cdc", "shasum": "" }, "require": { "ext-dom": "*", - "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.7", - "php": "^7.3 || ^8.0", - "phpunit/php-file-iterator": "^3.0.3", - "phpunit/php-text-template": "^2.0.2", - "sebastian/code-unit-reverse-lookup": "^2.0.2", - "sebastian/complexity": "^2.0", - "sebastian/environment": "^5.1.2", - "sebastian/lines-of-code": "^1.0", - "sebastian/version": "^3.0.1", - "theseer/tokenizer": "^1.2.0" + "php": "^7.3", + "phpunit/php-file-iterator": "^3.0", + "phpunit/php-text-template": "^2.0", + "phpunit/php-token-stream": "^4.0", + "sebastian/code-unit-reverse-lookup": "^2.0", + "sebastian/environment": "^5.0", + "sebastian/version": "^3.0", + "theseer/tokenizer": "^1.1.3" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^9.0" }, "suggest": { "ext-pcov": "*", @@ -1590,7 +1647,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.1-dev" + "dev-master": "8.0-dev" } }, "autoload": { @@ -1622,7 +1679,7 @@ "type": "github" } ], - "time": "2020-08-10T07:24:51+00:00" + "time": "2020-05-23T08:02:54+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1850,17 +1907,73 @@ "time": "2020-06-26T11:58:13+00:00" }, { - "name": "phpunit/phpunit", - "version": "9.3.5", + "name": "phpunit/php-token-stream", + "version": "4.0.4", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "7115b00b23bcd4f62a73855c9615694d2f206e71" + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "a853a0e183b9db7eed023d7933a858fa1c8d25a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7115b00b23bcd4f62a73855c9615694d2f206e71", - "reference": "7115b00b23bcd4f62a73855c9615694d2f206e71", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/a853a0e183b9db7eed023d7933a858fa1c8d25a3", + "reference": "a853a0e183b9db7eed023d7933a858fa1c8d25a3", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "abandoned": true, + "time": "2020-08-04T08:28:15+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "9.2.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "1c6a9e4312e209e659f1fce3ce88dd197c2448f6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1c6a9e4312e209e659f1fce3ce88dd197c2448f6", + "reference": "1c6a9e4312e209e659f1fce3ce88dd197c2448f6", "shasum": "" }, "require": { @@ -1871,30 +1984,30 @@ "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.1", - "phar-io/version": "^3.0.2", - "php": "^7.3 || ^8.0", - "phpspec/prophecy": "^1.11.1", - "phpunit/php-code-coverage": "^9.1.1", - "phpunit/php-file-iterator": "^3.0.4", - "phpunit/php-invoker": "^3.1", + "myclabs/deep-copy": "^1.9.5", + "phar-io/manifest": "^1.0.3", + "phar-io/version": "^2.0.1", + "php": "^7.3", + "phpspec/prophecy": "^1.10.3", + "phpunit/php-code-coverage": "^8.0.2", + "phpunit/php-file-iterator": "^3.0.3", + "phpunit/php-invoker": "^3.0.2", "phpunit/php-text-template": "^2.0.2", "phpunit/php-timer": "^5.0.1", "sebastian/code-unit": "^1.0.5", "sebastian/comparator": "^4.0.3", - "sebastian/diff": "^4.0.2", + "sebastian/diff": "^4.0.1", "sebastian/environment": "^5.1.2", "sebastian/exporter": "^4.0.2", - "sebastian/global-state": "^5.0", + "sebastian/global-state": "^4.0", "sebastian/object-enumerator": "^4.0.2", "sebastian/resource-operations": "^3.0.2", - "sebastian/type": "^2.2.1", + "sebastian/type": "^2.1.1", "sebastian/version": "^3.0.1" }, "require-dev": { "ext-pdo": "*", - "phpspec/prophecy-phpunit": "^2.0.1" + "phpspec/prophecy-phpunit": "^2.0" }, "suggest": { "ext-soap": "*", @@ -1906,7 +2019,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.3-dev" + "dev-master": "9.2-dev" } }, "autoload": { @@ -1945,7 +2058,7 @@ "type": "github" } ], - "time": "2020-08-10T06:50:08+00:00" + "time": "2020-07-13T17:55:55+00:00" }, { "name": "psr/container", @@ -2262,59 +2375,6 @@ ], "time": "2020-06-26T12:05:46+00:00" }, - { - "name": "sebastian/complexity", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/complexity.git", - "reference": "33fcd6a26656c6546f70871244ecba4b4dced097" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/33fcd6a26656c6546f70871244ecba4b4dced097", - "reference": "33fcd6a26656c6546f70871244ecba4b4dced097", - "shasum": "" - }, - "require": { - "nikic/php-parser": "^4.7", - "php": "^7.3 || ^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^9.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library for calculating the complexity of PHP code units", - "homepage": "https://github.com/sebastianbergmann/complexity", - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2020-07-25T14:01:34+00:00" - }, { "name": "sebastian/diff", "version": "4.0.2", @@ -2511,26 +2571,26 @@ }, { "name": "sebastian/global-state", - "version": "5.0.0", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "22ae663c951bdc39da96603edc3239ed3a299097" + "reference": "bdb1e7c79e592b8c82cb1699be3c8743119b8a72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/22ae663c951bdc39da96603edc3239ed3a299097", - "reference": "22ae663c951bdc39da96603edc3239ed3a299097", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bdb1e7c79e592b8c82cb1699be3c8743119b8a72", + "reference": "bdb1e7c79e592b8c82cb1699be3c8743119b8a72", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0", + "php": "^7.3", "sebastian/object-reflector": "^2.0", "sebastian/recursion-context": "^4.0" }, "require-dev": { "ext-dom": "*", - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^9.0" }, "suggest": { "ext-uopz": "*" @@ -2538,7 +2598,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.0-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -2561,66 +2621,7 @@ "keywords": [ "global state" ], - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2020-08-07T04:09:03+00:00" - }, - { - "name": "sebastian/lines-of-code", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "e02bf626f404b5daec382a7b8a6a4456e49017e5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e02bf626f404b5daec382a7b8a6a4456e49017e5", - "reference": "e02bf626f404b5daec382a7b8a6a4456e49017e5", - "shasum": "" - }, - "require": { - "nikic/php-parser": "^4.6", - "php": "^7.3 || ^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^9.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library for counting the lines of code in PHP source code", - "homepage": "https://github.com/sebastianbergmann/lines-of-code", - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2020-07-22T18:33:42+00:00" + "time": "2020-02-07T06:11:37+00:00" }, { "name": "sebastian/object-enumerator", @@ -4408,21 +4409,22 @@ }, { "name": "vimeo/psalm", - "version": "3.12.2", + "version": "3.13.1", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "7c7ebd068f8acaba211d4a2c707c4ba90874fa26" + "reference": "afd8874a9e4562eac42a02de90e42e430c3a1db1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/7c7ebd068f8acaba211d4a2c707c4ba90874fa26", - "reference": "7c7ebd068f8acaba211d4a2c707c4ba90874fa26", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/afd8874a9e4562eac42a02de90e42e430c3a1db1", + "reference": "afd8874a9e4562eac42a02de90e42e430c3a1db1", "shasum": "" }, "require": { "amphp/amp": "^2.1", "amphp/byte-stream": "^1.5", + "composer/package-versions-deprecated": "^1.8.0", "composer/semver": "^1.4 || ^2.0 || ^3.0", "composer/xdebug-handler": "^1.1", "ext-dom": "*", @@ -4432,9 +4434,8 @@ "ext-tokenizer": "*", "felixfbecker/advanced-json-rpc": "^3.0.3", "felixfbecker/language-server-protocol": "^1.4", - "netresearch/jsonmapper": "^1.0 || ^2.0", - "nikic/php-parser": "^4.3", - "ocramius/package-versions": "^1.2", + "netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0", + "nikic/php-parser": "4.3.* || 4.4.* || 4.5.* || 4.6.*", "openlss/lib-array2xml": "^1.0", "php": "^7.1.3|^8", "sebastian/diff": "^3.0 || ^4.0", @@ -4450,7 +4451,6 @@ "bamarni/composer-bin-plugin": "^1.2", "brianium/paratest": "^4.0.0", "ext-curl": "*", - "php-coveralls/php-coveralls": "^2.2", "phpmyadmin/sql-parser": "5.1.0", "phpspec/prophecy": ">=1.9.0", "phpunit/phpunit": "^7.5.16 || ^8.5 || ^9.0", @@ -4501,7 +4501,7 @@ "inspection", "php" ], - "time": "2020-07-03T16:59:07+00:00" + "time": "2020-07-30T19:42:34+00:00" }, { "name": "webmozart/assert", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 08b894e..662994b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,18 +9,17 @@ stopOnFailure="false" verbose="true" > - - - ./src - - - - - ./tests - + + + ./src + + + + + diff --git a/src/Message/ResponseFactory.php b/src/Message/ResponseFactory.php new file mode 100644 index 0000000..414d891 --- /dev/null +++ b/src/Message/ResponseFactory.php @@ -0,0 +1,27 @@ +withStatus($code, $reasonPhrase); + } +} diff --git a/src/Message/ServerRequest.php b/src/Message/ServerRequest.php index 6ec61aa..e61ffc8 100644 --- a/src/Message/ServerRequest.php +++ b/src/Message/ServerRequest.php @@ -76,7 +76,7 @@ class ServerRequest extends Request implements ServerRequestInterface array $headers = [], ?StreamInterface $body = null, array $serverParams = [] - ){ + ) { parent::__construct($method, $uri, $headers, $body); $this->serverParams = $serverParams; $this->cookieParams = []; diff --git a/src/Message/StreamFactory.php b/src/Message/StreamFactory.php new file mode 100644 index 0000000..0acda40 --- /dev/null +++ b/src/Message/StreamFactory.php @@ -0,0 +1,53 @@ +createResponse(); + + $this->assertEquals($statusCode, $response->getStatusCode()); + $this->assertEquals($reasonPhrase, $response->getReasonPhrase()); + } + + public function testCreateResponseWithStatusCode(): void + { + $statusCode = 201; + $reasonPhrase = 'Created'; + + $factory = new ResponseFactory(); + $response = $factory->createResponse($statusCode); + + $this->assertEquals($statusCode, $response->getStatusCode()); + $this->assertEquals($reasonPhrase, $response->getReasonPhrase()); + } + + public function testCreateResponseWithStatusCodeAndCustomReasonPhrase(): void + { + $statusCode = 512; + $reasonPhrase = 'Shortage of Chairs'; + + $factory = new ResponseFactory(); + $response = $factory->createResponse($statusCode, $reasonPhrase); + + $this->assertEquals($statusCode, $response->getStatusCode()); + $this->assertEquals($reasonPhrase, $response->getReasonPhrase()); + } +} diff --git a/tests/Message/StreamFactoryTest.php b/tests/Message/StreamFactoryTest.php new file mode 100644 index 0000000..2517d76 --- /dev/null +++ b/tests/Message/StreamFactoryTest.php @@ -0,0 +1,95 @@ +tempPath = tempnam(sys_get_temp_dir(), 'test'); + file_put_contents($this->tempPath, self::CONTENT); + } + + protected function tearDown(): void + { + parent::tearDown(); + unlink($this->tempPath); + } + + // ------------------------------------------------------------------------- + + public function testCreatesStreamFromString(): void + { + $factory = new StreamFactory(); + $stream = $factory->createStream(self::CONTENT); + + $this->assertEquals(self::CONTENT, (string) $stream); + } + + public function testCreatesStreamFromFile(): void + { + $factory = new StreamFactory(); + $stream = $factory->createStreamFromFile($this->tempPath); + + $this->assertEquals(self::CONTENT, (string) $stream); + } + + public function testCreatesStreamFromFileWithModeRByDefault(): void + { + $factory = new StreamFactory(); + $stream = $factory->createStreamFromFile($this->tempPath); + + $mode = $stream->getMetadata('mode'); + $this->assertEquals('r', $mode); + } + + /** + * @dataProvider modeProvider + * @param string $mode + */ + public function testCreatesStreamFromFileWithPassedMode(string $mode): void + { + $factory = new StreamFactory(); + $stream = $factory->createStreamFromFile($this->tempPath, $mode); + + $actual = $stream->getMetadata('mode'); + $this->assertEquals($mode, $actual); + } + + public function modeProvider(): array + { + return [ + ['r'], + ['r+'], + ['w'], + ['w+'] + ]; + } + + public function testCreateStreamFromFileThrowsRuntimeExceptionWhenUnableToOpenFile(): void + { + $this->expectException(RuntimeException::class); + + $factory = new StreamFactory(); + @$factory->createStreamFromFile('/dev/null/not-a-file', 'w'); + } + + public function testCreatesStreamFromResource(): void + { + $f = fopen($this->tempPath, 'r'); + + $factory = new StreamFactory(); + $stream = $factory->createStreamFromResource($f); + + $this->assertEquals(self::CONTENT, (string) $stream); + } +}