diff --git a/.gitattributes b/.gitattributes index 7cb1419..f726fe2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,10 @@ -/.gitattributes export-ignore -/.gitignore export-ignore -/.scrutinizer.yml export-ignore -/composer.lock export-ignore -/phpunit.xml.dist export-ignore -/doc export-ignore -/tests export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.scrutinizer.yml export-ignore +/.sensiolabs.yml export-ignore + +/composer.lock export-ignore +/phpunit.xml.dist export-ignore + +/doc export-ignore +/tests export-ignore diff --git a/.gitignore b/.gitignore index 61ead86..2f85675 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +/tests/runtime /vendor diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 539311f..f146a98 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,7 +1,7 @@ build: environment: php: - version: 5.6.16 + version: 5.6 dependencies: before: - sudo composer self-update @@ -9,8 +9,10 @@ build: imports: - php tools: - php_sim: false php_cpd: false + php_sim: false filter: excluded_paths: + - docs/* + - tests/* - vendor/* diff --git a/.sensiolabs.yml b/.sensiolabs.yml new file mode 100644 index 0000000..2477722 --- /dev/null +++ b/.sensiolabs.yml @@ -0,0 +1,6 @@ +exclude_patterns: + - docs/* + - tests/* + - vendor/* + - "*.jpg" + - "*.png" diff --git a/composer.json b/composer.json index 968b616..7dcbbb1 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,15 @@ "require": { "yiisoft/yii2": "~2.0.1" }, + "require-dev": { + "phpunit/phpunit": "^5.4" + }, "config": { "process-timeout": 1800 }, "autoload": { "psr-4": { - "sergeymakinen\\facades\\": "" + "sergeymakinen\\facades\\": "src" } } } diff --git a/composer.lock b/composer.lock index 5cd5442..4445aa8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "c9b5556ad2f126deb05f179b95ca9163", - "content-hash": "109114ed9efce9c2fc17daccf0db2c9b", + "hash": "75420ed1b51ad29c5ca78545bd06d4ef", + "content-hash": "4773caf3b8518d0e52df61d2c6f89f7d", "packages": [ { "name": "bower-asset/jquery", @@ -323,7 +323,1316 @@ "time": "2016-06-05 20:34:32" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "416fb8ad1d095a87f1d21bc40711843cd122fd4a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/416fb8ad1d095a87f1d21bc40711843cd122fd4a", + "reference": "416fb8ad1d095a87f1d21bc40711843cd122fd4a", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2016-03-31 10:24:22" + }, + { + "name": "myclabs/deep-copy", + "version": "1.5.5", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "399c1f9781e222f6eb6cc238796f5200d1b7f108" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/399c1f9781e222f6eb6cc238796f5200d1b7f108", + "reference": "399c1f9781e222f6eb6cc238796f5200d1b7f108", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "doctrine/collections": "1.*", + "phpunit/phpunit": "~4.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "homepage": "https://github.com/myclabs/DeepCopy", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2016-10-31 17:19:45" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-12-27 11:43:31" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/type-resolver": "^0.2.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2016-09-30 07:12:33" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.2", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b39c7a5b194f9ed7bd0dd345c751007a41862443", + "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2016-06-10 07:14:17" + }, + { + "name": "phpspec/prophecy", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "6c52c2722f8460122f96f86346600e1077ce22cb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/6c52c2722f8460122f96f86346600e1077ce22cb", + "reference": "6c52c2722f8460122f96f86346600e1077ce22cb", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", + "sebastian/comparator": "^1.1", + "sebastian/recursion-context": "^1.0|^2.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.0", + "phpunit/phpunit": "^4.8 || ^5.6.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2016-11-21 14:58:47" + }, + { + "name": "phpunit/php-code-coverage", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "6cba06ff75a1a63a71033e1a01b89056f3af1e8d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6cba06ff75a1a63a71033e1a01b89056f3af1e8d", + "reference": "6cba06ff75a1a63a71033e1a01b89056f3af1e8d", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "^1.4.2", + "sebastian/code-unit-reverse-lookup": "~1.0", + "sebastian/environment": "^1.3.2 || ^2.0", + "sebastian/version": "~1.0|~2.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "^5.4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.4.0", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.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" + ], + "time": "2016-11-01 05:06:24" + }, + { + "name": "phpunit/php-file-iterator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.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" + ], + "time": "2016-10-03 07:40:28" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "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" + ], + "time": "2015-06-21 13:50:34" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4|~5" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2016-05-12 18:03:57" + }, + { + "name": "phpunit/php-token-stream", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3b402f65a4cc90abf6e1104e388b896ce209631b", + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2016-11-15 14:06:22" + }, + { + "name": "phpunit/phpunit", + "version": "5.7.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "adf208ee82ab820a26394293f7a1b28ab07235ff" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/adf208ee82ab820a26394293f7a1b28ab07235ff", + "reference": "adf208ee82ab820a26394293f7a1b28ab07235ff", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "~1.3", + "php": "^5.6 || ^7.0", + "phpspec/prophecy": "^1.3.1", + "phpunit/php-code-coverage": "^4.0.1", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "^1.0.6", + "phpunit/phpunit-mock-objects": "^3.2", + "sebastian/comparator": "~1.2.2", + "sebastian/diff": "~1.2", + "sebastian/environment": "^1.3 || ^2.0", + "sebastian/exporter": "~2.0", + "sebastian/global-state": "~1.0", + "sebastian/object-enumerator": "~2.0", + "sebastian/resource-operations": "~1.0", + "sebastian/version": "~1.0|~2.0", + "symfony/yaml": "~2.1|~3.0" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-xdebug": "*", + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.7.x-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": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2016-11-23 08:53:43" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "3.4.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "45026c8383187ad1dcb14fbfec77dced265b9cfc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/45026c8383187ad1dcb14fbfec77dced265b9cfc", + "reference": "45026c8383187ad1dcb14fbfec77dced265b9cfc", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.6 || ^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^1.2 || ^2.0" + }, + "conflict": { + "phpunit/phpunit": "<5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2016-11-19 09:07:46" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "0a16efaff1cb18cf03d612d54e449db4a9e138c6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/0a16efaff1cb18cf03d612d54e449db4a9e138c6", + "reference": "0a16efaff1cb18cf03d612d54e449db4a9e138c6", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-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/", + "time": "2016-10-03 07:37:58" + }, + { + "name": "sebastian/comparator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "6a1ed12e8b2409076ab22e3897126211ff8b1f7f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/6a1ed12e8b2409076ab22e3897126211ff8b1f7f", + "reference": "6a1ed12e8b2409076ab22e3897126211ff8b1f7f", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2 || ~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2016-11-19 09:18:40" + }, + { + "name": "sebastian/diff", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "d0814318784b7756fb932116acd19ee3b0cbe67a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/d0814318784b7756fb932116acd19ee3b0cbe67a", + "reference": "d0814318784b7756fb932116acd19ee3b0cbe67a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2016-10-03 07:45:03" + }, + { + "name": "sebastian/environment", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "845620270f5b0714beeefd161efc0d7878d2a6d9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/845620270f5b0714beeefd161efc0d7878d2a6d9", + "reference": "845620270f5b0714beeefd161efc0d7878d2a6d9", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.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": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2016-10-03 07:36:49" + }, + { + "name": "sebastian/exporter", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "~4.4" + }, + "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": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2016-11-19 08:54:04" + }, + { + "name": "sebastian/global-state", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2015-10-12 03:26:01" + }, + { + "name": "sebastian/object-enumerator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35", + "reference": "96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "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": "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/", + "time": "2016-11-19 07:35:10" + }, + { + "name": "sebastian/recursion-context", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "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": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2016-11-19 07:33:16" + }, + { + "name": "sebastian/resource-operations", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "fadc83f7c41fb2924e542635fea47ae546816ece" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/fadc83f7c41fb2924e542635fea47ae546816ece", + "reference": "fadc83f7c41fb2924e542635fea47ae546816ece", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2016-10-03 07:43:09" + }, + { + "name": "sebastian/version", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "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": "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", + "time": "2016-10-03 07:35:21" + }, + { + "name": "symfony/yaml", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "b009b78abb48cff1010c51d2a2283141239a9be6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/b009b78abb48cff1010c51d2a2283141239a9be6", + "reference": "b009b78abb48cff1010c51d2a2283141239a9be6", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "symfony/console": "~2.8|~3.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "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 Yaml Component", + "homepage": "https://symfony.com", + "time": "2016-11-19 20:35:20" + }, + { + "name": "webmozart/assert", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "4a8bf11547e139e77b651365113fc12850c43d9a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/4a8bf11547e139e77b651365113fc12850c43d9a", + "reference": "4a8bf11547e139e77b651365113fc12850c43d9a", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2016-11-23 20:04:41" + } + ], "aliases": [], "minimum-stability": "dev", "stability-flags": [], diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..3a7669f --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,24 @@ + + + + + ./tests + + + + + ./src + + + diff --git a/Asset.php b/src/Asset.php similarity index 100% rename from Asset.php rename to src/Asset.php diff --git a/Auth.php b/src/Auth.php similarity index 100% rename from Auth.php rename to src/Auth.php diff --git a/Cache.php b/src/Cache.php similarity index 97% rename from Cache.php rename to src/Cache.php index b0bc89e..f6f9f12 100644 --- a/Cache.php +++ b/src/Cache.php @@ -50,9 +50,6 @@ * @method static bool flush() Deletes all values from cache. * @see \yii\caching\Cache::flush * - * @method static mixed get(mixed $key) Retrieves a value from cache with a specified key. - * @see \yii\caching\Cache::get - * * @method static null|\yii\base\Behavior getBehavior(string $name) Returns the named behavior object. * @see \yii\base\Component::getBehavior * @@ -130,7 +127,7 @@ public static function getFacadeComponentId() * the corresponding value in the cache will be invalidated when it is fetched via [[get()]]. * This parameter is ignored if [[serializer]] is false. * - * @return bool whether the value is successfully stored into cache. + * @return mixed the value stored into cache. */ public static function cache($key, $default, $duration = 0, $dependency = null) { diff --git a/Db.php b/src/Db.php similarity index 100% rename from Db.php rename to src/Db.php diff --git a/Error.php b/src/Error.php similarity index 100% rename from Error.php rename to src/Error.php diff --git a/Facade.php b/src/Facade.php similarity index 97% rename from Facade.php rename to src/Facade.php index 0df76d3..0678220 100644 --- a/Facade.php +++ b/src/Facade.php @@ -141,19 +141,25 @@ public static function __callStatic($name, $arguments) /** * @inheritDoc + * @codeCoverageIgnore */ private function __construct() - {} + { + } /** * @inheritDoc + * @codeCoverageIgnore */ private function __wakeup() - {} + { + } /** * @inheritDoc + * @codeCoverageIgnore */ private function __clone() - {} + { + } } diff --git a/Formatter.php b/src/Formatter.php similarity index 100% rename from Formatter.php rename to src/Formatter.php diff --git a/Http.php b/src/Http.php similarity index 100% rename from Http.php rename to src/Http.php diff --git a/I18n.php b/src/I18n.php similarity index 100% rename from I18n.php rename to src/I18n.php diff --git a/Log.php b/src/Log.php similarity index 100% rename from Log.php rename to src/Log.php diff --git a/Mailer.php b/src/Mailer.php similarity index 100% rename from Mailer.php rename to src/Mailer.php diff --git a/Redis.php b/src/Redis.php similarity index 100% rename from Redis.php rename to src/Redis.php diff --git a/Request.php b/src/Request.php similarity index 100% rename from Request.php rename to src/Request.php diff --git a/Response.php b/src/Response.php similarity index 98% rename from Response.php rename to src/Response.php index 2379413..2654c7d 100644 --- a/Response.php +++ b/src/Response.php @@ -11,6 +11,8 @@ namespace sergeymakinen\facades; +use yii\helpers\Url; + /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ /** * Yii::$app->get('response') facade. @@ -318,8 +320,7 @@ protected static function sendFormat($format, $data, array $headers) $response->data = $data; foreach ($headers as $name => $value) { if (strtolower($name) === 'location') { - /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $value = \yii\helpers\Url::to($value); + $value = Url::to($value); if (strpos($value, '/') === 0 && strpos($value, '//') !== 0) { $value = Request::getHostInfo() . $value; } diff --git a/Router.php b/src/Router.php similarity index 100% rename from Router.php rename to src/Router.php diff --git a/Security.php b/src/Security.php similarity index 100% rename from Security.php rename to src/Security.php diff --git a/Session.php b/src/Session.php similarity index 100% rename from Session.php rename to src/Session.php diff --git a/Url.php b/src/Url.php similarity index 100% rename from Url.php rename to src/Url.php diff --git a/User.php b/src/User.php similarity index 100% rename from User.php rename to src/User.php diff --git a/View.php b/src/View.php similarity index 100% rename from View.php rename to src/View.php diff --git a/tests/CacheTest.php b/tests/CacheTest.php new file mode 100644 index 0000000..a8fe321 --- /dev/null +++ b/tests/CacheTest.php @@ -0,0 +1,55 @@ +assertEquals(false, Cache::get($this->key)); + $this->assertEquals($this->value, Cache::cache($this->key, $this->value)); + $this->assertEquals($this->value, Cache::get($this->key)); + $this->assertEquals($this->value, Cache::cache($this->key, function () { + return $this->default; + })); + $this->assertEquals($this->value, Cache::get($this->key)); + Cache::delete($this->key); + $this->assertEquals($this->default, Cache::cache($this->key, function () { + return $this->default; + })); + $this->assertEquals($this->default, Cache::get($this->key)); + } + + public function testGet() + { + $this->assertEquals(false, Cache::get($this->key)); + $this->assertEquals($this->default, Cache::get($this->key, $this->default)); + $this->assertEquals($this->value, Cache::get($this->key, function () { + return $this->value; + })); + } + + protected function setUp() + { + parent::setUp(); + $this->createConsoleApplication([ + 'components' => [ + 'cache' => [ + 'class' => FileCache::class + ] + ] + ]); + Facade::setFacadeApplication(\Yii::$app); + Cache::flush(); + } +} diff --git a/tests/FacadeTest.php b/tests/FacadeTest.php new file mode 100644 index 0000000..7bebc2c --- /dev/null +++ b/tests/FacadeTest.php @@ -0,0 +1,194 @@ + [ + 'component' => [ + 'class' => Component::class + ], + 'component2' => [ + 'class' => Component2::class + ] + ] + ]; + + protected $mappings = [ + 'Asset' => 'assetManager', + 'Auth' => 'auth', + 'Cache' => 'cache', + 'Db' => 'db', + 'Error' => 'errorHandler', + 'Formatter' => 'formatter', + 'Http' => 'httpClient', + 'I18n' => 'i18n', + 'Log' => 'log', + 'Mailer' => 'mailer', + 'Redis' => 'redis', + 'Request' => 'request', + 'Response' => 'response', + 'Router' => 'urlManager', + 'Security' => 'security', + 'Session' => 'session', + 'Url' => 'urlManager', + 'User' => 'user', + 'View' => 'view', + ]; + + public function testGetFacadeComponentId() + { + $this->expectException(InvalidConfigException::class); + Facade::getFacadeComponentId(); + $this->assertSame('component', ComponentFacade::getFacadeComponentId()); + $this->assertSame('component2', Component2Facade::getFacadeComponentId()); + } + + /** + * @covers \sergeymakinen\facades\Facade::clearResolvedFacadeComponent + */ + public function testClearResolvedFacadeComponent() + { + ComponentFacade::getProperty(); + ComponentFacade::method(); + Component2Facade::getProperty(); + Component2Facade::method(); + $accessors = $this->getInaccessibleProperty(Facade::class, '_accessors'); + $components = $this->getInaccessibleProperty(Facade::class, '_components'); + $this->assertArrayHasKey('component', $accessors); + $this->assertArrayHasKey('component2', $accessors); + $this->assertArrayHasKey('component', $components); + $this->assertArrayHasKey('component2', $components); + + Facade::clearResolvedFacadeComponent('component'); + + $accessors = $this->getInaccessibleProperty(Facade::class, '_accessors'); + $components = $this->getInaccessibleProperty(Facade::class, '_components'); + $this->assertArrayNotHasKey('component', $accessors); + $this->assertArrayHasKey('component2', $accessors); + $this->assertArrayNotHasKey('component', $components); + $this->assertArrayHasKey('component2', $components); + } + + public function testClearResolvedFacadeComponents() + { + ComponentFacade::getProperty(); + ComponentFacade::method(); + Component2Facade::getProperty(); + Component2Facade::method(); + $accessors = $this->getInaccessibleProperty(Facade::class, '_accessors'); + $components = $this->getInaccessibleProperty(Facade::class, '_components'); + $this->assertArrayHasKey('component', $accessors); + $this->assertArrayHasKey('component2', $accessors); + $this->assertArrayHasKey('component', $components); + $this->assertArrayHasKey('component2', $components); + + Facade::clearResolvedFacadeComponents(); + + $accessors = $this->getInaccessibleProperty(Facade::class, '_accessors'); + $components = $this->getInaccessibleProperty(Facade::class, '_components'); + $this->assertEmpty($accessors); + $this->assertEmpty($components); + } + + public function testGetFacadeComponent() + { + $this->assertSame(\Yii::$app->get('component'), ComponentFacade::getFacadeComponent()); + $this->assertSame(\Yii::$app->get('component2'), Component2Facade::getFacadeComponent()); + } + + public function testGetFacadeApplication() + { + $this->setInaccessibleProperty(Facade::class, '_app', null); + $this->assertSame(\Yii::$app, ComponentFacade::getFacadeApplication()); + } + + public function testSetFacadeApplication() + { + $this->assertEquals(\Yii::$app, ComponentFacade::getFacadeApplication()); + ComponentFacade::getProperty(); + ComponentFacade::method(); + Component2Facade::getProperty(); + Component2Facade::method(); + $accessors = $this->getInaccessibleProperty(Facade::class, '_accessors'); + $components = $this->getInaccessibleProperty(Facade::class, '_components'); + $this->assertArrayHasKey('component', $accessors); + $this->assertArrayHasKey('component2', $accessors); + $this->assertArrayHasKey('component', $components); + $this->assertArrayHasKey('component2', $components); + + $component = \Yii::$app->get('component'); + $component2 = \Yii::$app->get('component2'); + $oldApp = \Yii::$app; + $this->createConsoleApplication($this->config); + $this->assertNotSame(\Yii::$app, $oldApp); + $this->assertSame($oldApp, Facade::getFacadeApplication()); + $this->assertNotSame(\Yii::$app, Facade::getFacadeApplication()); + + Facade::setFacadeApplication(\Yii::$app); + $accessors = $this->getInaccessibleProperty(Facade::class, '_accessors'); + $components = $this->getInaccessibleProperty(Facade::class, '_components'); + $this->assertEmpty($accessors); + $this->assertEmpty($components); + $this->assertSame(\Yii::$app->get('component'), ComponentFacade::getFacadeComponent()); + $this->assertSame(\Yii::$app->get('component2'), Component2Facade::getFacadeComponent()); + $this->assertNotSame($component, ComponentFacade::getFacadeComponent()); + $this->assertNotSame($component2, Component2Facade::getFacadeComponent()); + + $this->destroyApplication(); + \Yii::$app = $oldApp; + Facade::setFacadeApplication(\Yii::$app); + $this->assertSame(\Yii::$app->get('component'), ComponentFacade::getFacadeComponent()); + $this->assertSame(\Yii::$app->get('component2'), Component2Facade::getFacadeComponent()); + $this->assertSame($component, ComponentFacade::getFacadeComponent()); + $this->assertSame($component2, Component2Facade::getFacadeComponent()); + } + + public function testCallStatic() + { + /** @var Component $component */ + $component = \Yii::$app->get('component'); + $this->assertEquals($component->property, ComponentFacade::getProperty()); + + $newValue = 'foo'; + $component->property = $newValue; + $this->assertEquals($component->property, ComponentFacade::getProperty()); + + $newValue = 'bar'; + ComponentFacade::setProperty($newValue); + $this->assertEquals(ComponentFacade::getProperty(), $component->property); + + $this->assertEquals($newValue, ComponentFacade::method($newValue)); + } + + public function testPrivateConstruction() + { + $this->assertFalse((new \ReflectionMethod(ComponentFacade::class, '__construct'))->isPublic()); + $this->assertFalse((new \ReflectionMethod(ComponentFacade::class, '__clone'))->isPublic()); + $this->assertFalse((new \ReflectionMethod(ComponentFacade::class, '__wakeup'))->isPublic()); + } + + public function testMappings() + { + foreach ($this->mappings as $className => $id) { + /** @var Facade $class */ + $class = 'sergeymakinen\facades\\' . $className; + $this->assertEquals($id, $class::getFacadeComponentId()); + } + } + + protected function setUp() + { + parent::setUp(); + $this->createConsoleApplication($this->config); + Facade::setFacadeApplication(\Yii::$app); + } +} diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php new file mode 100644 index 0000000..5e16ff9 --- /dev/null +++ b/tests/ResponseTest.php @@ -0,0 +1,82 @@ + 'bar', + 'location' => '/' + ]; + + protected $data = [ + 'foo' => 'bar', + 'bar' => 'foo' + ]; + + public function testBare() + { + $response = Response::bare(204, $this->headers); + $this->assertEquals(204, $response->statusCode); + $this->checkResponse($response, \yii\web\Response::FORMAT_RAW, null); + } + + public function testHtml() + { + $response = Response::html($this->data, $this->headers); + $this->checkResponse($response, \yii\web\Response::FORMAT_HTML, $this->data); + } + + public function testJson() + { + $response = Response::json($this->data, $this->headers); + $this->checkResponse($response, \yii\web\Response::FORMAT_JSON, $this->data); + } + + public function testJsonp() + { + $response = Response::jsonp($this->data, 'foobar', $this->headers); + $this->checkResponse($response, \yii\web\Response::FORMAT_JSONP, [ + 'callback' => 'foobar', + 'data' => $this->data + ]); + } + + public function testRaw() + { + $response = Response::raw($this->data, $this->headers); + $this->checkResponse($response, \yii\web\Response::FORMAT_RAW, $this->data); + } + + public function testXml() + { + $response = Response::xml($this->data, $this->headers); + $this->checkResponse($response, \yii\web\Response::FORMAT_XML, $this->data); + } + + protected function setUp() + { + parent::setUp(); + $this->createWebApplication(); + Facade::setFacadeApplication(\Yii::$app); + } + + protected function checkResponse(\yii\web\Response $response, $format, $data) + { + $this->assertEquals($format, $response->format); + $this->assertSame($data, $response->data); + foreach ($this->headers as $name => $value) { + $this->assertTrue($response->headers->has($name)); + if ($name === 'location') { + $value = \Yii::$app->request->getHostInfo() . Url::to($value); + $this->assertEquals($value, $response->headers->get($name)); + } else { + $this->assertEquals($value, $response->headers->get($name)); + } + } + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..9ac3981 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,120 @@ +destroyApplication(); + } + + protected function createConsoleApplication($config = [], $class = \yii\console\Application::class) + { + new $class(ArrayHelper::merge([ + 'id' => 'console-test', + 'basePath' => __DIR__, + 'vendorPath' => __DIR__ . '/../vendor', + ], $config)); + } + + protected function createWebApplication($config = [], $class = \yii\web\Application::class) + { + new $class(ArrayHelper::merge([ + 'id' => 'web-test', + 'basePath' => __DIR__, + 'vendorPath' => __DIR__ . '/../vendor', + 'components' => [ + 'request' => [ + 'enableCookieValidation' => false, + 'scriptFile' => __DIR__ . '/index.php', + 'scriptUrl' => '/index.php', + ], + ] + ], $config)); + } + + protected function destroyApplication() + { + if (!isset(\Yii::$app)) { + return; + } + + if (\Yii::$app->has('session', true)) { + \Yii::$app->session->close(); + } + \Yii::$app = null; + } + + /** + * @param object|string $object + * @param string $name + * + * @return \ReflectionProperty + */ + protected function getProperty($object, $name) + { + $class = new \ReflectionClass($object); + while (!$class->hasProperty($name)) { + $class = $class->getParentClass(); + } + return $class->getProperty($name); + } + + /** + * @param object|string $object + * @param string $name + * + * @return \ReflectionMethod + */ + protected function getMethod($object, $name) + { + $class = new \ReflectionClass($object); + while (!$class->hasMethod($name)) { + $class = $class->getParentClass(); + } + return $class->getMethod($name); + } + + /** + * @param object|string $object + * @param string $name + * + * @return mixed + */ + protected function getInaccessibleProperty($object, $name) + { + $property = $this->getProperty($object, $name); + $property->setAccessible(true); + return $property->getValue($object); + } + + /** + * @param object|string $object + * @param string $name + * @param mixed $value + */ + protected function setInaccessibleProperty($object, $name, $value) + { + $property = $this->getProperty($object, $name); + $property->setAccessible(true); + $property->setValue($value); + } + + /** + * @param object|string $object + * @param string $name + * @param array $args + * + * @return mixed + */ + protected function invokeInaccessibleMethod($object, $name, array $args = []) + { + $method = $this->getMethod($object, $name); + $method->setAccessible(true); + return $method->invokeArgs($object, $args); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..8f67a47 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,20 @@ +addPsr4('sergeymakinen\tests\\', __DIR__, true); +$loader->register(); + +$_SERVER['SCRIPT_FILENAME'] = __FILE__; +$_SERVER['SCRIPT_NAME'] = '/index.php'; +$_SERVER['SERVER_NAME'] = 'example.com'; + +define('YII_DEBUG', true); +define('YII_ENABLE_ERROR_HANDLER', false); + +require_once __DIR__ . '/../vendor/yiisoft/yii2/Yii.php'; + +require_once __DIR__ . '/TestCase.php'; diff --git a/tests/mocks/Component.php b/tests/mocks/Component.php new file mode 100644 index 0000000..a2035b6 --- /dev/null +++ b/tests/mocks/Component.php @@ -0,0 +1,13 @@ +