From 1345b7eddbe544867f7b558d104735d92efddbd5 Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Sun, 10 Sep 2023 09:03:54 +0800 Subject: [PATCH] Refactorings - important curl and wget improvements - initial test coverage - setters and getters in Request classes - namespace fixes - some additions in README - docblocks and code-style --- .gitignore | 2 + README.md | 23 +- composer.json | 7 +- composer.lock | 1614 ++++++++++++++++- phpunit.xml | 26 + .../Abstract/AbstractConverter.php | 11 +- src/Converters/Abstract/AbstractRequest.php | 295 +++ .../ConvertFormat.php | 9 +- .../ConverterContract.php | 2 +- .../Curl/CurlConverter.php | 4 +- .../Curl/CurlRequest.php | 14 +- .../Http/HttpConverter.php | 4 +- .../Http/HttpRequest.php | 24 +- src/Converters/RequestContract.php | 153 ++ .../Wget/WgetConverter.php | 4 +- .../Wget/WgetRequest.php | 39 +- src/Exceptions/EmptyHttpVerbException.php | 11 + src/Exceptions/EmptyURLException.php | 11 + .../InvalidHttpVersionException.php | 11 + src/Exporters/Abstract/AbstractRequest.php | 222 --- src/Exporters/RequestContract.php | 19 - src/HttpVersions.php | 21 + src/Processor.php | 6 +- tests/AbstractRequestTest.php | 297 +++ tests/HttpRequestTest.php | 140 ++ tests/WgetRequestTest.php | 232 +++ 26 files changed, 2901 insertions(+), 300 deletions(-) create mode 100644 phpunit.xml rename src/{Exporters => Converters}/Abstract/AbstractConverter.php (95%) create mode 100644 src/Converters/Abstract/AbstractRequest.php rename src/{Exporters => Converters}/ConvertFormat.php (51%) rename src/{Exporters => Converters}/ConverterContract.php (84%) rename src/{Exporters => Converters}/Curl/CurlConverter.php (81%) rename src/{Exporters => Converters}/Curl/CurlRequest.php (80%) rename src/{Exporters => Converters}/Http/HttpConverter.php (81%) rename src/{Exporters => Converters}/Http/HttpRequest.php (60%) create mode 100644 src/Converters/RequestContract.php rename src/{Exporters => Converters}/Wget/WgetConverter.php (81%) rename src/{Exporters => Converters}/Wget/WgetRequest.php (52%) create mode 100644 src/Exceptions/EmptyHttpVerbException.php create mode 100644 src/Exceptions/EmptyURLException.php create mode 100644 src/Exceptions/InvalidHttpVersionException.php delete mode 100644 src/Exporters/Abstract/AbstractRequest.php delete mode 100644 src/Exporters/RequestContract.php create mode 100644 src/HttpVersions.php create mode 100644 tests/AbstractRequestTest.php create mode 100644 tests/HttpRequestTest.php create mode 100644 tests/WgetRequestTest.php diff --git a/.gitignore b/.gitignore index 9df34f8..46b5631 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /.idea /.vscode /vendor +.phpunit.result.cache +.phpunit.cache diff --git a/README.md b/README.md index 73d23a2..75e3c98 100644 --- a/README.md +++ b/README.md @@ -89,14 +89,25 @@ Example: --file ~/dir2/second.postman_collection.json \ --env ~/localhost.postman_environment.json \ -d ~/personal \ - -o ~/postman_export - + -o ~/postman_export ``` -### Notice -Make sure every (I mean _every_) collection (not collection file), its folders and/or requests has unique names. -If not, you can rename them in Postman or convert collections with similar names into different directories. -Otherwise converted files may be overwritten by each other. +### Notices + +1. Result of `pm-convert` execution is bunch of generated files. + Most likely they will contain errors such as not interpolated `{{variables}}` values (due to missed ones in collection), + wrong command format or `GET`s with bodies. + You must review any generated file before using. +2. Make sure every (I mean _every_) collection (not collection file), its folders and/or requests has unique names. + If not, you can rename them in Postman or convert collections with similar names into different directories. + Otherwise any generated file may be accidently overwritten by another one. + +## How to implement a new format + +1. Create new namespace in `./src/Converters` and name it according to format of your choice +2. Create two classes for converter and request object which extends `Converters\Abstract\Abstract{Converter, Request}` respectively +3. Change constants values in your new request class according to format you want to implement +4. Write your own logic in converter's `__toString()` method, write new methods and override abstract ones ## License diff --git a/composer.json b/composer.json index d144c19..8c5cf7c 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,7 @@ "php": "^8.1", "ext-json": "*" }, - "bin": [ - "pm-convert" - ], + "bin": ["pm-convert"], "autoload": { "psr-4": { "PmConverter\\": "src\\" @@ -30,5 +28,8 @@ "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true + }, + "require-dev": { + "phpunit/phpunit": "^10.3" } } diff --git a/composer.lock b/composer.lock index f95283c..a8349ce 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,1619 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b49bb03a97ad612632a24ebc59dfafcb", + "content-hash": "7d1dfd3f8475dd697f5d4bdab92776a2", "packages": [], - "packages-dev": [], + "packages-dev": [ + { + "name": "myclabs/deep-copy", + "version": "1.11.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3,<3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2023-03-08T13:26:56+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v4.17.1", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" + }, + "time": "2023-08-13T19:53:39+00:00" + }, + { + "name": "phar-io/manifest", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/2.0.3" + }, + "time": "2021-07-20T11:28:43+00:00" + }, + { + "name": "phar-io/version", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" + }, + "time": "2022-02-21T01:04:05+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "10.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "be1fe461fdc917de2a29a452ccf2657d325b443d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/be1fe461fdc917de2a29a452ccf2657d325b443d", + "reference": "be1fe461fdc917de2a29a452ccf2657d325b443d", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^4.15", + "php": ">=8.1", + "phpunit/php-file-iterator": "^4.0", + "phpunit/php-text-template": "^3.0", + "sebastian/code-unit-reverse-lookup": "^3.0", + "sebastian/complexity": "^3.0", + "sebastian/environment": "^6.0", + "sebastian/lines-of-code": "^2.0", + "sebastian/version": "^4.0", + "theseer/tokenizer": "^1.2.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.1" + }, + "suggest": { + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "10.1-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 that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-07-26T13:45:28+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "4.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "5647d65443818959172645e7ed999217360654b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/5647d65443818959172645e7ed999217360654b6", + "reference": "5647d65443818959172645e7ed999217360654b6", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.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": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-05-07T09:13:23+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^10.0" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.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": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/4.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:56:09+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/9f3d3709577a527025f55bcf0f7ab8052c8bb37d", + "reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.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": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:56:46+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "6.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d", + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.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": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/6.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:57:52+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "10.3.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "241ed4dd0db1c096984e62d414c4e1ac8d5dbff4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/241ed4dd0db1c096984e62d414c4e1ac8d5dbff4", + "reference": "241ed4dd0db1c096984e62d414c4e1ac8d5dbff4", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.10.1", + "phar-io/manifest": "^2.0.3", + "phar-io/version": "^3.0.2", + "php": ">=8.1", + "phpunit/php-code-coverage": "^10.1.1", + "phpunit/php-file-iterator": "^4.0", + "phpunit/php-invoker": "^4.0", + "phpunit/php-text-template": "^3.0", + "phpunit/php-timer": "^6.0", + "sebastian/cli-parser": "^2.0", + "sebastian/code-unit": "^2.0", + "sebastian/comparator": "^5.0", + "sebastian/diff": "^5.0", + "sebastian/environment": "^6.0", + "sebastian/exporter": "^5.0", + "sebastian/global-state": "^6.0.1", + "sebastian/object-enumerator": "^5.0", + "sebastian/recursion-context": "^5.0", + "sebastian/type": "^4.0", + "sebastian/version": "^4.0" + }, + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "10.3-dev" + } + }, + "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.3.3" + }, + "funding": [ + { + "url": "https://phpunit.de/sponsors.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2023-09-05T04:34:51+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/efdc130dbbbb8ef0b545a994fd811725c5282cae", + "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "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 parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/2.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:58:15+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "a81fee9eef0b7a76af11d121767abc44c104e503" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/a81fee9eef0b7a76af11d121767abc44c104e503", + "reference": "a81fee9eef0b7a76af11d121767abc44c104e503", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "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": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/2.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:58:43+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", + "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:59:15+00:00" + }, + { + "name": "sebastian/comparator", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "2db5010a484d53ebf536087a70b4a5423c102372" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2db5010a484d53ebf536087a70b4a5423c102372", + "reference": "2db5010a484d53ebf536087a70b4a5423c102372", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-mbstring": "*", + "php": ">=8.1", + "sebastian/diff": "^5.0", + "sebastian/exporter": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "security": "https://github.com/sebastianbergmann/comparator/security/policy", + "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-08-14T13:18:12+00:00" + }, + { + "name": "sebastian/complexity", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "e67d240970c9dc7ea7b2123a6d520e334dd61dc6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/e67d240970c9dc7ea7b2123a6d520e334dd61dc6", + "reference": "e67d240970c9dc7ea7b2123a6d520e334dd61dc6", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.10", + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.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", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "source": "https://github.com/sebastianbergmann/complexity/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:59:47+00:00" + }, + { + "name": "sebastian/diff", + "version": "5.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/912dc2fbe3e3c1e7873313cc801b100b6c68c87b", + "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/5.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-05-01T07:48:21+00:00" + }, + { + "name": "sebastian/environment", + "version": "6.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/43c751b41d74f96cbbd4e07b7aec9675651e2951", + "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "https://github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "security": "https://github.com/sebastianbergmann/environment/security/policy", + "source": "https://github.com/sebastianbergmann/environment/tree/6.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-04-11T05:39:26+00:00" + }, + { + "name": "sebastian/exporter", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0", + "reference": "f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=8.1", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "https://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/5.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:06:49+00:00" + }, + { + "name": "sebastian/global-state", + "version": "6.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/7ea9ead78f6d380d2a667864c132c2f7b83055e4", + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "sebastian/object-reflector": "^3.0", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "security": "https://github.com/sebastianbergmann/global-state/security/policy", + "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-07-19T07:19:23+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "17c4d940ecafb3d15d2cf916f4108f664e28b130" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/17c4d940ecafb3d15d2cf916f4108f664e28b130", + "reference": "17c4d940ecafb3d15d2cf916f4108f664e28b130", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.10", + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "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 counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:08:02+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906", + "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "sebastian/object-reflector": "^3.0", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/5.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:08:32+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "24ed13d98130f0e7122df55d06c5c4942a577957" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957", + "reference": "24ed13d98130f0e7122df55d06c5c4942a577957", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:06:18+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "05909fb5bc7df4c52992396d0116aed689f93712" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/05909fb5bc7df4c52992396d0116aed689f93712", + "reference": "05909fb5bc7df4c52992396d0116aed689f93712", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "https://github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/5.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:05:40+00:00" + }, + { + "name": "sebastian/type", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "462699a16464c3944eefc02ebdd77882bd3925bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf", + "reference": "462699a16464c3944eefc02ebdd77882bd3925bf", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.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": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/4.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:10:45+00:00" + }, + { + "name": "sebastian/version", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17", + "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.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 that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-07T11:34:05+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.2.1" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2021-07-28T10:34:58+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..57e9751 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,26 @@ + + + + + + tests/AbstractRequestTest.php + tests/HttpRequestTest.php + tests/WgetRequestTest.php + + + + + + src + + + diff --git a/src/Exporters/Abstract/AbstractConverter.php b/src/Converters/Abstract/AbstractConverter.php similarity index 95% rename from src/Exporters/Abstract/AbstractConverter.php rename to src/Converters/Abstract/AbstractConverter.php index 46cb256..12a7c45 100644 --- a/src/Exporters/Abstract/AbstractConverter.php +++ b/src/Converters/Abstract/AbstractConverter.php @@ -2,13 +2,14 @@ declare(strict_types=1); -namespace PmConverter\Exporters\Abstract; +namespace PmConverter\Converters\Abstract; use Exception; -use PmConverter\Environment; -use PmConverter\Exporters\{ +use PmConverter\Converters\{ ConverterContract, RequestContract}; +use PmConverter\Environment; +use PmConverter\Exceptions\InvalidHttpVersionException; use PmConverter\FileSystem; /** @@ -129,14 +130,16 @@ abstract class AbstractConverter implements ConverterContract * * @param object $item * @return RequestContract + * @throws InvalidHttpVersionException */ protected function initRequest(object $item): RequestContract { $request_class = static::REQUEST_CLASS; /** @var RequestContract $result */ - $result = new $request_class($this->vars); + $result = new $request_class(); $result->setName($item->name); + $result->setHttpVersion(1.1); //TODO http version? $result->setDescription($item->request?->description ?? null); $result->setVerb($item->request->method); $result->setUrl($item->request->url->raw); diff --git a/src/Converters/Abstract/AbstractRequest.php b/src/Converters/Abstract/AbstractRequest.php new file mode 100644 index 0000000..f87b6a4 --- /dev/null +++ b/src/Converters/Abstract/AbstractRequest.php @@ -0,0 +1,295 @@ +httpVersion = $version; + return $this; + } + + /** + * @inheritDoc + */ + public function getHttpVersion(): float + { + return $this->httpVersion; + } + + /** + * @inheritDoc + */ + public function setName(string $name): static + { + $this->name = $name; + return $this; + } + + /** + * @inheritDoc + */ + public function getName(): string + { + return str_replace(DIRECTORY_SEPARATOR, '_', $this->name); + } + + /** + * @inheritDoc + */ + public function setDescription(?string $description): static + { + $this->description = $description; + return $this; + } + + /** + * @inheritDoc + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @inheritDoc + */ + public function setVerb(string $verb): static + { + $this->verb = $verb; + return $this; + } + + /** + * @inheritDoc + */ + public function getVerb(): string + { + empty($this->verb) && throw new EmptyHttpVerbException('Request HTTP verb must be defined before conversion'); + return $this->verb; + } + + /** + * @inheritDoc + */ + public function setUrl(string $url): static + { + $this->url = $url; + return $this; + } + + /** + * @inheritDoc + */ + public function getUrl(): string + { + return $this->url ?: ''; + } + + /** + * @inheritDoc + */ + public function setHeaders(?array $headers): static + { + foreach ($headers as $header) { + $this->setHeader($header->key, $header->value, $header?->disabled ?? false); + } + return $this; + } + + /** + * @inheritDoc + */ + public function setHeader(string $name, mixed $value, bool $disabled = false): static + { + $this->headers[$name] = [ + 'value' => $value, + 'disabled' => $disabled, + ]; + return $this; + } + + /** + * @inheritDoc + */ + public function getHeaders(): array + { + return $this->headers; + } + + /** + * @inheritDoc + */ + public function setAuth(?object $auth): static + { + if (!empty($auth)) { + switch ($auth->type) { + case 'bearer': + $this->setHeader('Authorization', 'Bearer ' . $auth->{$auth->type}[0]->value); + break; + default: + break; + } + } + return $this; + } + + /** + * @inheritDoc + */ + public function setBodymode(string $bodymode): static + { + $this->bodymode = $bodymode; + return $this; + } + + /** + * @inheritDoc + */ + public function getBodymode(): string + { + return $this->bodymode; + } + + /** + * @inheritDoc + */ + public function setBody(object $body): static + { + $this->setBodymode($body->mode); + if ($body->mode === 'formdata') { + $this->setHeader('Content-Type', 'multipart/form-data') + ->setFormdataBody($body); + } elseif (!empty($body->options) && $body->options->{$this->bodymode}->language === 'json') { + $this->setHeader('Content-Type', 'application/json') + ->setJsonBody($body); + } + return $this; + } + + /** + * Sets body content from multipart/formdata + * + * @param object $body + * @return $this + */ + protected function setFormdataBody(object $body): static + { + foreach ($body->formdata as $field) { + $this->body[$field->key] = [ + 'value' => $field->type === 'file' ? $field->src : $field->value, + 'type' => $field->type, + ]; + } + return $this; + } + + /** + * Sets body content from application/json + * + * @param object $body + * @return $this + */ + protected function setJsonBody(object $body): static + { + $this->body = $body->{$this->getBodymode()}; + return $this; + } + + /** + * @inheritDoc + */ + public function getBody(): mixed + { + return $this->body; + } + + /** + * Returns array of description lines + * + * @return array + */ + abstract protected function prepareDescription(): array; + + /** + * Returns array of headers + * + * @return array + */ + abstract protected function prepareHeaders(): array; + + /** + * Returns array of request body lines + * + * @return array + */ + abstract protected function prepareBody(): array; + + /** + * Converts request object to string to be written in result file + * + * @return string + */ + abstract public function __toString(): string; +} diff --git a/src/Exporters/ConvertFormat.php b/src/Converters/ConvertFormat.php similarity index 51% rename from src/Exporters/ConvertFormat.php rename to src/Converters/ConvertFormat.php index 9872819..73800b6 100644 --- a/src/Exporters/ConvertFormat.php +++ b/src/Converters/ConvertFormat.php @@ -2,12 +2,13 @@ declare(strict_types=1); -namespace PmConverter\Exporters; +namespace PmConverter\Converters; -use PmConverter\Exporters\Curl\CurlConverter; -use PmConverter\Exporters\Http\HttpConverter; -use PmConverter\Exporters\Wget\WgetConverter; +use PmConverter\Converters\{ + Curl\CurlConverter, + Http\HttpConverter, + Wget\WgetConverter}; enum ConvertFormat: string { diff --git a/src/Exporters/ConverterContract.php b/src/Converters/ConverterContract.php similarity index 84% rename from src/Exporters/ConverterContract.php rename to src/Converters/ConverterContract.php index 8c21fd5..1f280de 100644 --- a/src/Exporters/ConverterContract.php +++ b/src/Converters/ConverterContract.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PmConverter\Exporters; +namespace PmConverter\Converters; interface ConverterContract { diff --git a/src/Exporters/Curl/CurlConverter.php b/src/Converters/Curl/CurlConverter.php similarity index 81% rename from src/Exporters/Curl/CurlConverter.php rename to src/Converters/Curl/CurlConverter.php index 88e2d22..5b11944 100644 --- a/src/Exporters/Curl/CurlConverter.php +++ b/src/Converters/Curl/CurlConverter.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace PmConverter\Exporters\Curl; +namespace PmConverter\Converters\Curl; -use PmConverter\Exporters\{ +use PmConverter\Converters\{ Abstract\AbstractConverter, ConverterContract}; diff --git a/src/Exporters/Curl/CurlRequest.php b/src/Converters/Curl/CurlRequest.php similarity index 80% rename from src/Exporters/Curl/CurlRequest.php rename to src/Converters/Curl/CurlRequest.php index fe7fe71..3dd06a8 100644 --- a/src/Exporters/Curl/CurlRequest.php +++ b/src/Converters/Curl/CurlRequest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace PmConverter\Exporters\Curl; +namespace PmConverter\Converters\Curl; -use PmConverter\Exporters\Abstract\AbstractRequest; +use PmConverter\Converters\Abstract\AbstractRequest; /** * Class to determine file content with curl request format @@ -31,7 +31,7 @@ class CurlRequest extends AbstractRequest if ($header['disabled']) { continue; } - $output[] = sprintf("\t--header '%s=%s' \ ", $header_key, $header['value']); + $output[] = sprintf("\t--header '%s: %s' \ ", $header_key, $header['value']); } return $output; } @@ -44,12 +44,12 @@ class CurlRequest extends AbstractRequest $output = []; switch ($this->bodymode) { case 'formdata': - foreach ($this->body as $data) { + foreach ($this->body as $key => $data) { $output[] = sprintf( "%s\t--form '%s=%s' \ ", - isset($data->disabled) ? '# ' : '', - $data->key, - $data->type === 'file' ? "@$data->src" : $data->value + isset($data['disabled']) ? '# ' : '', + $key, + $data['type'] === 'file' ? "@" . $data['value'] : $data['value'] ); } break; diff --git a/src/Exporters/Http/HttpConverter.php b/src/Converters/Http/HttpConverter.php similarity index 81% rename from src/Exporters/Http/HttpConverter.php rename to src/Converters/Http/HttpConverter.php index 73dc042..e344172 100644 --- a/src/Exporters/Http/HttpConverter.php +++ b/src/Converters/Http/HttpConverter.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace PmConverter\Exporters\Http; +namespace PmConverter\Converters\Http; -use PmConverter\Exporters\{ +use PmConverter\Converters\{ Abstract\AbstractConverter, ConverterContract}; diff --git a/src/Exporters/Http/HttpRequest.php b/src/Converters/Http/HttpRequest.php similarity index 60% rename from src/Exporters/Http/HttpRequest.php rename to src/Converters/Http/HttpRequest.php index adc4118..6297429 100644 --- a/src/Exporters/Http/HttpRequest.php +++ b/src/Converters/Http/HttpRequest.php @@ -2,9 +2,11 @@ declare(strict_types=1); -namespace PmConverter\Exporters\Http; +namespace PmConverter\Converters\Http; -use PmConverter\Exporters\Abstract\AbstractRequest; +use PmConverter\Converters\Abstract\AbstractRequest; +use PmConverter\Exceptions\{ + EmptyHttpVerbException}; /** * Class to determine file content with http request format @@ -23,12 +25,13 @@ class HttpRequest extends AbstractRequest /** * @inheritDoc + * @throws EmptyHttpVerbException */ protected function prepareHeaders(): array { - $output[] = "$this->verb $this->url $this->http"; - foreach ($this->headers as $header_key => $header) { - $output[] = sprintf('%s%s: %s', $header['disabled'] ? '# ' : '', $header_key, $header['value']); + $output[] = sprintf('%s %s HTTP/%s', $this->getVerb(), $this->getUrl(), $this->getHttpVersion()); + foreach ($this->headers as $name => $data) { + $output[] = sprintf('%s%s: %s', $data['disabled'] ? '# ' : '', $name, $data['value']); } return $output; } @@ -38,15 +41,15 @@ class HttpRequest extends AbstractRequest */ protected function prepareBody(): array { - switch ($this->bodymode) { + switch ($this->getBodymode()) { case 'formdata': $output = ['']; - foreach ($this->body as $data) { + foreach ($this->body as $key => $data) { $output[] = sprintf( '%s%s=%s', - empty($data->disabled) ? '' : '# ', - $data->key, - $data->type === 'file' ? $data->src : $data->value + empty($data['disabled']) ? '' : '# ', + $key, + $data['type'] === 'file' ? '@' . $data['value'] : $data['value'] ); } return $output; @@ -57,6 +60,7 @@ class HttpRequest extends AbstractRequest /** * @inheritDoc + * @throws EmptyHttpVerbException */ public function __toString(): string { diff --git a/src/Converters/RequestContract.php b/src/Converters/RequestContract.php new file mode 100644 index 0000000..424f31e --- /dev/null +++ b/src/Converters/RequestContract.php @@ -0,0 +1,153 @@ +bodymode) { case 'formdata': - $params = []; - foreach ($this->body as $data) { - if ($data->type === 'file') { + $output = []; + foreach ($this->body as $key => $data) { + if ($data['type'] === 'file') { continue; } - $params[$data->key] = $data->value; + $output[$key] = $data['value']; } - $output[] = http_build_query($params); return $output; default: - return ["\t'$this->body' \ "]; + return [$this->body]; } } /** * @inheritDoc + * @throws EmptyHttpVerbException */ public function __toString(): string { @@ -68,14 +69,26 @@ class WgetRequest extends AbstractRequest [ 'wget \ ', "\t--no-check-certificate \ ", - "\t--quiet \ ", - "\t--timeout=0 \ ", + "\t--timeout 0 \ ", "\t--method $this->verb \ ", ], $this->prepareHeaders(), - $this->prepareBody() ); - $output[] = "\t'$this->url'"; + if ($this->getBodymode() === 'formdata') { + if ($this->getBody()) { + if ($this->getVerb() === 'GET') { + $output[] = sprintf("\t%s?%s", $this->getUrl(), http_build_query($this->prepareBody())); + } else { + $output[] = sprintf("\t--body-data '%s' \ ", http_build_query($this->prepareBody())); + $output[] = sprintf("\t%s", $this->getUrl()); + } + } + } else { + if ($this->getVerb() !== 'GET') { + $output[] = sprintf("\t--body-data '%s' \ ", implode("\n", $this->prepareBody())); + $output[] = sprintf("\t%s", $this->getUrl()); + } + } return implode(PHP_EOL, array_merge($output, [''])); } } diff --git a/src/Exceptions/EmptyHttpVerbException.php b/src/Exceptions/EmptyHttpVerbException.php new file mode 100644 index 0000000..53be4e9 --- /dev/null +++ b/src/Exceptions/EmptyHttpVerbException.php @@ -0,0 +1,11 @@ +name = $name; - return $this; - } - - /** - * Returns name of request - * - * @return string - */ - public function getName(): string - { - return str_replace(DIRECTORY_SEPARATOR, '_', $this->name); - } - - /** - * Sets description from collection item to request object - * - * @param string|null $description - * @return HttpRequest - */ - public function setDescription(?string $description): static - { - $this->description = $description; - return $this; - } - - /** - * Sets HTTP verb from collection item to request object - * - * @param string $verb - * @return HttpRequest - */ - public function setVerb(string $verb): static - { - $this->verb = $verb; - return $this; - } - - /** - * Sets URL from collection item to request object - * - * @param string $url - * @return HttpRequest - */ - public function setUrl(string $url): static - { - $this->url = $url; - return $this; - } - - /** - * Sets headers from collection item to request object - * - * @param object[]|null $headers - * @return $this - */ - public function setHeaders(?array $headers): static - { - foreach ($headers as $header) { - $this->headers[$header->key] = [ - 'value' => $header->value, - 'disabled' => $header?->disabled ?? false, - ]; - } - return $this; - } - - /** - * Sets authorization headers - * - * @param object|null $auth - * @return $this - */ - public function setAuth(?object $auth): static - { - if (!empty($auth)) { - switch ($auth->type) { - case 'bearer': - $this->headers['Authorization'] = [ - 'value' => 'Bearer ' . $auth->{$auth->type}[0]->value, - 'disabled' => false, - ]; - break; - default: - break; - } - } - return $this; - } - - - /** - * Sets body mode from collection item to request object - * - * @param string $bodymode - * @return HttpRequest - */ - public function setBodymode(string $bodymode): static - { - $this->bodymode = $bodymode; - return $this; - } - - /** - * Sets body from collection item to request object - * - * @param object $body - * @return $this - */ - public function setBody(object $body): static - { - $this->setBodymode($body->mode); - if (!empty($body->options) && $body->options->{$this->bodymode}->language === 'json') { - empty($this->headers['Content-Type']) && $this->setHeaders([ - (object)[ - 'key' => 'Content-Type', - 'value' => 'application/json', - 'disabled' => false, - ], - ]); - } - $body->mode === 'formdata' && $this->setHeaders([ - (object)[ - 'key' => 'Content-Type', - 'value' => 'multipart/form-data', - 'disabled' => false, - ], - ]); - $this->body = $body->{$body->mode}; - return $this; - } - - /** - * Returns array of description lines - * - * @return array - */ - abstract protected function prepareDescription(): array; - - /** - * Returns array of headers - * - * @return array - */ - abstract protected function prepareHeaders(): array; - - /** - * Returns array of request body lines - * - * @return array - */ - abstract protected function prepareBody(): array; - - /** - * Converts request object to string to be written in result file - * - * @return string - */ - abstract public function __toString(): string; -} diff --git a/src/Exporters/RequestContract.php b/src/Exporters/RequestContract.php deleted file mode 100644 index b0c277e..0000000 --- a/src/Exporters/RequestContract.php +++ /dev/null @@ -1,19 +0,0 @@ -setHttpVersion(2.0); + + $this->assertSame(2.0, $request->getHttpVersion()); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Abstract\AbstractRequest::getVerb() + * @covers PmConverter\HttpVersions + * @return void + * @throws InvalidHttpVersionException + */ + public function testInvalidHttpVersionException(): void + { + $this->expectException(InvalidHttpVersionException::class); + + $request = new \PmConverter\Converters\Http\HttpRequest(); + $request->setHttpVersion(5); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Abstract\AbstractRequest::setVerb() + * @covers PmConverter\Converters\Abstract\AbstractRequest::getVerb() + * @return void + * @throws EmptyHttpVerbException + */ + public function testVerb(): void + { + $request = new \PmConverter\Converters\Http\HttpRequest(); + $request->setVerb('GET'); + + $this->assertSame('GET', $request->getVerb()); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Abstract\AbstractRequest::getVerb() + * @return void + * @throws EmptyHttpVerbException + */ + public function testEmptyHttpVerbException(): void + { + $this->expectException(EmptyHttpVerbException::class); + + $request = new \PmConverter\Converters\Http\HttpRequest(); + $request->getVerb(); + } + + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Abstract\AbstractRequest::setUrl() + * @covers PmConverter\Converters\Abstract\AbstractRequest::getUrl() + * @return void + */ + public function testUrl(): void + { + $request = new \PmConverter\Converters\Http\HttpRequest(); + $request->setUrl('http://localhost'); + + $this->assertSame('http://localhost', $request->getUrl()); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Abstract\AbstractRequest::setName() + * @covers PmConverter\Converters\Abstract\AbstractRequest::getName() + * @return void + */ + public function testName(): void + { + $request = new \PmConverter\Converters\Http\HttpRequest(); + $request->setName('lorem ipsum'); + + $this->assertSame('lorem ipsum', $request->getName()); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Abstract\AbstractRequest::setDescription() + * @covers PmConverter\Converters\Abstract\AbstractRequest::getDescription() + * @return void + */ + public function testDescription(): void + { + $request = new \PmConverter\Converters\Http\HttpRequest(); + $request->setDescription("lorem ipsum\ndolor sit\namet"); + + $this->assertSame("lorem ipsum\ndolor sit\namet", $request->getDescription()); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Abstract\AbstractRequest::setBodymode() + * @covers PmConverter\Converters\Abstract\AbstractRequest::getBodymode() + * @return void + */ + public function testBodyMode(): void + { + $request = new \PmConverter\Converters\Http\HttpRequest(); + $request->setBodymode('raw'); + + $this->assertSame('raw', $request->getBodymode()); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Abstract\AbstractRequest::setHeaders() + * @covers PmConverter\Converters\Abstract\AbstractRequest::setHeader() + * @covers PmConverter\Converters\Abstract\AbstractRequest::getHeaders() + * @return void + */ + public function testHeaders(): void + { + $headers = [ + (object)[ + 'key' => 'Header 1', + 'value' => 'Value 1', + 'disabled' => true, + ], + (object)[ + 'key' => 'Header 2', + 'value' => 'Value 2', + 'disabled' => false, + ], + (object)[ + 'key' => 'Header 3', + 'value' => 'Value 3', + ], + ]; + $expected = [ + 'Header 1' => [ + 'value' => 'Value 1', + 'disabled' => true, + ], + 'Header 2' => [ + 'value' => 'Value 2', + 'disabled' => false, + ], + 'Header 3' => [ + 'value' => 'Value 3', + 'disabled' => false, + ], + 'Header 4' => [ + 'value' => 'Value 4', + 'disabled' => false, + ], + 'Header 5' => [ + 'value' => 'Value 5', + 'disabled' => true, + ], + ]; + + $request = new \PmConverter\Converters\Http\HttpRequest(); + $request->setHeaders($headers) + ->setHeader('Header 4', 'Value 4') + ->setHeader('Header 5', 'Value 5', true); + + $this->assertSame($expected, $request->getHeaders()); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Abstract\AbstractRequest::setAuth() + * @return void + */ + public function testAuthBearer(): void + { + $auth = (object)[ + 'type' => 'bearer', + 'bearer' => [ + (object)[ + 'key' => 'token', + 'value' => 'qwerty', + 'type' => 'string', + ] + ] + ]; + $expected = [ + 'Authorization' => [ + 'value' => 'Bearer qwerty', + 'disabled' => false, + ], + ]; + + $request = new \PmConverter\Converters\Http\HttpRequest(); + $request->setAuth($auth); + + $this->assertSame($expected, $request->getHeaders()); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Abstract\AbstractRequest::setBodymode() + * @covers PmConverter\Converters\Abstract\AbstractRequest::setHeader() + * @covers PmConverter\Converters\Abstract\AbstractRequest::setBody() + * @covers PmConverter\Converters\Abstract\AbstractRequest::setJsonBody() + * @covers PmConverter\Converters\Abstract\AbstractRequest::getBody() + * @return void + */ + public function testJson(): void + { + $body = (object)[ + 'mode' => 'raw', + 'raw' => $expectedBody = '["lorem ipsum dolor sit amet"]', + 'options' => (object)[ + 'raw' => (object)[ + 'language' => 'json', + ] + ] + ]; + + $request = new \PmConverter\Converters\Http\HttpRequest(); + $request->setBody($body); + + $expectedHeaders = [ + 'Content-Type' => [ + 'value' => 'application/json', + 'disabled' => false, + ], + ]; + + $this->assertSame($expectedHeaders, $request->getHeaders()); + $this->assertSame($expectedBody, $request->getBody()); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Abstract\AbstractRequest::setBodymode + * @covers PmConverter\Converters\Abstract\AbstractRequest::setHeader + * @covers PmConverter\Converters\Abstract\AbstractRequest::setBody + * @covers PmConverter\Converters\Abstract\AbstractRequest::setFormdataBody + * @covers PmConverter\Converters\Abstract\AbstractRequest::getBody + * @return void + */ + public function testFormdata(): void + { + $body = (object)[ + 'mode' => 'formdata', + 'formdata' => [ + (object)[ + 'key' => 'param1', + 'value' => 'value1', + 'type' => 'text', + ], + (object)[ + 'key' => 'param2', + 'src' => '/tmp/somefile.txt', + 'type' => 'file', + ], + ], + ]; + $expectedBody = [ + 'param1' => [ + 'value' => 'value1', + 'type' => 'text', + ], + 'param2' => [ + 'value' => '/tmp/somefile.txt', + 'type' => 'file', + ], + ]; + $expectedHeaders = [ + 'Content-Type' => [ + 'value' => 'multipart/form-data', + 'disabled' => false, + ], + ]; + + $request = new \PmConverter\Converters\Http\HttpRequest(); + $request->setBody($body); + + $this->assertSame($expectedHeaders, $request->getHeaders()); + $this->assertSame($expectedBody, $request->getBody()); + } +} diff --git a/tests/HttpRequestTest.php b/tests/HttpRequestTest.php new file mode 100644 index 0000000..9d63fea --- /dev/null +++ b/tests/HttpRequestTest.php @@ -0,0 +1,140 @@ +setVerb('GET') + ->setUrl('http://localhost') + ->setDescription(implode("\n", $description)); + + $this->assertStringContainsString($needle, (string)$request); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Http\HttpRequest + * @covers PmConverter\Converters\Http\HttpRequest::prepareHeaders() + * @covers PmConverter\Converters\Http\HttpRequest::__toString() + * @return void + */ + public function testPrepareHeaders() + { + $headers = [ + (object)[ + 'key' => 'Header1', + 'value' => 'Value 1', + 'disabled' => true, + ], + (object)[ + 'key' => 'Header2', + 'value' => 'Value 2', + 'disabled' => false, + ], + (object)[ + 'key' => 'Header3', + 'value' => 'Value 3', + ], + ]; + $needle = implode("\n", [ + '# Header1: Value 1', + 'Header2: Value 2', + 'Header3: Value 3', + ]); + + $request = (new HttpRequest()) + ->setVerb('GET') + ->setUrl('http://localhost') + ->setHeaders($headers); + + $this->assertStringContainsString($needle, (string)$request); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Http\HttpRequest + * @covers PmConverter\Converters\Http\HttpRequest::prepareBody() + * @covers PmConverter\Converters\Http\HttpRequest::__toString() + * @return void + */ + public function testPrepareFormdataBody() + { + $body = (object)[ + 'mode' => 'formdata', + 'formdata' => [ + (object)[ + 'key' => 'param1', + 'value' => 'value1', + 'type' => 'text', + ], + (object)[ + 'key' => 'param2', + 'src' => '/tmp/somefile.txt', + 'type' => 'file', + ], + ], + ]; + $needle = implode("\n", [ + 'param1=value1', + 'param2=@/tmp/somefile.txt', + ]); + + $request = (new HttpRequest()) + ->setVerb('GET') + ->setUrl('http://localhost') + ->setBody($body); + + $this->assertStringContainsString($needle, (string)$request); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Http\HttpRequest + * @covers PmConverter\Converters\Http\HttpRequest::prepareBody() + * @covers PmConverter\Converters\Http\HttpRequest::__toString() + * @return void + */ + public function testPrepareJsonBody() + { + $body = (object)[ + 'mode' => 'raw', + 'raw' => $needle = '["lorem ipsum dolor sit amet"]', + 'options' => (object)[ + 'raw' => (object)[ + 'language' => 'json', + ] + ] + ]; + + $request = (new HttpRequest()) + ->setVerb('GET') + ->setUrl('http://localhost') + ->setBody($body); + + $this->assertStringContainsString($needle, (string)$request); + } +} diff --git a/tests/WgetRequestTest.php b/tests/WgetRequestTest.php new file mode 100644 index 0000000..86f84b1 --- /dev/null +++ b/tests/WgetRequestTest.php @@ -0,0 +1,232 @@ +setVerb('GET') + ->setUrl('http://localhost') + ->setDescription(null); + + $result = explode("\n", (string)$request); + + $this->assertFalse(str_starts_with($result[0], '# ') && str_starts_with($result[1], '# ')); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Wget\WgetRequest + * @covers PmConverter\Converters\Wget\WgetRequest::prepareDescription() + * @covers PmConverter\Converters\Wget\WgetRequest::__toString() + * @return void + */ + public function testPrepareEmptyDescription() + { + $description = [ + 'lorem ipsum', + 'dolor sit', + 'amet', + ]; + $needle = implode("\n", [ + '# lorem ipsum', + '# dolor sit', + '# amet', + ]); + + $request = (new WgetRequest()) + ->setVerb('GET') + ->setUrl('http://localhost') + ->setDescription(implode("\n", $description)); + + $this->assertStringContainsString($needle, (string)$request); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Wget\WgetRequest + * @covers PmConverter\Converters\Wget\WgetRequest::prepareHeaders() + * @covers PmConverter\Converters\Wget\WgetRequest::__toString() + * @return void + */ + public function testPrepareHeaders() + { + $headers = [ + (object)[ + 'key' => 'Header1', + 'value' => 'Value 1', + 'disabled' => true, + ], + (object)[ + 'key' => 'Header2', + 'value' => 'Value 2', + 'disabled' => false, + ], + (object)[ + 'key' => 'Header3', + 'value' => 'Value 3', + ], + ]; + $needle = implode("\n", [ + "\t--header 'Header2: Value 2' \ ", + "\t--header 'Header3: Value 3' \ ", + ]); + + $request = (new WgetRequest()) + ->setVerb('GET') + ->setUrl('http://localhost') + ->setHeaders($headers); + + $this->assertStringContainsString($needle, (string)$request); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Wget\WgetRequest + * @covers PmConverter\Converters\Wget\WgetRequest::prepareBody() + * @covers PmConverter\Converters\Wget\WgetRequest::__toString() + * @return void + */ + public function testPrepareFormdataBodyGet() + { + $body = (object)[ + 'mode' => 'formdata', + 'formdata' => [ + (object)[ + 'key' => 'param1', + 'value' => 'value1', + 'type' => 'text', + ], + (object)[ + 'key' => 'param2', + 'src' => '/tmp/somefile.txt', + 'type' => 'file', + ], + (object)[ + 'key' => 'param3', + 'value' => 'value3', + 'type' => 'text', + ], + ], + ]; + $needle = 'http://localhost?' . http_build_query([ + 'param1' => 'value1', + 'param3' => 'value3', + ]); + + $request = (new WgetRequest()) + ->setVerb('GET') + ->setUrl('http://localhost') + ->setBody($body); + + $this->assertStringContainsString($needle, (string)$request); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Wget\WgetRequest + * @covers PmConverter\Converters\Wget\WgetRequest::prepareBody() + * @covers PmConverter\Converters\Wget\WgetRequest::__toString() + * @return void + */ + public function testPrepareFormdataBodyPost() + { + $body = (object)[ + 'mode' => 'formdata', + 'formdata' => [ + (object)[ + 'key' => 'param1', + 'value' => 'value1', + 'type' => 'text', + ], + (object)[ + 'key' => 'param2', + 'src' => '/tmp/somefile.txt', + 'type' => 'file', + ], + (object)[ + 'key' => 'param3', + 'value' => 'value3', + 'type' => 'text', + ], + ], + ]; + $needle = http_build_query([ + 'param1' => 'value1', + 'param3' => 'value3', + ]); + + $request = (new WgetRequest()) + ->setVerb('POST') + ->setUrl('http://localhost') + ->setBody($body); + + $this->assertStringContainsString($needle, (string)$request); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Wget\WgetRequest + * @covers PmConverter\Converters\Wget\WgetRequest::prepareBody() + * @covers PmConverter\Converters\Wget\WgetRequest::__toString() + * @return void + */ + public function testPrepareJsonBodyGet() + { + $body = (object)[ + 'mode' => 'raw', + 'raw' => $needle = '["lorem ipsum dolor sit amet"]', + 'options' => (object)[ + 'raw' => (object)[ + 'language' => 'json', + ] + ] + ]; + + $request = (new WgetRequest()) + ->setVerb('GET') + ->setUrl('http://localhost') + ->setBody($body); + + $this->assertStringNotContainsString($needle, (string)$request); + } + + /** + * @covers PmConverter\Converters\Abstract\AbstractRequest + * @covers PmConverter\Converters\Wget\WgetRequest + * @covers PmConverter\Converters\Wget\WgetRequest::prepareBody() + * @covers PmConverter\Converters\Wget\WgetRequest::__toString() + * @return void + */ + public function testPrepareJsonBodyPost() + { + $body = (object)[ + 'mode' => 'raw', + 'raw' => $needle = '["lorem ipsum dolor sit amet"]', + 'options' => (object)[ + 'raw' => (object)[ + 'language' => 'json', + ] + ] + ]; + + $request = (new WgetRequest()) + ->setVerb('POST') + ->setUrl('http://localhost') + ->setBody($body); + + $this->assertStringContainsString($needle, (string)$request); + } +} -- 2.46.GIT