From 628d66a2856f602e3b1b30ef9c80d8d7e42fd3b5 Mon Sep 17 00:00:00 2001 From: Tetiana Blindaruk Date: Sun, 16 Dec 2018 12:05:58 +0200 Subject: [PATCH] [tests] testing - install phpunit and orchestra/testbench - write some tests --- .gitignore | 1 + README.md | 1 + composer.json | 11 +- composer.lock | 1439 ----------------- phpunit.xml | 25 + src/RequestMapperProvider.php | 26 +- src/Resolver.php | 65 + src/Storage.php | 41 + src/Support/RequestMapperServiceProvider.php | 15 +- ...equestMapperResolver.php => Validator.php} | 47 +- tests/Integration/AutoDispatchingTest.php | 37 + .../ConfigurableDispatchingTest.php | 50 + .../Integration/Stub/InvalidCustomObject.php | 28 + .../Stub/RequestDataTransferObject.php | 52 + .../Stub/RequestMapperServiceProvider.php | 27 + tests/Integration/Stub/ValidCustomObject.php | 38 + tests/Integration/TestCase.php | 27 + tests/bootstrap.php | 13 + 18 files changed, 435 insertions(+), 1508 deletions(-) delete mode 100644 composer.lock create mode 100644 phpunit.xml create mode 100644 src/Resolver.php create mode 100644 src/Storage.php rename src/{RequestMapperResolver.php => Validator.php} (59%) create mode 100644 tests/Integration/AutoDispatchingTest.php create mode 100644 tests/Integration/ConfigurableDispatchingTest.php create mode 100644 tests/Integration/Stub/InvalidCustomObject.php create mode 100644 tests/Integration/Stub/RequestDataTransferObject.php create mode 100644 tests/Integration/Stub/RequestMapperServiceProvider.php create mode 100644 tests/Integration/Stub/ValidCustomObject.php create mode 100644 tests/Integration/TestCase.php create mode 100644 tests/bootstrap.php diff --git a/.gitignore b/.gitignore index 57872d0..55940e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /vendor/ +composer.lock \ No newline at end of file diff --git a/README.md b/README.md index 11264f4..2afa9f9 100644 --- a/README.md +++ b/README.md @@ -125,3 +125,4 @@ return [ ## 1.3. Todo - check nested DTO validation - contextual binding +- add integration tests for `change exception` diff --git a/composer.json b/composer.json index bc119e1..213ef9b 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,22 @@ "doctrine/annotations": "^1.6", "doctrine/cache": "^1.8", "illuminate/http": "^5.7", - "illuminate/config": "^5.7" + "illuminate/contracts": "^5.7" + }, + "require-dev": { + "phpunit/phpunit": "^7.5", + "orchestra/testbench": "^3.7" }, "autoload": { "psr-4": { "Maksi\\RequestMapperL\\": "src" } }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, "extra": { "laravel": { "providers": [ diff --git a/composer.lock b/composer.lock deleted file mode 100644 index b75bff9..0000000 --- a/composer.lock +++ /dev/null @@ -1,1439 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "hash": "d89b8650aab15d04ef3efc41973d9e93", - "content-hash": "ac06c5d7d6707f71b7b6e9c8bbeb5539", - "packages": [ - { - "name": "doctrine/annotations", - "version": "v1.6.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/annotations.git", - "reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5", - "reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5", - "shasum": "" - }, - "require": { - "doctrine/lexer": "1.*", - "php": "^7.1" - }, - "require-dev": { - "doctrine/cache": "1.*", - "phpunit/phpunit": "^6.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.6.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Docblock Annotations Parser", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "annotations", - "docblock", - "parser" - ], - "time": "2017-12-06 07:11:42" - }, - { - "name": "doctrine/cache", - "version": "v1.8.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/cache.git", - "reference": "d768d58baee9a4862ca783840eca1b9add7a7f57" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/d768d58baee9a4862ca783840eca1b9add7a7f57", - "reference": "d768d58baee9a4862ca783840eca1b9add7a7f57", - "shasum": "" - }, - "require": { - "php": "~7.1" - }, - "conflict": { - "doctrine/common": ">2.2,<2.4" - }, - "require-dev": { - "alcaeus/mongo-php-adapter": "^1.1", - "doctrine/coding-standard": "^4.0", - "mongodb/mongodb": "^1.1", - "phpunit/phpunit": "^7.0", - "predis/predis": "~1.0" - }, - "suggest": { - "alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.8.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Caching library offering an object-oriented API for many cache backends", - "homepage": "https://www.doctrine-project.org", - "keywords": [ - "cache", - "caching" - ], - "time": "2018-08-21 18:01:43" - }, - { - "name": "doctrine/inflector", - "version": "v1.3.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/inflector.git", - "reference": "5527a48b7313d15261292c149e55e26eae771b0a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/inflector/zipball/5527a48b7313d15261292c149e55e26eae771b0a", - "reference": "5527a48b7313d15261292c149e55e26eae771b0a", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "require-dev": { - "phpunit/phpunit": "^6.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Common String Manipulations with regard to casing and singular/plural rules.", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "inflection", - "pluralize", - "singularize", - "string" - ], - "time": "2018-01-09 20:05:19" - }, - { - "name": "doctrine/lexer", - "version": "v1.0.1", - "source": { - "type": "git", - "url": "https://github.com/doctrine/lexer.git", - "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", - "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Common\\Lexer\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "lexer", - "parser" - ], - "time": "2014-09-09 13:34:57" - }, - { - "name": "illuminate/config", - "version": "5.7.17", - "source": { - "type": "git", - "url": "https://github.com/illuminate/config.git", - "reference": "08b6e422d62602ee5263ca2113e9f3d800e905a4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/illuminate/config/zipball/08b6e422d62602ee5263ca2113e9f3d800e905a4", - "reference": "08b6e422d62602ee5263ca2113e9f3d800e905a4", - "shasum": "" - }, - "require": { - "illuminate/contracts": "5.7.*", - "illuminate/support": "5.7.*", - "php": "^7.1.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.7-dev" - } - }, - "autoload": { - "psr-4": { - "Illuminate\\Config\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "The Illuminate Config package.", - "homepage": "https://laravel.com", - "time": "2018-10-06 18:48:42" - }, - { - "name": "illuminate/contracts", - "version": "5.7.17", - "source": { - "type": "git", - "url": "https://github.com/illuminate/contracts.git", - "reference": "758927e5e925c1d442a1faaa1356675ceba0194c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/illuminate/contracts/zipball/758927e5e925c1d442a1faaa1356675ceba0194c", - "reference": "758927e5e925c1d442a1faaa1356675ceba0194c", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "psr/container": "^1.0", - "psr/simple-cache": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.7-dev" - } - }, - "autoload": { - "psr-4": { - "Illuminate\\Contracts\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "The Illuminate Contracts package.", - "homepage": "https://laravel.com", - "time": "2018-11-15 13:49:08" - }, - { - "name": "illuminate/filesystem", - "version": "5.7.17", - "source": { - "type": "git", - "url": "https://github.com/illuminate/filesystem.git", - "reference": "dfd91acf0cc557c91b59f6b4b7b9a31a6561b109" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/illuminate/filesystem/zipball/dfd91acf0cc557c91b59f6b4b7b9a31a6561b109", - "reference": "dfd91acf0cc557c91b59f6b4b7b9a31a6561b109", - "shasum": "" - }, - "require": { - "illuminate/contracts": "5.7.*", - "illuminate/support": "5.7.*", - "php": "^7.1.3", - "symfony/finder": "^4.1" - }, - "suggest": { - "league/flysystem": "Required to use the Flysystem local and FTP drivers (^1.0).", - "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).", - "league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).", - "league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (^1.0).", - "league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0)." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.7-dev" - } - }, - "autoload": { - "psr-4": { - "Illuminate\\Filesystem\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "The Illuminate Filesystem package.", - "homepage": "https://laravel.com", - "time": "2018-10-29 20:54:16" - }, - { - "name": "illuminate/http", - "version": "5.7.17", - "source": { - "type": "git", - "url": "https://github.com/illuminate/http.git", - "reference": "9ac7cd1d1859402e9aa165332b8110d55e4b9413" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/illuminate/http/zipball/9ac7cd1d1859402e9aa165332b8110d55e4b9413", - "reference": "9ac7cd1d1859402e9aa165332b8110d55e4b9413", - "shasum": "" - }, - "require": { - "illuminate/session": "5.7.*", - "illuminate/support": "5.7.*", - "php": "^7.1.3", - "symfony/http-foundation": "^4.1", - "symfony/http-kernel": "^4.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.7-dev" - } - }, - "autoload": { - "psr-4": { - "Illuminate\\Http\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "The Illuminate Http package.", - "homepage": "https://laravel.com", - "time": "2018-12-12 13:04:52" - }, - { - "name": "illuminate/session", - "version": "5.7.17", - "source": { - "type": "git", - "url": "https://github.com/illuminate/session.git", - "reference": "966b62512666bec8a5bf473cf277f0876ec2aeb8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/illuminate/session/zipball/966b62512666bec8a5bf473cf277f0876ec2aeb8", - "reference": "966b62512666bec8a5bf473cf277f0876ec2aeb8", - "shasum": "" - }, - "require": { - "illuminate/contracts": "5.7.*", - "illuminate/filesystem": "5.7.*", - "illuminate/support": "5.7.*", - "php": "^7.1.3", - "symfony/finder": "^4.1", - "symfony/http-foundation": "^4.1" - }, - "suggest": { - "illuminate/console": "Required to use the session:table command (5.7.*)." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.7-dev" - } - }, - "autoload": { - "psr-4": { - "Illuminate\\Session\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "The Illuminate Session package.", - "homepage": "https://laravel.com", - "time": "2018-10-10 20:24:53" - }, - { - "name": "illuminate/support", - "version": "5.7.17", - "source": { - "type": "git", - "url": "https://github.com/illuminate/support.git", - "reference": "f8b9387034e11980d3953c814b6ad65e2cd244e3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/f8b9387034e11980d3953c814b6ad65e2cd244e3", - "reference": "f8b9387034e11980d3953c814b6ad65e2cd244e3", - "shasum": "" - }, - "require": { - "doctrine/inflector": "^1.1", - "ext-mbstring": "*", - "illuminate/contracts": "5.7.*", - "nesbot/carbon": "^1.26.3", - "php": "^7.1.3" - }, - "conflict": { - "tightenco/collect": "<5.5.33" - }, - "suggest": { - "illuminate/filesystem": "Required to use the composer class (5.7.*).", - "moontoast/math": "Required to use ordered UUIDs (^1.1).", - "ramsey/uuid": "Required to use Str::uuid() (^3.7).", - "symfony/process": "Required to use the composer class (^4.1).", - "symfony/var-dumper": "Required to use the dd function (^4.1)." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.7-dev" - } - }, - "autoload": { - "psr-4": { - "Illuminate\\Support\\": "" - }, - "files": [ - "helpers.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "The Illuminate Support package.", - "homepage": "https://laravel.com", - "time": "2018-12-08 15:33:10" - }, - { - "name": "nesbot/carbon", - "version": "1.36.1", - "source": { - "type": "git", - "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "63da8cdf89d7a5efe43aabc794365f6e7b7b8983" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/63da8cdf89d7a5efe43aabc794365f6e7b7b8983", - "reference": "63da8cdf89d7a5efe43aabc794365f6e7b7b8983", - "shasum": "" - }, - "require": { - "php": ">=5.3.9", - "symfony/translation": "~2.6 || ~3.0 || ~4.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7" - }, - "suggest": { - "friendsofphp/php-cs-fixer": "Needed for the `composer phpcs` command. Allow to automatically fix code style.", - "phpstan/phpstan": "Needed for the `composer phpstan` command. Allow to detect potential errors." - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "Carbon\\Laravel\\ServiceProvider" - ] - } - }, - "autoload": { - "psr-4": { - "": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Brian Nesbitt", - "email": "brian@nesbot.com", - "homepage": "http://nesbot.com" - } - ], - "description": "A simple API extension for DateTime.", - "homepage": "http://carbon.nesbot.com", - "keywords": [ - "date", - "datetime", - "time" - ], - "time": "2018-11-22 18:23:02" - }, - { - "name": "psr/container", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Container\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", - "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" - ], - "time": "2017-02-14 16:28:37" - }, - { - "name": "psr/log", - "version": "1.1.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", - "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2018-11-20 15:27:04" - }, - { - "name": "psr/simple-cache", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/simple-cache.git", - "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", - "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\SimpleCache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interfaces for simple caching", - "keywords": [ - "cache", - "caching", - "psr", - "psr-16", - "simple-cache" - ], - "time": "2017-10-23 01:57:42" - }, - { - "name": "symfony/contracts", - "version": "v1.0.2", - "source": { - "type": "git", - "url": "https://github.com/symfony/contracts.git", - "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/contracts/zipball/1aa7ab2429c3d594dd70689604b5cf7421254cdf", - "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf", - "shasum": "" - }, - "require": { - "php": "^7.1.3" - }, - "require-dev": { - "psr/cache": "^1.0", - "psr/container": "^1.0" - }, - "suggest": { - "psr/cache": "When using the Cache contracts", - "psr/container": "When using the Service contracts", - "symfony/cache-contracts-implementation": "", - "symfony/service-contracts-implementation": "", - "symfony/translation-contracts-implementation": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\": "" - }, - "exclude-from-classmap": [ - "**/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "A set of abstractions extracted out of the Symfony components", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "time": "2018-12-05 08:06:11" - }, - { - "name": "symfony/debug", - "version": "v4.2.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/debug.git", - "reference": "e0a2b92ee0b5b934f973d90c2f58e18af109d276" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/e0a2b92ee0b5b934f973d90c2f58e18af109d276", - "reference": "e0a2b92ee0b5b934f973d90c2f58e18af109d276", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "psr/log": "~1.0" - }, - "conflict": { - "symfony/http-kernel": "<3.4" - }, - "require-dev": { - "symfony/http-kernel": "~3.4|~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.2-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Debug\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Debug Component", - "homepage": "https://symfony.com", - "time": "2018-11-28 18:24:18" - }, - { - "name": "symfony/event-dispatcher", - "version": "v4.2.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "921f49c3158a276d27c0d770a5a347a3b718b328" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/921f49c3158a276d27c0d770a5a347a3b718b328", - "reference": "921f49c3158a276d27c0d770a5a347a3b718b328", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "symfony/contracts": "^1.0" - }, - "conflict": { - "symfony/dependency-injection": "<3.4" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/config": "~3.4|~4.0", - "symfony/dependency-injection": "~3.4|~4.0", - "symfony/expression-language": "~3.4|~4.0", - "symfony/stopwatch": "~3.4|~4.0" - }, - "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.2-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\EventDispatcher\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony EventDispatcher Component", - "homepage": "https://symfony.com", - "time": "2018-12-01 08:52:38" - }, - { - "name": "symfony/finder", - "version": "v4.2.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/finder.git", - "reference": "e53d477d7b5c4982d0e1bfd2298dbee63d01441d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/e53d477d7b5c4982d0e1bfd2298dbee63d01441d", - "reference": "e53d477d7b5c4982d0e1bfd2298dbee63d01441d", - "shasum": "" - }, - "require": { - "php": "^7.1.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.2-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Finder\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Finder Component", - "homepage": "https://symfony.com", - "time": "2018-11-11 19:52:12" - }, - { - "name": "symfony/http-foundation", - "version": "v4.2.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/http-foundation.git", - "reference": "1b31f3017fadd8cb05cf2c8aebdbf3b12a943851" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/1b31f3017fadd8cb05cf2c8aebdbf3b12a943851", - "reference": "1b31f3017fadd8cb05cf2c8aebdbf3b12a943851", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "symfony/polyfill-mbstring": "~1.1" - }, - "require-dev": { - "predis/predis": "~1.0", - "symfony/expression-language": "~3.4|~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.2-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\HttpFoundation\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony HttpFoundation Component", - "homepage": "https://symfony.com", - "time": "2018-11-26 10:55:26" - }, - { - "name": "symfony/http-kernel", - "version": "v4.2.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/http-kernel.git", - "reference": "b39ceffc0388232c309cbde3a7c3685f2ec0a624" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/b39ceffc0388232c309cbde3a7c3685f2ec0a624", - "reference": "b39ceffc0388232c309cbde3a7c3685f2ec0a624", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "psr/log": "~1.0", - "symfony/contracts": "^1.0.2", - "symfony/debug": "~3.4|~4.0", - "symfony/event-dispatcher": "~4.1", - "symfony/http-foundation": "^4.1.1", - "symfony/polyfill-ctype": "~1.8" - }, - "conflict": { - "symfony/config": "<3.4", - "symfony/dependency-injection": "<4.2", - "symfony/translation": "<4.2", - "symfony/var-dumper": "<4.1.1", - "twig/twig": "<1.34|<2.4,>=2" - }, - "provide": { - "psr/log-implementation": "1.0" - }, - "require-dev": { - "psr/cache": "~1.0", - "symfony/browser-kit": "~3.4|~4.0", - "symfony/config": "~3.4|~4.0", - "symfony/console": "~3.4|~4.0", - "symfony/css-selector": "~3.4|~4.0", - "symfony/dependency-injection": "^4.2", - "symfony/dom-crawler": "~3.4|~4.0", - "symfony/expression-language": "~3.4|~4.0", - "symfony/finder": "~3.4|~4.0", - "symfony/process": "~3.4|~4.0", - "symfony/routing": "~3.4|~4.0", - "symfony/stopwatch": "~3.4|~4.0", - "symfony/templating": "~3.4|~4.0", - "symfony/translation": "~4.2", - "symfony/var-dumper": "^4.1.1" - }, - "suggest": { - "symfony/browser-kit": "", - "symfony/config": "", - "symfony/console": "", - "symfony/dependency-injection": "", - "symfony/var-dumper": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.2-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\HttpKernel\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony HttpKernel Component", - "homepage": "https://symfony.com", - "time": "2018-12-06 17:39:52" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.10.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.9-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "time": "2018-08-06 14:22:27" - }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.10.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "c79c051f5b3a46be09205c73b80b346e4153e494" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494", - "reference": "c79c051f5b3a46be09205c73b80b346e4153e494", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-mbstring": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.9-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for the Mbstring extension", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "time": "2018-09-21 13:07:52" - }, - { - "name": "symfony/translation", - "version": "v4.2.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/translation.git", - "reference": "c0e2191e9bed845946ab3d99767513b56ca7dcd6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/c0e2191e9bed845946ab3d99767513b56ca7dcd6", - "reference": "c0e2191e9bed845946ab3d99767513b56ca7dcd6", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "symfony/contracts": "^1.0.2", - "symfony/polyfill-mbstring": "~1.0" - }, - "conflict": { - "symfony/config": "<3.4", - "symfony/dependency-injection": "<3.4", - "symfony/yaml": "<3.4" - }, - "provide": { - "symfony/translation-contracts-implementation": "1.0" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/config": "~3.4|~4.0", - "symfony/console": "~3.4|~4.0", - "symfony/dependency-injection": "~3.4|~4.0", - "symfony/finder": "~2.8|~3.0|~4.0", - "symfony/intl": "~3.4|~4.0", - "symfony/yaml": "~3.4|~4.0" - }, - "suggest": { - "psr/log-implementation": "To use logging capability in translator", - "symfony/config": "", - "symfony/yaml": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.2-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Translation\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Translation Component", - "homepage": "https://symfony.com", - "time": "2018-12-06 10:45:32" - }, - { - "name": "symfony/validator", - "version": "v4.2.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/validator.git", - "reference": "cd35bb14a0e81bd99835e36cac4db1e72ad1939b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/validator/zipball/cd35bb14a0e81bd99835e36cac4db1e72ad1939b", - "reference": "cd35bb14a0e81bd99835e36cac4db1e72ad1939b", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "symfony/contracts": "^1.0.2", - "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.0" - }, - "conflict": { - "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0", - "symfony/dependency-injection": "<3.4", - "symfony/http-kernel": "<3.4", - "symfony/intl": "<4.1", - "symfony/translation": "<4.2", - "symfony/yaml": "<3.4" - }, - "require-dev": { - "doctrine/annotations": "~1.0", - "doctrine/cache": "~1.0", - "egulias/email-validator": "^1.2.8|~2.0", - "symfony/cache": "~3.4|~4.0", - "symfony/config": "~3.4|~4.0", - "symfony/dependency-injection": "~3.4|~4.0", - "symfony/expression-language": "~3.4|~4.0", - "symfony/http-foundation": "~4.1", - "symfony/http-kernel": "~3.4|~4.0", - "symfony/intl": "~4.1", - "symfony/property-access": "~3.4|~4.0", - "symfony/translation": "~4.2", - "symfony/var-dumper": "~3.4|~4.0", - "symfony/yaml": "~3.4|~4.0" - }, - "suggest": { - "doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.", - "doctrine/cache": "For using the default cached annotation reader and metadata cache.", - "egulias/email-validator": "Strict (RFC compliant) email validation", - "psr/cache-implementation": "For using the metadata cache.", - "symfony/config": "", - "symfony/expression-language": "For using the Expression validator", - "symfony/http-foundation": "", - "symfony/intl": "", - "symfony/property-access": "For accessing properties within comparison constraints", - "symfony/translation": "For translating validation errors.", - "symfony/yaml": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.2-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Validator\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Validator Component", - "homepage": "https://symfony.com", - "time": "2018-12-05 08:06:11" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [] -} diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..4518021 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,25 @@ + + + + + ./tests + + + + + ./src + + + \ No newline at end of file diff --git a/src/RequestMapperProvider.php b/src/RequestMapperProvider.php index f96dea8..4fb5293 100644 --- a/src/RequestMapperProvider.php +++ b/src/RequestMapperProvider.php @@ -4,8 +4,6 @@ namespace Maksi\RequestMapperL; use Doctrine\Common\Annotations\AnnotationRegistry; -use Illuminate\Contracts\Container\Container; -use Illuminate\Http\Request; use Illuminate\Support\ServiceProvider; use Maksi\RequestMapperL\Exception\AbstractException; use Maksi\RequestMapperL\Exception\RequestMapperException; @@ -33,7 +31,7 @@ public function boot(): void */ final public function register(): void { - $this->singletonResolver(); + $this->singletonStorage(); $this->bindValidatorInterface(); $this->bindException(); $this->resolveDataTransferObject(); @@ -61,11 +59,11 @@ protected function bindException(): void } /** - * + * @return void */ - protected function singletonResolver(): void + protected function singletonStorage(): void { - $this->app->singleton(RequestMapperResolver::class, RequestMapperResolver::class); + $this->app->singleton(Storage::class, Storage::class); } /** @@ -73,20 +71,12 @@ protected function singletonResolver(): void */ protected function resolveDataTransferObject(): void { - $this->app->resolving(function ($object, Container $container) { + $this->app->resolving(function ($object) { if ($object instanceof DataTransferObject) { - /** @var RequestMapperResolver $resolver */ - $resolver = $this->app->make(RequestMapperResolver::class); - $registererClass = $resolver->getRegisterClass(); - - if (!\in_array(\get_class($object), $registererClass, true)) { - /** @var Request $request */ - $request = $container->make(Request::class); - - $object->__construct($request->all()); - $resolver->applyAfterResolvingValidation($object); - } + /** @var Resolver $resolving */ + $resolving = $this->app->make(Resolver::class); + $resolving->resolve($object); } return $object; diff --git a/src/Resolver.php b/src/Resolver.php new file mode 100644 index 0000000..b7745c7 --- /dev/null +++ b/src/Resolver.php @@ -0,0 +1,65 @@ +storage = $storage; + $this->request = $request; + $this->validator = $validator; + } + + /** + * @param $object + * + * @throws Exception\AbstractException + * @throws RequestMapperException + */ + public function resolve(DataTransferObject $object): void + { + $registererClass = $this->storage->getRegisterClass(); + $objectName = \get_class($object); + if (!\in_array($objectName, $registererClass, true)) { + $data = $this->request->all(); + } else { + $map = $this->storage->getMap(); + $data = $map[$objectName]; + } + + $object->__construct($data); + $this->validator->applyAfterResolvingValidation($object); + } +} diff --git a/src/Storage.php b/src/Storage.php new file mode 100644 index 0000000..0287e9b --- /dev/null +++ b/src/Storage.php @@ -0,0 +1,41 @@ +map = array_merge($this->map, $map); + } + + /** + * @return array + */ + public function getRegisterClass(): array + { + return array_keys($this->map); + } + + /** + * @return array + */ + public function getMap(): array + { + return $this->map; + } +} diff --git a/src/Support/RequestMapperServiceProvider.php b/src/Support/RequestMapperServiceProvider.php index 028a90f..77b7171 100644 --- a/src/Support/RequestMapperServiceProvider.php +++ b/src/Support/RequestMapperServiceProvider.php @@ -5,7 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Support\ServiceProvider; -use Maksi\RequestMapperL\RequestMapperResolver; +use Maksi\RequestMapperL\Storage; /** * Class RequestMapperServiceProvider @@ -17,15 +17,18 @@ abstract class RequestMapperServiceProvider extends ServiceProvider /** * @return void */ - final public function register(): void + final public function boot(): void { - $this->bindResolver(); + $this->bootResolver(); } - protected function bindResolver(): void + /** + * @return void + */ + protected function bootResolver(): void { - /** @var RequestMapperResolver $resolver */ - $resolver = $this->app->make(RequestMapperResolver::class); + /** @var Storage $resolver */ + $resolver = $this->app->make(Storage::class); /** @var Request $request */ $request = $this->app->make(Request::class); $resolver->map($this->resolveMap($request)); diff --git a/src/RequestMapperResolver.php b/src/Validator.php similarity index 59% rename from src/RequestMapperResolver.php rename to src/Validator.php index b200eff..96d101d 100644 --- a/src/RequestMapperResolver.php +++ b/src/Validator.php @@ -4,36 +4,25 @@ namespace Maksi\RequestMapperL; use Illuminate\Contracts\Config\Repository as Config; -use Illuminate\Contracts\Container\Container; use Maksi\RequestMapperL\Exception\AbstractException; use Maksi\RequestMapperL\Exception\RequestMapperException; use Symfony\Component\Validator\Exception\LogicException; use Symfony\Component\Validator\Validator\ValidatorInterface; /** - * Class RequestMapperResolver + * Class Validator * * @package Maksi\RequestMapperL */ -class RequestMapperResolver +class Validator { private const CONFIG_EXCEPTION_STRING = 'request-mapper-l.exception-class'; - /** - * @var array - */ - private $map = []; - /** * @var Config */ private $config; - /** - * @var Container - */ - private $container; - /** * @var ValidatorInterface */ @@ -43,44 +32,14 @@ class RequestMapperResolver * RequestMapperResolver constructor. * * @param Config $config - * @param Container $container * @param ValidatorInterface $validator */ - public function __construct(Config $config, Container $container, ValidatorInterface $validator) + public function __construct(Config $config, ValidatorInterface $validator) { $this->config = $config; - $this->container = $container; $this->validator = $validator; } - /** - * @param array $map - */ - public function map(array $map): void - { - $this->map = array_merge($this->map, $map); - foreach ($map as $className => $arguments) { - $this->container->singleton($className, function () use ($className, $arguments) { - if (!\is_array($arguments)) { - throw new \InvalidArgumentException('$arguments should be array'); - } - - return new $className($arguments); - }); - $this->container->afterResolving($className, function ($resolved) { - $this->applyAfterResolvingValidation($resolved); - }); - } - } - - /** - * @return array - */ - public function getRegisterClass(): array - { - return array_keys($this->map); - } - /** * @param $resolved * diff --git a/tests/Integration/AutoDispatchingTest.php b/tests/Integration/AutoDispatchingTest.php new file mode 100644 index 0000000..2a8863e --- /dev/null +++ b/tests/Integration/AutoDispatchingTest.php @@ -0,0 +1,37 @@ +app->instance(Request::class, new Request(['title' => 'title1', 'age' => 2])); + + $dto = $this->app->make(RequestDataTransferObject::class); + $this->assertInstanceOf(RequestDataTransferObject::class, $dto); + $this->assertSame('title1', $dto->getTitle()); + } + + /** + * @expectedException \Maksi\RequestMapperL\Exception\RequestMapperException + */ + public function testInvalidAutoResolving(): void + { + /** @var RequestDataTransferObject $dto */ + $this->app->instance(Request::class, new Request(['title1' => 'title1'])); + + $dto = $this->app->make(RequestDataTransferObject::class); + $this->assertInstanceOf(RequestDataTransferObject::class, $dto); + } +} diff --git a/tests/Integration/ConfigurableDispatchingTest.php b/tests/Integration/ConfigurableDispatchingTest.php new file mode 100644 index 0000000..e645f9c --- /dev/null +++ b/tests/Integration/ConfigurableDispatchingTest.php @@ -0,0 +1,50 @@ +app->make(ValidCustomObject::class); + $this->assertInstanceOf(ValidCustomObject::class, $dto); + $this->assertSame(['Symfony'], $dto->getUserAgent()); + } + + /** + * @expectedException \Maksi\RequestMapperL\Exception\RequestMapperException + */ + public function testInvalidResolving(): void + { + $dto = $this->app->make(InvalidCustomObject::class); + $this->assertInstanceOf(InvalidCustomObject::class, $dto); + } + + /** + * @param \Illuminate\Foundation\Application $app + * + * @return array + */ + protected function getPackageProviders($app): array + { + return [ + RequestMapperProvider::class, + RequestMapperServiceProvider::class, + ]; + } +} diff --git a/tests/Integration/Stub/InvalidCustomObject.php b/tests/Integration/Stub/InvalidCustomObject.php new file mode 100644 index 0000000..655d940 --- /dev/null +++ b/tests/Integration/Stub/InvalidCustomObject.php @@ -0,0 +1,28 @@ +name = $data['name'] ?? null; + } +} diff --git a/tests/Integration/Stub/RequestDataTransferObject.php b/tests/Integration/Stub/RequestDataTransferObject.php new file mode 100644 index 0000000..22d60e1 --- /dev/null +++ b/tests/Integration/Stub/RequestDataTransferObject.php @@ -0,0 +1,52 @@ +age = $data['age'] ?? null; + $this->title = $data['title'] ?? null; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @return int + */ + public function getAge(): int + { + return $this->age; + } +} \ No newline at end of file diff --git a/tests/Integration/Stub/RequestMapperServiceProvider.php b/tests/Integration/Stub/RequestMapperServiceProvider.php new file mode 100644 index 0000000..062200b --- /dev/null +++ b/tests/Integration/Stub/RequestMapperServiceProvider.php @@ -0,0 +1,27 @@ + $request->headers->all(), + InvalidCustomObject::class => $request->headers->all(), + ]; + } +} diff --git a/tests/Integration/Stub/ValidCustomObject.php b/tests/Integration/Stub/ValidCustomObject.php new file mode 100644 index 0000000..764dc60 --- /dev/null +++ b/tests/Integration/Stub/ValidCustomObject.php @@ -0,0 +1,38 @@ +userAgent = $data['user-agent'] ?? null; + } + + /** + * @return array + */ + public function getUserAgent(): array + { + return $this->userAgent; + } +} \ No newline at end of file diff --git a/tests/Integration/TestCase.php b/tests/Integration/TestCase.php new file mode 100644 index 0000000..21136b6 --- /dev/null +++ b/tests/Integration/TestCase.php @@ -0,0 +1,27 @@ +