diff --git a/composer.json b/composer.json index d2a5730..3d16f30 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,15 @@ "require": { "php": "^8" }, + "scripts": { + "test":"phpunit --verbose --testdox --colors tests " + }, "autoload": { "psr-4": { "Webrium\\": "src/" } + }, + "require-dev": { + "phpunit/phpunit": "^9.6" } } diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..048fc38 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1764 @@ +{ + "_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#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "9f436cf826f1687f87d5307a897dc355", + "packages": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "2.0.x-dev", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "f49f6a836a816609c853718ba2ea422dc18a8e4a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f49f6a836a816609c853718ba2ea422dc18a8e4a", + "reference": "f49f6a836a816609c853718ba2ea422dc18a8e4a", + "shasum": "" + }, + "require": { + "php": "^8.1" + }, + "require-dev": { + "doctrine/coding-standard": "^11", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.9.4", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "^10.1.0", + "vimeo/psalm": "^5.4" + }, + "default-branch": true, + "type": "library", + "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": "https://ocramius.github.io/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "keywords": [ + "constructor", + "instantiate" + ], + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/2.0.x" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", + "type": "tidelift" + } + ], + "time": "2023-08-24T20:23:35+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.x-dev", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "202aaf6b7c2e1e0a622b0298e9f3f537e4d84018" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/202aaf6b7c2e1e0a622b0298e9f3f537e4d84018", + "reference": "202aaf6b7c2e1e0a622b0298e9f3f537e4d84018", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3 <3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "default-branch": true, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.x" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2023-11-01T08:01:43+00:00" + }, + { + "name": "nikic/php-parser", + "version": "4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "e453389866395e57146efe12077458c2d906687d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/e453389866395e57146efe12077458c2d906687d", + "reference": "e453389866395e57146efe12077458c2d906687d", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/4.x" + }, + "time": "2023-11-12T15:49:53+00:00" + }, + { + "name": "phar-io/manifest", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "67729272c564ab9f953c81f48db44e8b1cb1e1c3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/67729272c564ab9f953c81f48db44e8b1cb1e1c3", + "reference": "67729272c564ab9f953c81f48db44e8b1cb1e1c3", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-phar": "*", + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.3 || ^8.0" + }, + "default-branch": true, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/master" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2023-06-01T14:19:47+00:00" + }, + { + "name": "phar-io/version", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" + }, + "time": "2022-02-21T01:04:05+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "9.2.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "00bc23209e885ae1aab33c9a2303b0eb8ebd5c28" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/00bc23209e885ae1aab33c9a2303b0eb8ebd5c28", + "reference": "00bc23209e885ae1aab33c9a2303b0eb8ebd5c28", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^4.15", + "php": ">=7.3", + "phpunit/php-file-iterator": "^3.0.3", + "phpunit/php-text-template": "^2.0.2", + "sebastian/code-unit-reverse-lookup": "^2.0.2", + "sebastian/complexity": "^2.0", + "sebastian/environment": "^5.1.2", + "sebastian/lines-of-code": "^1.0.3", + "sebastian/version": "^3.0.1", + "theseer/tokenizer": "^1.2.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-11-09T06:48:38+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "3.0.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "38b24367e1b340aa78b96d7cab042942d917bb84" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/38b24367e1b340aa78b96d7cab042942d917bb84", + "reference": "38b24367e1b340aa78b96d7cab042942d917bb84", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2022-02-11T16:23:04+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T05:58:55+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T05:33:50+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "5.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:16:10+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "9.6.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "d492067162cc3685ef35452e6ac02bd09744aa95" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d492067162cc3685ef35452e6ac02bd09744aa95", + "reference": "d492067162cc3685ef35452e6ac02bd09744aa95", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.3.1 || ^2", + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.10.1", + "phar-io/manifest": "^2.0.3", + "phar-io/version": "^3.0.2", + "php": ">=7.3", + "phpunit/php-code-coverage": "^9.2.28", + "phpunit/php-file-iterator": "^3.0.5", + "phpunit/php-invoker": "^3.1.1", + "phpunit/php-text-template": "^2.0.3", + "phpunit/php-timer": "^5.0.2", + "sebastian/cli-parser": "^1.0.1", + "sebastian/code-unit": "^1.0.6", + "sebastian/comparator": "^4.0.8", + "sebastian/diff": "^4.0.3", + "sebastian/environment": "^5.1.3", + "sebastian/exporter": "^4.0.5", + "sebastian/global-state": "^5.0.1", + "sebastian/object-enumerator": "^4.0.3", + "sebastian/resource-operations": "^3.0.3", + "sebastian/type": "^3.2", + "sebastian/version": "^3.0.2" + }, + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.6-dev" + } + }, + "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6" + }, + "funding": [ + { + "url": "https://phpunit.de/sponsors.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2023-11-12T09:29:13+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T06:08:49+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/1fc9f64c0927627ef78ba436c9b17d967e68e120", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.8" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:08:54+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T05:30:19+00:00" + }, + { + "name": "sebastian/comparator", + "version": "4.0.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "b247957a1c8dc81a671770f74b479c0a78a818f1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/b247957a1c8dc81a671770f74b479c0a78a818f1", + "reference": "b247957a1c8dc81a671770f74b479c0a78a818f1", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/diff": "^4.0", + "sebastian/exporter": "^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2022-09-14T12:46:14+00:00" + }, + { + "name": "sebastian/complexity", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "739b35e53379900cc9ac327b2147867b8b6efd88" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/739b35e53379900cc9ac327b2147867b8b6efd88", + "reference": "739b35e53379900cc9ac327b2147867b8b6efd88", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.7", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T15:52:27+00:00" + }, + { + "name": "sebastian/diff", + "version": "4.0.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/4.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-05-07T05:35:17+00:00" + }, + { + "name": "sebastian/environment", + "version": "5.1.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-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" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/5.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:03:51+00:00" + }, + { + "name": "sebastian/exporter", + "version": "4.0.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", + "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "https://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2022-09-14T06:03:37+00:00" + }, + { + "name": "sebastian/global-state", + "version": "5.0.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "bde739e7565280bda77be70044ac1047bc007e34" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", + "reference": "bde739e7565280bda77be70044ac1047bc007e34", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-08-02T09:26:13+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.6", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-28T06:42:11+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "4.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71", + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:12:34+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:14:26+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "4.0.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "https://github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:07:39+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "20bdda85c7c585ab265c0c37ec052a019bae29c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/20bdda85c7c585ab265c0c37ec052a019bae29c4", + "reference": "20bdda85c7c585ab265c0c37ec052a019bae29c4", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "default-branch": true, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "support": { + "source": "https://github.com/sebastianbergmann/resource-operations/tree/main" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-03-25T08:11:39+00:00" + }, + { + "name": "sebastian/type", + "version": "3.2.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/3.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:13:03+00:00" + }, + { + "name": "sebastian/version", + "version": "3.0.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "c6c1022351a901512170118436c764e473f6de8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c", + "reference": "c6c1022351a901512170118436c764e473f6de8c", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/3.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T06:39:44+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.2.1" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2021-07-28T10:34:58+00:00" + } + ], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": "^8" + }, + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..f2bbb59 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,19 @@ + + + + ./tests/FormValidationTest.php + + + + \ No newline at end of file diff --git a/src/FormValidation.php b/src/FormValidation.php index 09749e7..3b3250d 100644 --- a/src/FormValidation.php +++ b/src/FormValidation.php @@ -7,270 +7,647 @@ class FormValidation { - private $currentName; - private $fakeName=false; - private $currentValue; - private $errors=[]; - private $list=[]; - private $type; - private $messages; + private array $form_data_params; + private static array $validation_messages; + private array $validation_data; - public function field($name,$translation=false) - { - $this->currentName = $name; - $this->fakeName = $translation; + private string $current_field; - $this->currentValue = input($name,null); + private array $error_list = []; + + + /** + * Construct a new FormValidation object. + * + * @param array|null $form_data_params The form data parameters. + */ + function __construct($form_data_params = null) + { + if ($form_data_params === null) { + $this->form_data_params = input(); + } else { + $this->form_data_params = $form_data_params; - $message_path = Directory::path('langs').'/'.App::getLocale().'/validation.php'; - if (File::exists($message_path)) { - $this->messages = include $message_path; - } - else { - $this->messages = false; } - if ($this->fakeName==false) { - $this->fakeName = $this->messages['attributes'][$name]??false; + $this->loadValidationMessages(); + } + + + + /** + * Load the validation messages from a file. + */ + private function loadValidationMessages(): void + { + + $validation_message_path = Directory::path('langs') . '/' . App::getLocale() . '/validation.php'; + if (isset(FormValidation::$validation_messages) == false) { + if (File::exists($validation_message_path) == true) { + FormValidation::$validation_messages = include_once $validation_message_path; + } else { + throw new \Exception("File not found in path '$validation_message_path'", 1); + } + } + } + + + /** + * Validate the value of a field. + * + * @param string $name The name of the field. + * @param string|null $translation The translation of the field name. + * @return FormValidation + */ + public function field(string $name, $translation = null) + { - $this->type = false; + $this->current_field = $name; + + $this->validation_data[$name] = [ + 'has_value' => false, + 'name' => $name, + 't_name' => $translation, + 'rules' => [], + ]; return $this; } - public function numeric($message=false) + + + /** + * Adds a numeric validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function numeric($custom_message = null) { - $this->type = 'numeric'; + return $this->addNewRule('numeric', $custom_message); + } - if (! \is_numeric($this->currentValue)) { - $message = $this->initMessage($this->messages['numeric'],$message); - $this->addError($message); - } - return $this; + /** + * Adds an integer validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function integer($custom_message = null) + { + return $this->addNewRule('integer', $custom_message); } - public function string($message=false) + /** + * Adds a string validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function string($custom_message = null) { - $this->type = 'string'; + return $this->addNewRule('string', $custom_message); + } - if (! \is_string($this->currentValue) || \is_numeric($this->currentValue)) { - $message = $this->initMessage($this->messages['string'],$message); - $this->addError($message); - } - return $this; + /** + * Adds a digits validation rule to the current field. + * + * @param int $digits The number of digits. + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function digits(int $digits, $custom_message = null) + { + return $this->addNewRule('digits', $custom_message, $digits); } - public function min($min,$message=false) + + /** + * Adds a digits_between validation rule to the current field. + * + * @param int $min The minimum number of digits. + * @param int $max The maximum number of digits. + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function digitsBetween(int $min, int $max, $custom_message = false) { - if (is_string($this->currentValue) && (! $this->type || $this->type =='string' )) { - $message = $this->initMessage($this->messages['min']['string'],$message); - $message = \str_replace(':min',$min,$message); + return $this->addNewRule('digits_between', $custom_message, $min, $max); + } - if (\mb_strlen($this->currentValue) < $min ) { - $this->addError($message); - } - } - elseif (\is_numeric($this->currentValue) && (! $this->type || $this->type =='numeric' ) ) { - $message = $this->initMessage($this->messages['min']['numeric'],$message); - $message = \str_replace(':min',$min,$message); - if ( $this->currentValue < $min ) { - $this->addError($message); - } - } - elseif (is_array($this->currentValue) && (! $this->type || $this->type =='array' )) { - $message = $this->initMessage($this->messages['min']['array'],$message); - $message = \str_replace(':min',$min,$message); + /** + * Adds a different validation rule to the current field. + * + * @param mixed $other_value The value to compare the current value to. + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function different($other_value, $custom_message = false) + { + return $this->addNewRule('different', $custom_message, $other_value); + } - if ( count($this->currentValue) < $min ) { - $this->addError($message); - } - } - return $this; + /** + * Adds a confirmed validation rule to the current field. + * + * @param string $field The name of the field to compare the current value to. + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function confirmed($field, $custom_message = false) + { + return $this->addNewRule('confirmed', $custom_message, $field); } - public function max($max,$message=false) + /** + * Adds a min validation rule to the current field. + * + * @param int|float $min_value The minimum value. + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function min($min_value, $custom_message = null) { + return $this->addNewRule('min', $custom_message, $min_value); + } - if (is_string($this->currentValue) && (! $this->type || $this->type =='string' ) ) { - $message = $this->initMessage($this->messages['max']['string'],$message); - $message = \str_replace(':max',$max,$message); + /** + * Adds a max validation rule to the current field. + * + * @param int|float $max_value The maximum value. + * @param string|null $custom_message The custom error + * @return FormValidation The current FormValidation instance. + */ + public function max($max_value, $custom_message = null) + { + return $this->addNewRule('max', $custom_message, $max_value); + } - if (\mb_strlen($this->currentValue) > $max ) { - $this->addError($message); - } - } - elseif (\is_numeric($this->currentValue) && (! $this->type || $this->type =='numeric' )) { - $message = $this->initMessage($this->messages['max']['numeric'],$message); - $message = \str_replace(':max',$max,$message); + /** + * Adds a required validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function required($custom_message = false) + { + return $this->addNewRule('required', $custom_message); + } - if ( $this->currentValue > $max ) { - $this->addError($message); - } - } - elseif (is_array($this->currentValue) && (! $this->type || $this->type =='array' )) { - $message = $this->initMessage($this->messages['max']['array'],$message); - $message = \str_replace(':max',$max,$message); + /** + * Adds an email validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function email($custom_message = false) + { + return $this->addNewRule('email', $custom_message); - if ( count($this->currentValue) > $max ) { - $this->addError($message); - } - } + } - return $this; + + /** + * Adds a url validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function url($custom_message = false) + { + return $this->addNewRule('url', $custom_message); } - public function required($message=false) + + /** + * Adds a domain validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function domain($custom_message = false) { - $message = $this->initMessage($this->messages['required'],$message); + return $this->addNewRule('domain', $custom_message); + } - if (empty($this->currentValue)) { - $this->addError($message); - } - return $this; + + /** + * Adds a mac validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function mac($custom_message = false) + { + return $this->addNewRule('mac', $custom_message); } - public function accepted($message=false) + + /** + * Adds an ip validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function ip($custom_message = false) { - $message = $this->initMessage($this->messages['accepted'],$message); + return $this->addNewRule('ip', $custom_message); + } - if (input($this->currentName,false)==false) { - $this->addError($message); - } - return $this; + + /** + * Adds a boolean validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function boolean($custom_message = false) + { + return $this->addNewRule('boolean', $custom_message); } - public function confirmed($name_2,$message=false) + + /** + * Adds an array validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function array($custom_message = false) { - $message = $this->initMessage($this->messages['confirmed'],$message); + return $this->addNewRule('array', $custom_message); + } - if ($this->currentValue != input($name_2)) { - $this->addError($message); - } - return $this; + + /** + * Adds an object validation rule to the current field. + * + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function object($custom_message = false) + { + return $this->addNewRule('object', $custom_message); } - public function email($message=false) + + /** + * Adds a between validation rule to the current field. + * + * @param int|float $min The minimum value. + * @param int|float $max The maximum value. + * @param string|null $custom_message The custom error message for the rule. + * @return FormValidation The current FormValidation instance. + */ + public function between($min, $max, $custom_message = null) { - $this->usePHPFilter($this->messages['email'],$message,FILTER_VALIDATE_EMAIL); - return $this; + return $this->addNewRule('between', $custom_message, $min, $max); } - public function url($message=false) + // public function file($custom_message = null) + // { + // return $this->addNewRule('file', $custom_message); + // } + + // public function size(int $size_number, $custom_message) + // { + // return $this->addNewRule('size', $custom_message, $size_number); + // } + + + + /** + * Add a new validation rule. + * + * @param string $type The type of validation rule. + * @param string $message The custom message for the validation rule. + * @param mixed|null $value1 The first value for the validation rule. + * @param mixed|null $value2 The second value for the validation rule. + * @return FormValidation + */ + private function addNewRule(string $type, $message, $value1 = null, $value2 = null) { - $this->usePHPFilter($this->messages['url'],$message,FILTER_VALIDATE_URL); + $this->validation_data[$this->current_field]['rules'][] = ['type' => $type, 'custom_message' => $message, 'value1' => $value1, 'value2' => $value2]; return $this; } - public function mac($message=false) + + /** + * Add an error to the error list. + * + * @param string $field_name The name of the field with the error. + * @param array $validation_result The result of the validation check. + * @param array $rule The validation rule that caused the error. + */ + private function addError(string $field_name, array $validation_result, array $rule) { - $this->usePHPFilter($this->messages['mac'],$message,FILTER_VALIDATE_MAC); - return $this; + $message = $this->generateErrorMessage($field_name, $validation_result, $rule); + $this->error_list[] = ['field' => $field_name, 'message' => $message]; } - public function usePHPFilter($cmessage,$message,$FILTER) + /** + * Get the first error in the error list. + * + * @return array|false The first error or false if there are no errors. + */ + public function getFirstError() { - if(! filter_var($this->currentValue, $FILTER)) { - $message = $this->initMessage($cmessage,$message); - $this->addError($message); - } + return $this->error_list[0] ?? false; + } - return $this; + + /** + * Get the first error message. + * + * @return array|false The first error message or false. + */ + public function getFirstErrorMessage() + { + return $this->getFirstError()['message'] ?? false; } - public function addError($error){ - $error = \str_replace('@field',$this->currentName,$error); - $this->errors[$this->currentName][] = $error; - $this->list[] = $error; - return $this; + + /** + * Get all errors in the error list. + * + * @return array An array of errors. + */ + public function getAllError() + { + return $this->error_list ?? []; } - public function getErrors(){ - return $this->errors; + private function generateErrorMessage(string $field_name, $validation_result, $rule): string + { + if ($rule['custom_message'] == false) { + $message = $this->getValidationErrorMessage($validation_result[1]); + } else { + $message = $rule['custom_message']; + } + + $data = $this->validation_data[$field_name]; + $name = $data['name']; + $t_name = $data['t_name']; + + $message = str_replace(':attribute', $t_name ?? $name, $message); + + foreach ($validation_result[2] ?? [] as $key => $value) { + $message = str_replace(':' . $key, $value, $message); + } + + return $message; } - public function error() + private function getValidationErrorMessage(array $array) { - $error = new GetError; - $error->set($this->errors,$this->list); - return $error; + if (count($array) == 1) { + return FormValidation::$validation_messages[$array[0]] ?? null; + } else if (count($array) == 2) { + return FormValidation::$validation_messages[$array[0]][$array[1]] ?? null; + } } - public function autoCheck() + + private function process() { - if ($this->isValid()==false) { - back()->withError($this->error()->all())->withInput()->die(); + $validation = true; + foreach ($this->validation_data as $data) { + + $name = $data['name']; + $rules = $data['rules']; + + if (isset($this->form_data_params[$name]) && empty($this->form_data_params[$name]) == false) { + $this->validation_data[$name]['has_value'] = true; + } + + + foreach ($rules as $rule) { + + if ($this->validation_data[$name]['has_value'] == false && $rule['type'] != 'required') { + break; + } + + $method_exec_name = '_check_' . $rule['type']; + + $result = $this->$method_exec_name($rule, $name); + + if ($result[0] == false) { + $this->addError($name, $result, $rule); + $validation = false; + } + + } + } + + return $validation; } - public function isValid() + + private function getParam($name) + { + return $this->form_data_params[$name] ?? null; + } + + private function getCurrentValue() + { + return $this->getParam($this->current_field); + } + + public function _check_required($rule, $name) { - if (count($this->getErrors())==0) { - return true; + // echo "\ncheck ".$this->validation_data[$name]['has_value']."\n"; + return [$this->validation_data[$name]['has_value'] ?? false, ['required']]; + } + + private function _check_string($rule, $name): array + { + $value = $this->getParam($name); + return [(is_string($value) && (gettype($value) == 'string')), ['string']]; + } + + private function _check_numeric($rule, $name): array + { + return [is_numeric($this->getParam($name)), ['numeric']]; + } + + private function _check_integer($rule, $name): array + { + return [gettype($this->getParam($name)) == 'integer', ['integer']]; + } + + public function _check_digits($rule, $name): array + { + $status = true; + if ($this->getParam($name) != null) { + $digits = $rule['value1'] ?? null; + $status = (strlen((string) $this->getParam($name)) == $digits); } - return false; + return [$status, ['digits'], ['digits' => $digits ?? '']]; } - private function initMessage($text,$customMessage=false) + public function _check_digits_between($rule, $name): array { - if ($customMessage) { - $text = $customMessage; + $min = $rule['value1']; + $max = $rule['value2']; + $digits = strlen((string) $this->getParam($name)); + + $status = false; + if ($digits <= $max && $digits >= $min) { + $status = true; } - $text = \str_replace(':attribute',($this->fakeName?$this->fakeName:$this->currentName),$text); + return [$status, ['digits_between'], ['min' => $min, 'max' => $max]]; + } + + + public function _check_different($rule, $name): array + { + $other = $this->getParam($rule['value1']); - if ($this->fakeName) { - $text = \str_replace($this->currentName,$this->fakeName,$text); + $status = true; + if ($other == $this->getParam($name)) { + $status = false; } - return $text; + return [$status, ['different'], ['other' => $other]]; } -} -class GetError{ + public function _check_confirmed($rule, $name): array + { + $field = $this->getParam($rule['value1']); + + $status = false; + if ($field == $this->getParam($name)) { + $status = true; + } + + return [$status, ['confirmed']]; + } + + private function _check_min($rule, $name): array + { + $value = $this->getParam($name); + $min = $rule['value1']; + $status = true; + $error_message_array = []; + $type = gettype($value); + + if ($type == 'string' && \mb_strlen($value) < $min) { + $status = false; + $error_message_array = ['min', 'string']; + } else if ($type == 'integer' && $value < $min) { + $status = false; + $error_message_array = ['min', 'integer']; + } else if (is_array($value) && count($value) < $min) { + $status = false; + $error_message_array = ['min', 'array']; + } - protected $array; - protected $list; + return [$status, $error_message_array, ['min' => $min]]; + } - public function set($array,$list) + private function _check_max($rule, $name): array { - $this->array = $array; - $this->list = $list; + $value = $this->getParam($name); + $max = $rule['value1']; + $status = true; + $type = gettype($value); + $error_message_array = []; + + + if ($type == 'string' && \mb_strlen($value) > $max) { + $status = false; + $error_message_array = ['max', 'string']; + } else if ($type == 'integer' && $value > $max) { + $status = false; + $error_message_array = ['max', 'integer']; + } else if (is_array($value) && count($value) > $max) { + $status = false; + $error_message_array = ['max', 'array']; + } - return $this; + return [$status, $error_message_array, ['max' => $max]]; } - public function all() + private function _check_email($rule, $name): array { - return $this->list; + $status = $this->filter($this->getParam($name), FILTER_VALIDATE_EMAIL); + return [$status, ['email'],]; } - public function withFields() + + + private function _check_url($rule, $name): array { - return $this->array; + $status = (!$this->filter($this->getParam($name), FILTER_VALIDATE_URL) === false); + return [$status, ['url'],]; } - public function first() + private function _check_domain($rule, $name): array { - if (isset($this->list[0])) { - return $this->list[0]; - } - else { - return false; + + $url = $this->getParam($name); + $domain = str_replace('https://', '', $url); + $domain = str_replace('http://', '', $domain); + + // Define a regular expression pattern for a valid domain name + $pattern = '/^(?!\-)(?:(?:[a-zA-Z\d][a-zA-Z\d\-]{0,61})?[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/'; + + // Use preg_match to check if the domain matches the pattern + if (preg_match($pattern, $domain)) { + $status = true; + } else { + $status = false; } + + return [$status, ['url']]; + } + + private function _check_mac($rule, $name): array + { + $status = $this->filter($this->getParam($name), FILTER_VALIDATE_MAC); + return [$status, ['mac']]; + } + + private function _check_array($rule, $name): array + { + $status = is_array($this->getParam($name)); + return [$status, ['array']]; + } + + private function _check_object($rule, $name): array + { + $status = is_object($this->getParam($name)); + return [$status, ['object']]; } - public function asString($separator="\n") + private function _check_ip($rule, $name) { - return \implode($separator,$this->all()); + $status = $this->filter($this->getParam($name), FILTER_VALIDATE_IP); + return [$status, ['mac']]; } -} + + + private function filter($value, $FILTER) + { + return filter_var($value, $FILTER); + } + + + public function isValid() + { + return $this->process(); + } + +} \ No newline at end of file diff --git a/src/Url.php b/src/Url.php index 69abfab..c863dbb 100644 --- a/src/Url.php +++ b/src/Url.php @@ -31,7 +31,7 @@ public static function scheme($full=false) } - public static function domain() + public static function domain():string { return $_SERVER['HTTP_HOST']??''; } diff --git a/tests/.htaccess b/tests/.htaccess deleted file mode 100644 index f133675..0000000 --- a/tests/.htaccess +++ /dev/null @@ -1,8 +0,0 @@ -AddDefaultCharset UTF-8 - - - RewriteEngine On - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L] - diff --git a/tests/FormValidationTest.php b/tests/FormValidationTest.php new file mode 100644 index 0000000..c7b962b --- /dev/null +++ b/tests/FormValidationTest.php @@ -0,0 +1,640 @@ + 'fdsfdsajklfas', + ]; + + $form = new FormValidation($array); + + $form->field('email')->email(); + + $this->assertFalse($form->isValid()); + + + + $array = [ + 'email' => 'test@gmail.com', + ]; + + $form = new FormValidation($array); + + $form->field('email')->email(); + + $this->assertTrue($form->isValid()); + } + + public function testCheckUrlValidation() + { + + $array = [ + 'site_url' => 'https://google.com', + ]; + + $form = new FormValidation($array); + + $form->field('site_url')->url(); + + $this->assertTrue($form->isValid()); + + + $array = [ + 'site_url' => 'httpgoogle.com', + ]; + + $form = new FormValidation($array); + + $form->field('site_url')->url(); + + $this->assertFalse($form->isValid()); + } + + public function testCheckDomainValidation() + { + + $array = [ + 'site_url' => 'https://google.com', + ]; + + $form = new FormValidation($array); + + $form->field('site_url')->domain(); + + $this->assertTrue($form->isValid()); + + + $array = [ + 'site_url' => 'https://google', + ]; + + $form = new FormValidation($array); + + $form->field('site_url')->domain(); + + $this->assertFalse($form->isValid()); + } + + public function testCheckMacValidation() + { + + $array = [ + 'mac' => '00-B0-D0-63-C2-26', + ]; + + $form = new FormValidation($array); + + $form->field('mac')->mac(); + + $this->assertTrue($form->isValid()); + + + $array = [ + 'mac' => '00-B0-D0-63-C2-2', + ]; + + $form = new FormValidation($array); + + $form->field('mac')->mac(); + + $this->assertFalse($form->isValid()); + } + + public function testCheckIpValidation() + { + + $array = [ + 'ip' => '8.8.8.8', + ]; + + $form = new FormValidation($array); + + $form->field('ip')->ip(); + + $this->assertTrue($form->isValid()); + + + $array = [ + 'ip' => '8.8.8.266', + ]; + + $form = new FormValidation($array); + + $form->field('ip')->ip(); + + $this->assertFalse($form->isValid()); + } + + public function testCheckMinAndMaxStringLength() + { + $array = [ + 'name' => 'BE', + ]; + + $form = new FormValidation($array); + + $form->field('name')->min(3); + + $is_valid = $form->isValid(); + $message = $form->getFirstError(); + + $this->assertFalse($is_valid, $message['message'] ?? ''); + + + $array = [ + 'name' => 'BEN', + 'mobile' => '09999999990', + + ]; + + $form = new FormValidation($array); + + $form->field('name')->min(3)->max(3); + $form->field('mobile')->min(11)->max(11); + + $is_valid = $form->isValid(); + $message = $form->getFirstError(); + + $this->assertTrue($is_valid, $message['message'] ?? ''); + + + } + + + public function testCheckMinAndMaxIntegerLength() + { + + + $array = [ + 'age' => 15, + ]; + + $form = new FormValidation($array); + + $form->field('age')->min(18); + + $is_valid = $form->isValid(); + + $this->assertFalse($is_valid); + + + + $array = [ + 'age' => 18, + ]; + + $form = new FormValidation($array); + + $form->field('age')->min(18)->max(30); + + $is_valid = $form->isValid(); + + $this->assertTrue($is_valid); + + + + $array = [ + 'age' => 19, + ]; + + $form = new FormValidation($array); + + $form->field('age')->max(18); + + $is_valid = $form->isValid(); + + $this->assertFalse($is_valid); + } + + public function testCheckMinAndMaxArrayLength() + { + $array = [ + 'category' => ['cat', 'car'], + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('category')->min(3)->isValid(); + + $this->assertFalse($is_valid); + + $array = [ + 'category' => ['cat', 'car'], + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('category')->min(2)->max(5)->isValid(); + + $this->assertTrue($is_valid); + + $array = [ + 'category' => ['cat', 'car', 'dog'], + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('category')->min(1)->max(2)->isValid(); + + $this->assertFalse($is_valid); + } + + + + public function testCheckIntegerAndNumericType() + { + $array = [ + 'age' => '19', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('age')->integer()->isValid(); + + $this->assertFalse($is_valid); + + + $array = [ + 'age' => 19, + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('age')->integer()->isValid(); + + $this->assertTrue($is_valid); + + + $array = [ + 'age' => 's44', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('age')->numeric()->isValid(); + + $this->assertFalse($is_valid); + + + $array = [ + 'age' => '44', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('age')->numeric()->isValid(); + + $this->assertTrue($is_valid); + } + + public function testCheckStringValidation() + { + $array = [ + 'name' => 'BEN', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('name')->string()->isValid(); + + $this->assertTrue($is_valid); + + + $array = [ + 'name' => 333, + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('name')->string()->isValid(); + + $this->assertFalse($is_valid); + + + $array = [ + 'name' => '333', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('name')->string()->isValid(); + + $this->assertTrue($is_valid); + } + + + public function testCheckArrayValidation(){ + $array = [ + 'category' => '333', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('category')->array()->isValid(); + + $this->assertFalse($is_valid); + + + $array = [ + 'category' => ['cat', 'dog'], + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('category')->array()->isValid(); + + $this->assertTrue($is_valid); + } + + public function testCheckOnjectValidation(){ + $array = [ + 'user' => '333', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('user')->object()->isValid(); + + $this->assertFalse($is_valid); + + $std = new stdClass; + $std->name = 'BEN'; + + $array = [ + 'user' => $std, + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('user')->object()->isValid(); + + $this->assertTrue($is_valid); + } + + + public function testCheckDigitsValidation() + { + $array = [ + 'mobile' => '09999999999', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('mobile')->digits(11)->isValid(); + + $this->assertTrue($is_valid); + + + $array = [ + 'mobile' => '0999999999', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('mobile')->digits(11)->isValid(); + + $this->assertFalse($is_valid); + } + + + public function testCheckDigitsBetweenValidation() + { + $array = [ + 'mobile' => '0999999910', + 'mobile2' => '09999999911' + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('mobile')->digitsBetween(10, 11)->isValid(); + $is_valid = $form->field('mobile2')->digitsBetween(10, 11)->isValid(); + + $this->assertTrue($is_valid); + + + $array = [ + 'mobile' => '0999999999', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('mobile')->digitsBetween(11, 12)->isValid(); + + $this->assertFalse($is_valid); + + $array = [ + 'mobile' => '0999999999000', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('mobile')->digitsBetween(11, 12)->isValid(); + + $this->assertFalse($is_valid); + } + + + public function testCheckDifferentValidation(){ + $array = [ + 'father_mobile' => '0999999999000', + 'mother_mobile' => '0999999999001', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('father_mobile')->different('mother_mobile')->isValid(); + + $this->assertTrue($is_valid); + + $array = [ + 'father_mobile' => '0999999999000', + 'mother_mobile' => '0999999999000', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('father_mobile')->different('mother_mobile')->isValid(); + + $this->assertFalse($is_valid); + } + + + public function testCheckConfirmedValidation(){ + $array = [ + 'password' => '1234567', + 'confirm_password' => '1234567', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('password')->confirmed('confirm_password')->isValid(); + + $this->assertTrue($is_valid); + + $array = [ + 'password' => '1234567', + 'confirm_password' => '123456', + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('password')->confirmed('confirm_password')->isValid(); + + $this->assertFalse($is_valid); + } + + + public function testCheckRequiredValidation(){ + $array = [ + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('username')->required()->isValid(); + + $this->assertFalse($is_valid); + + $array = [ + 'username'=>'' + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('username')->required()->isValid(); + + $this->assertFalse($is_valid); + + + $array = [ + 'username'=>'dsfsdfs' + ]; + + $form = new FormValidation($array); + + $is_valid = $form->field('username')->required()->isValid(); + + $this->assertTrue($is_valid); + } + + + public function testCheckIgnoreConditionsWhenNoValueIsPassed(){ + $array = [ + ]; + + $form = new FormValidation($array); + $form->field('username')->digits(10); + $is_valid = $form->isValid(); + $this->assertTrue($is_valid, $form->getFirstError()['message']??''); + } + + + public function testCheckErrorMessages(){ + + $array = [ + 'name'=>'BEN', + 'email'=>'benkhaliferoton.me', + 'username'=>'benkhalife', + 'password'=> '1234567', + 'confirm_password'=> '12345678', + // 'age'=>18, + ]; + $form = new FormValidation($array); + $form->field('email')->required()->email(); + $form->field('age')->required(); + + + $is_valid = $form->isValid(); + + $this->assertEquals('The email must be a valid email address.', $form->getFirstError()['message']??''); + + + $array = [ + 'name'=>'BEN', + 'email'=>'benkhalif@proton.me', + 'username'=>'benkhalife', + 'password'=> '1234567', + 'confirm_password'=> '12345678', + 'age'=>'18', + ]; + $form = new FormValidation($array); + $form->field('email')->required()->email(); + $form->field('age')->required()->integer(); + + + $is_valid = $form->isValid(); + + $this->assertEquals('The age must be an integer.', $form->getFirstError()['message']??''); + } + + + public function testSimulationOfRealValidationMode(){ + $array = [ + 'name'=>'BEN', + 'email'=>'benkhalife@proton.me', + 'username'=>'benkhalife', + 'password'=> '12345678', + 'confirm_password'=> '12345678', + 'age'=>18, + ]; + + $form = new FormValidation($array); + $form->field('name')->required()->min(2)->max(25); + $form->field('email')->required()->email(); + $form->field('password')->required()->confirmed('confirm_password')->min(6); + $form->field('age')->required()->integer()->min(12)->max(99); + + $is_valid = $form->isValid(); + $this->assertTrue($is_valid, $form->getFirstError()['message']??''); + + + + $array = [ + 'name'=>'BEN', + 'email'=>'benkhalife@proton.me', + 'username'=>'benkhalife', + 'password'=> '12345678', + 'confirm_password'=> '12345678', + // 'age'=>18, + ]; + + $form = new FormValidation($array); + $form->field('name')->required()->min(2)->max(25); + $form->field('username')->required()->min(2)->max(25); + $form->field('email')->required()->email(); + $form->field('password')->required()->confirmed('confirm_password')->min(6); + $form->field('age')->integer()->min(12)->max(99); + + $is_valid = $form->isValid(); + $this->assertTrue($is_valid, $form->getFirstError()['message']??''); + + + + $array = [ + 'name'=>'BEN', + 'email'=>'benkhaliferoton.me', + 'username'=>'benkhalife', + 'password'=> '1234567', + 'confirm_password'=> '12345678', + // 'age'=>18, + ]; + + $form = new FormValidation($array); + $form->field('name')->required()->min(2)->max(25); + $form->field('username')->required()->min(2)->max(25); + $form->field('email')->required()->email(); + $form->field('password')->required()->confirmed('confirm_password')->min(6); + $form->field('age')->integer()->min(12)->max(99); + + $is_valid = $form->isValid(); + $this->assertFalse($is_valid, $form->getFirstError()['message']??''); + } + + +} diff --git a/tests/config.php b/tests/config.php new file mode 100644 index 0000000..76bbfef --- /dev/null +++ b/tests/config.php @@ -0,0 +1,7 @@ +'successful']; -}); \ No newline at end of file