From f6bfd4eea7b017eff3a401651d2a43c5f7290024 Mon Sep 17 00:00:00 2001 From: "dorian.hodin" Date: Sun, 19 Mar 2023 00:43:39 +0100 Subject: [PATCH] Add some Unit tests, not all test are here, still cant link coverage.xml to SonarQube --- .idea/SAE4.01_FORMULAIRE.iml | 1 - Source/BusinessClass/ListBoxQuestion.php | 2 +- Source/Config/AltoRouter.php | 23 + Source/Config/Autoload.php | 24 +- Source/Config/Clean.php | 20 +- Source/Config/Connection.php | 54 - Source/Config/SplClassLoader.php | 4 +- Source/Config/Validate.php | 44 +- Source/Config/composer.json | 9 +- Source/Config/composer.lock | 977 +++++++++--------- Source/Config/config.php | 33 +- Source/Controller/ControllerAdmin.php | 27 +- Source/Controller/ControllerCandidate.php | 2 + Source/Model/Factory.php | 4 +- Source/Model/FactoryQuestion.php | 2 +- .../TestBusinessClass/BoxQuestionTest.php | 55 + .../{ => TestBusinessClass}/FormTest.php | 16 +- .../IPrintQuestionStrategyTest.php | 21 + .../Tests/TestBusinessClass/KeywordTest.php | 31 + .../Tests/TestBusinessClass/QuestionTest.php | 39 + .../Tests/TestBusinessClass/ResponseTest.php | 49 + .../TestBusinessClass/TextQuestionTest.php | 25 + Source/Tests/TestConfig/AltoRouterTest.php | 73 ++ Source/Tests/TestConfig/AutoloadTest.php | 29 + Source/Tests/TestConfig/CleanTest.php | 47 + Source/Tests/TestConfig/ValidateTest.php | 70 ++ Source/Tests/TestController/.gitkeep | 0 Source/Tests/TestModel/.gitkeep | 0 Source/Tests/coverage.xml | 65 ++ Source/coverage.xml | 12 - 30 files changed, 1127 insertions(+), 631 deletions(-) delete mode 100644 Source/Config/Connection.php create mode 100644 Source/Tests/TestBusinessClass/BoxQuestionTest.php rename Source/Tests/{ => TestBusinessClass}/FormTest.php (90%) create mode 100644 Source/Tests/TestBusinessClass/IPrintQuestionStrategyTest.php create mode 100644 Source/Tests/TestBusinessClass/KeywordTest.php create mode 100644 Source/Tests/TestBusinessClass/QuestionTest.php create mode 100644 Source/Tests/TestBusinessClass/ResponseTest.php create mode 100644 Source/Tests/TestBusinessClass/TextQuestionTest.php create mode 100644 Source/Tests/TestConfig/AltoRouterTest.php create mode 100644 Source/Tests/TestConfig/AutoloadTest.php create mode 100644 Source/Tests/TestConfig/CleanTest.php create mode 100644 Source/Tests/TestConfig/ValidateTest.php create mode 100644 Source/Tests/TestController/.gitkeep create mode 100644 Source/Tests/TestModel/.gitkeep create mode 100644 Source/Tests/coverage.xml delete mode 100644 Source/coverage.xml diff --git a/.idea/SAE4.01_FORMULAIRE.iml b/.idea/SAE4.01_FORMULAIRE.iml index 5a2fa99..aa81e2c 100644 --- a/.idea/SAE4.01_FORMULAIRE.iml +++ b/.idea/SAE4.01_FORMULAIRE.iml @@ -5,7 +5,6 @@ - diff --git a/Source/BusinessClass/ListBoxQuestion.php b/Source/BusinessClass/ListBoxQuestion.php index 07c37b3..22d6d45 100644 --- a/Source/BusinessClass/ListBoxQuestion.php +++ b/Source/BusinessClass/ListBoxQuestion.php @@ -3,7 +3,7 @@ namespace BusinessClass; /** - * Définit une question avec plusieurs réponse mais une seule possible. + * Définit une question avec plusieurs réponses, mais une seule possible. */ class ListBoxQuestion extends BoxQuestion { diff --git a/Source/Config/AltoRouter.php b/Source/Config/AltoRouter.php index 059a8f7..5b87eb5 100644 --- a/Source/Config/AltoRouter.php +++ b/Source/Config/AltoRouter.php @@ -62,6 +62,29 @@ class AltoRouter $this->addMatchTypes($matchTypes); } + /** + * @return string + */ + public function getBasePath(): string + { + return $this->basePath; + } + + /** + * @return array + */ + public function getMatchTypes(): array + { + return $this->matchTypes; + } + + /** + * @return array + */ + public function getNamedRoutes(): array + { + return $this->namedRoutes; + } /** * Retrieves all routes. * Useful if you want to process or display routes. diff --git a/Source/Config/Autoload.php b/Source/Config/Autoload.php index 4d934b1..ba4a319 100644 --- a/Source/Config/Autoload.php +++ b/Source/Config/Autoload.php @@ -1,37 +1,47 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } - - - /** - * Éxécute une réquête SQL. - * - * @param string $query - * @param array $parameters - * @return bool Returns `true` on success, `false` otherwise - */ - public function executeQuery(string $query, array $parameters = []): bool - { - $this->stmt = parent::prepare($query); - foreach ($parameters as $name => $value) { - $this->stmt->bindValue($name, $value[0], $value[1]); - } - - return $this->stmt->execute(); - } - - - /** - * Permet de récupère le résultat de la dernière réquête éxecuté avec - * la fonction executeQuery(). - * - * @return array - */ - public function getResults(): array - { - return $this->stmt->fetchAll(); - - } -} \ No newline at end of file diff --git a/Source/Config/SplClassLoader.php b/Source/Config/SplClassLoader.php index 668ae98..98e4fed 100644 --- a/Source/Config/SplClassLoader.php +++ b/Source/Config/SplClassLoader.php @@ -1,5 +1,7 @@ = 3 && preg_match("#[a-zA-Z0-9]+#", $login) && strlen($login) <= $loginMaxLength); + // Vérifier si la longueur est supérieure à 3. + if (strlen($login) <= 3 || !ctype_alnum($login) || strlen($login) >= $GLOBALS['pseudoMaxLength']) { + return false; + } + return true; } /** @@ -42,66 +47,63 @@ class Validate public static function password(string $password) : bool { - global $passwordMaxLength; - return (strlen($password) >= 8 && strlen($password) <=$passwordMaxLength && + return (strlen($password) >= 8 && strlen($password) <=$GLOBALS['passwordMaxLength'] && preg_match("/\d/", $password) && preg_match("#[a-zA-Z]+#", $password)); } /** * Vérifie si le mot-clé est valide. * - * @param string $keyword Le mot-clé a vérifié. + * @param string $keyword Le mot-clé à vérifier * @return bool Vrai si le mot-clé est valide, faux sinon. */ public static function keyWord(string $keyword) : bool { - global $keyWordMaxLength; - return (strlen($keyword) <= $keyWordMaxLength && strlen($keyword) >= 3); + return (strlen($keyword) <= $GLOBALS['keyWordMaxLength'] && strlen($keyword) >= 3); } /** * Vérifie si le titre est valide. * - * @param string $title Le titre a vérifié. + * @param string $title Le titre à vérifier * @return bool Vrai si le titre est valide, faux sinon. */ public static function title(string $title) : bool { - global $titleMaxLength; - return (strlen($title) <= $titleMaxLength && strlen($title) >= 3); + return (strlen($title) <= $GLOBALS['titleMaxLength'] && strlen($title) >= 3); } /** * Vérifie si le type est valide. * - * @param string $type Le type a vérifié. + * @param string $type Le type à vérifier * @return bool Vrai si le type est valide, faux sinon. */ public static function type(string $type) : bool { - global $typeMaxLength; - return (strlen($type) <= $typeMaxLength && strlen($type) >=3); + return (strlen($type) <= $GLOBALS['typeMaxLength'] && strlen($type) >=3); } /** * Vérifie si la réponse est valide. * - * @param string $response La réponse a vérifié. + * @param string $response La réponse à vérifier * @return bool Vrai si la réponse est valide, faux sinon. */ public static function response(string $response) : bool { - global $responseMaxLength; - return (strlen($response) <= $responseMaxLength); + return (strlen($response) <= $GLOBALS['responseMaxLength'] && !empty($response)); } public static function username(string $username): bool { - global $usernameMaxLength; - return (strlen($username) >= 3 && preg_match("#[a-zA-Z0-9]+#", $username) && strlen($username) <= $usernameMaxLength); + if (strlen($username) <= 3 || !ctype_alnum($username) || strlen($username) >= $GLOBALS['usernameMaxLength']) { + return false; + } + return true; } } diff --git a/Source/Config/composer.json b/Source/Config/composer.json index 9b3900e..4f8fe47 100644 --- a/Source/Config/composer.json +++ b/Source/Config/composer.json @@ -3,14 +3,19 @@ "description": "composer for guzzle client", "require": { "guzzlehttp/psr7": "^2.4", - "guzzlehttp/guzzle": "^7.5", - "phpunit/phpunit": "^10.0" + "guzzlehttp/guzzle": "^7.5" }, "autoload": { + "classmap": [ + "../../Source/" + ], "psr-4": { "BusinessClass\\" : "../BusinessClass", "Config\\" : "../Config" } + }, + "require-dev": { + "phpunit/phpunit": "^10.0" } } diff --git a/Source/Config/composer.lock b/Source/Config/composer.lock index e8010d0..7eff834 100644 --- a/Source/Config/composer.lock +++ b/Source/Config/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ec899ea4c011f402975e722ae2c64082", + "content-hash": "d0a75076330551a7dae87f2ac5047fce", "packages": [ { "name": "guzzlehttp/guzzle", @@ -337,6 +337,279 @@ ], "time": "2023-03-09T13:19:02+00:00" }, + { + "name": "psr/http-client", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client/tree/master" + }, + "time": "2020-06-29T06:28:15+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/master" + }, + "time": "2019-04-30T12:38:16+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/master" + }, + "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e", + "reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.3-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.2.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-03-01T10:25:55+00:00" + } + ], + "packages-dev": [ { "name": "myclabs/deep-copy", "version": "1.11.1", @@ -523,213 +796,13 @@ "dist": { "type": "zip", "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", - "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" - }, - { - "name": "Sebastian Heuer", - "email": "sebastian@phpeople.de", - "role": "Developer" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "Developer" - } - ], - "description": "Library for handling version information and constraints", - "support": { - "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/3.2.1" - }, - "time": "2022-02-21T01:04:05+00:00" - }, - { - "name": "phpunit/php-code-coverage", - "version": "10.0.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "20800e84296ea4732f9a125e08ce86b4004ae3e4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/20800e84296ea4732f9a125e08ce86b4004ae3e4", - "reference": "20800e84296ea4732f9a125e08ce86b4004ae3e4", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-libxml": "*", - "ext-xmlwriter": "*", - "nikic/php-parser": "^4.15", - "php": ">=8.1", - "phpunit/php-file-iterator": "^4.0", - "phpunit/php-text-template": "^3.0", - "sebastian/code-unit-reverse-lookup": "^3.0", - "sebastian/complexity": "^3.0", - "sebastian/environment": "^6.0", - "sebastian/lines-of-code": "^2.0", - "sebastian/version": "^4.0", - "theseer/tokenizer": "^1.2.0" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "suggest": { - "ext-pcov": "PHP extension that provides line coverage", - "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "10.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 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", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.0.2" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-03-06T13:00:19+00:00" - }, - { - "name": "phpunit/php-file-iterator", - "version": "4.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "fd9329ab3368f59fe1fe808a189c51086bd4b6bd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/fd9329ab3368f59fe1fe808a189c51086bd4b6bd", - "reference": "fd9329ab3368f59fe1fe808a189c51086bd4b6bd", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "4.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.0.1" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-10T16:53:14+00:00" - }, - { - "name": "phpunit/php-invoker", - "version": "4.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-invoker.git", - "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", - "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", "shasum": "" }, "require": { - "php": ">=8.1" - }, - "require-dev": { - "ext-pcntl": "*", - "phpunit/phpunit": "^10.0" - }, - "suggest": { - "ext-pcntl": "*" + "php": "^7.2 || ^8.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-main": "4.0-dev" - } - }, "autoload": { "classmap": [ "src/" @@ -740,53 +813,69 @@ "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": "lead" + "role": "Developer" } ], - "description": "Invoke callables with a timeout", - "homepage": "https://github.com/sebastianbergmann/php-invoker/", - "keywords": [ - "process" - ], + "description": "Library for handling version information and constraints", "support": { - "issues": "https://github.com/sebastianbergmann/php-invoker/issues", - "source": "https://github.com/sebastianbergmann/php-invoker/tree/4.0.0" + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-03T06:56:09+00:00" + "time": "2022-02-21T01:04:05+00:00" }, { - "name": "phpunit/php-text-template", - "version": "3.0.0", + "name": "phpunit/php-code-coverage", + "version": "10.0.2", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d" + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "20800e84296ea4732f9a125e08ce86b4004ae3e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/9f3d3709577a527025f55bcf0f7ab8052c8bb37d", - "reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/20800e84296ea4732f9a125e08ce86b4004ae3e4", + "reference": "20800e84296ea4732f9a125e08ce86b4004ae3e4", "shasum": "" }, "require": { - "php": ">=8.1" + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^4.15", + "php": ">=8.1", + "phpunit/php-file-iterator": "^4.0", + "phpunit/php-text-template": "^3.0", + "sebastian/code-unit-reverse-lookup": "^3.0", + "sebastian/complexity": "^3.0", + "sebastian/environment": "^6.0", + "sebastian/lines-of-code": "^2.0", + "sebastian/version": "^4.0", + "theseer/tokenizer": "^1.2.0" }, "require-dev": { "phpunit/phpunit": "^10.0" }, + "suggest": { + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, "type": "library", "extra": { "branch-alias": { - "dev-main": "3.0-dev" + "dev-main": "10.0-dev" } }, "autoload": { @@ -805,14 +894,16 @@ "role": "lead" } ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", "keywords": [ - "template" + "coverage", + "testing", + "xunit" ], "support": { - "issues": "https://github.com/sebastianbergmann/php-text-template/issues", - "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.0" + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.0.2" }, "funding": [ { @@ -820,20 +911,20 @@ "type": "github" } ], - "time": "2023-02-03T06:56:46+00:00" + "time": "2023-03-06T13:00:19+00:00" }, { - "name": "phpunit/php-timer", - "version": "6.0.0", + "name": "phpunit/php-file-iterator", + "version": "4.0.1", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d" + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "fd9329ab3368f59fe1fe808a189c51086bd4b6bd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d", - "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/fd9329ab3368f59fe1fe808a189c51086bd4b6bd", + "reference": "fd9329ab3368f59fe1fe808a189c51086bd4b6bd", "shasum": "" }, "require": { @@ -845,7 +936,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "6.0-dev" + "dev-main": "4.0-dev" } }, "autoload": { @@ -864,14 +955,15 @@ "role": "lead" } ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", "keywords": [ - "timer" + "filesystem", + "iterator" ], "support": { - "issues": "https://github.com/sebastianbergmann/php-timer/issues", - "source": "https://github.com/sebastianbergmann/php-timer/tree/6.0.0" + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.0.1" }, "funding": [ { @@ -879,66 +971,39 @@ "type": "github" } ], - "time": "2023-02-03T06:57:52+00:00" + "time": "2023-02-10T16:53:14+00:00" }, { - "name": "phpunit/phpunit", - "version": "10.0.16", + "name": "phpunit/php-invoker", + "version": "4.0.0", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "07d386a11ac7094032900f07cada1c8975d16607" + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/07d386a11ac7094032900f07cada1c8975d16607", - "reference": "07d386a11ac7094032900f07cada1c8975d16607", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", "shasum": "" }, "require": { - "ext-dom": "*", - "ext-json": "*", - "ext-libxml": "*", - "ext-mbstring": "*", - "ext-xml": "*", - "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.3", - "phar-io/version": "^3.0.2", - "php": ">=8.1", - "phpunit/php-code-coverage": "^10.0", - "phpunit/php-file-iterator": "^4.0", - "phpunit/php-invoker": "^4.0", - "phpunit/php-text-template": "^3.0", - "phpunit/php-timer": "^6.0", - "sebastian/cli-parser": "^2.0", - "sebastian/code-unit": "^2.0", - "sebastian/comparator": "^5.0", - "sebastian/diff": "^5.0", - "sebastian/environment": "^6.0", - "sebastian/exporter": "^5.0", - "sebastian/global-state": "^6.0", - "sebastian/object-enumerator": "^5.0", - "sebastian/recursion-context": "^5.0", - "sebastian/type": "^4.0", - "sebastian/version": "^4.0" + "php": ">=8.1" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^10.0" }, "suggest": { - "ext-soap": "To be able to generate mocks based on WSDL files" + "ext-pcntl": "*" }, - "bin": [ - "phpunit" - ], "type": "library", "extra": { "branch-alias": { - "dev-main": "10.0-dev" + "dev-main": "4.0-dev" } }, "autoload": { - "files": [ - "src/Framework/Assert/Functions.php" - ], "classmap": [ "src/" ] @@ -954,236 +1019,240 @@ "role": "lead" } ], - "description": "The PHP Unit Testing framework.", - "homepage": "https://phpunit.de/", + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", "keywords": [ - "phpunit", - "testing", - "xunit" + "process" ], "support": { - "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.0.16" + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/4.0.0" }, "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-03-13T09:02:40+00:00" + "time": "2023-02-03T06:56:09+00:00" }, { - "name": "psr/http-client", - "version": "1.0.1", + "name": "phpunit/php-text-template", + "version": "3.0.0", "source": { "type": "git", - "url": "https://github.com/php-fig/http-client.git", - "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", - "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/9f3d3709577a527025f55bcf0f7ab8052c8bb37d", + "reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d", "shasum": "" }, "require": { - "php": "^7.0 || ^8.0", - "psr/http-message": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Client\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP clients", - "homepage": "https://github.com/php-fig/http-client", - "keywords": [ - "http", - "http-client", - "psr", - "psr-18" - ], - "support": { - "source": "https://github.com/php-fig/http-client/tree/master" - }, - "time": "2020-06-29T06:28:15+00:00" - }, - { - "name": "psr/http-factory", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-factory.git", - "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", - "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", - "shasum": "" + "php": ">=8.1" }, - "require": { - "php": ">=7.0.0", - "psr/http-message": "^1.0" + "require-dev": { + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-main": "3.0-dev" } }, "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } + "classmap": [ + "src/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" } ], - "description": "Common interfaces for PSR-7 HTTP message factories", + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", "keywords": [ - "factory", - "http", - "message", - "psr", - "psr-17", - "psr-7", - "request", - "response" + "template" ], "support": { - "source": "https://github.com/php-fig/http-factory/tree/master" + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.0" }, - "time": "2019-04-30T12:38:16+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:56:46+00:00" }, { - "name": "psr/http-message", - "version": "1.0.1", + "name": "phpunit/php-timer", + "version": "6.0.0", "source": { "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d", + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-main": "6.0-dev" } }, "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } + "classmap": [ + "src/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" } ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" + "timer" ], "support": { - "source": "https://github.com/php-fig/http-message/tree/master" + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/6.0.0" }, - "time": "2016-08-06T14:39:51+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:57:52+00:00" }, { - "name": "ralouphie/getallheaders", - "version": "3.0.3", + "name": "phpunit/phpunit", + "version": "10.0.16", "source": { "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "07d386a11ac7094032900f07cada1c8975d16607" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/07d386a11ac7094032900f07cada1c8975d16607", + "reference": "07d386a11ac7094032900f07cada1c8975d16607", "shasum": "" }, "require": { - "php": ">=5.6" + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.10.1", + "phar-io/manifest": "^2.0.3", + "phar-io/version": "^3.0.2", + "php": ">=8.1", + "phpunit/php-code-coverage": "^10.0", + "phpunit/php-file-iterator": "^4.0", + "phpunit/php-invoker": "^4.0", + "phpunit/php-text-template": "^3.0", + "phpunit/php-timer": "^6.0", + "sebastian/cli-parser": "^2.0", + "sebastian/code-unit": "^2.0", + "sebastian/comparator": "^5.0", + "sebastian/diff": "^5.0", + "sebastian/environment": "^6.0", + "sebastian/exporter": "^5.0", + "sebastian/global-state": "^6.0", + "sebastian/object-enumerator": "^5.0", + "sebastian/recursion-context": "^5.0", + "sebastian/type": "^4.0", + "sebastian/version": "^4.0" }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files" }, + "bin": [ + "phpunit" + ], "type": "library", + "extra": { + "branch-alias": { + "dev-main": "10.0-dev" + } + }, "autoload": { "files": [ - "src/getallheaders.php" + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" } ], - "description": "A polyfill for getallheaders.", + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], "support": { - "issues": "https://github.com/ralouphie/getallheaders/issues", - "source": "https://github.com/ralouphie/getallheaders/tree/develop" + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.0.16" }, - "time": "2019-03-08T08:55:37+00:00" + "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-03-13T09:02:40+00:00" }, { "name": "sebastian/cli-parser", @@ -2093,73 +2162,6 @@ ], "time": "2023-02-07T11:34:05+00:00" }, - { - "name": "symfony/deprecation-contracts", - "version": "v3.2.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e", - "reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.3-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "files": [ - "function.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "A generic function and convention to trigger deprecation notices", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.2.1" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2023-03-01T10:25:55+00:00" - }, { "name": "theseer/tokenizer", "version": "1.2.1", @@ -2211,7 +2213,6 @@ "time": "2021-07-28T10:34:58+00:00" } ], - "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/Source/Config/config.php b/Source/Config/config.php index 2995d00..25eebd7 100644 --- a/Source/Config/config.php +++ b/Source/Config/config.php @@ -1,8 +1,5 @@ - addQuestion(); if (strcmp($type, "BusinessClass\TextQuestion") == 0) { $this->goToQuestions(); @@ -33,13 +39,17 @@ class ControllerAdmin /** - * Ajoute une possibilité de réponse à une question, on assige également cette réponse - * à des catégories. On propose ensuite à l'utilisateur de continuer l'ajout d'autre réponses. + * Ajoute une possibilité de réponse à une question, on assigne également cette réponse + * à des catégories. On propose ensuite à l'utilisateur de continuer l'ajout d'autres réponses. * * @return void + * @throws Exception */ public function addResponse(): void { + if (empty($_POST['idQuestion'] || empty($_POST['question']) || empty($_POST['type']))) { + throw new InvalidArgumentException('$_POST parameters is missing'); + } (new ModelAdmin())->addResponse(); $categories = (new ModelAdmin())->getCategories(); $idQuestion = $_POST['idQuestion']; @@ -52,12 +62,16 @@ class ControllerAdmin /** * Permet de proposer à l'utiliser de continuer ou non à ajouter des possibilités de réponses à l'aide - * de la fonction addResponse(). Si non, il retourne à la page d'admnistration. + * de la fonction addResponse(). Sinon, il retourne à la page administration. * * @return void + * @throws Exception */ public function continueResponse(): void { + if (empty($_POST['choose'] || empty($_POST['idQuestion']) || empty($_POST['type']) || empty($_POST['question']))) { + throw new InvalidArgumentException('$_POST parameters is missing'); + } $choose = $_POST['choose']; if ($choose == "Oui") { $idQuestion = $_POST['idQuestion']; @@ -76,6 +90,7 @@ class ControllerAdmin * Permet de créer un nouveau formulaire avec un titre et une description. * * @return void + * @throws Exception */ public function createForm(): void { @@ -84,9 +99,10 @@ class ControllerAdmin /** - * Permet d'ajouter une catégories (mot-clef) à notre application + * Permet d'ajouter une catégorie (mot-clef) à notre application * * @return void + * @throws Exception */ public function addKeyword(): void { @@ -99,6 +115,7 @@ class ControllerAdmin * Permet de naviguer jusqu'à la page de gestion des catégories * * @return void + * @throws Exception */ public function goToCategories(): void { @@ -112,6 +129,7 @@ class ControllerAdmin * Permet de naviguer jusqu'à la page de gestion des questions * * @return void + * @throws Exception */ public function goToQuestions(): void { @@ -125,6 +143,7 @@ class ControllerAdmin * Permet de naviguer jusqu'à la page de gestion des réponses * * @return void + * @throws Exception */ public function goToResponses(): void { diff --git a/Source/Controller/ControllerCandidate.php b/Source/Controller/ControllerCandidate.php index 7c0a52e..99c5f5d 100644 --- a/Source/Controller/ControllerCandidate.php +++ b/Source/Controller/ControllerCandidate.php @@ -15,6 +15,7 @@ class ControllerCandidate * Permet de naviguer jusqu'au formulaire. * * @return void + * @throws Exception */ public function goToForm(): void { @@ -34,6 +35,7 @@ class ControllerCandidate * Permet de finaliser la saisie du formulaire et de le soumettre. * * @return void + * @throws Exception */ public function submitForm(): void { diff --git a/Source/Model/Factory.php b/Source/Model/Factory.php index 60093bf..685fad3 100644 --- a/Source/Model/Factory.php +++ b/Source/Model/Factory.php @@ -5,7 +5,7 @@ namespace Model; use BusinessClass\Question; /** - * Décrit les fonctionnalités principale d'une frabique + * Décrit les fonctionnalités principales d'une fabrique */ abstract class Factory { @@ -20,7 +20,7 @@ abstract class Factory /** - * Permet de récupérer les objets créer par la fonction create(). + * Permet de récupérer les objets créés par la fonction create(). * * @param array $results * @param string $type diff --git a/Source/Model/FactoryQuestion.php b/Source/Model/FactoryQuestion.php index cc82f63..64129e2 100644 --- a/Source/Model/FactoryQuestion.php +++ b/Source/Model/FactoryQuestion.php @@ -12,7 +12,7 @@ class FactoryQuestion extends Factory { /** * Permet de créer une liste de question en fonction du retour d'une gateway - * passer en paramètre. On prend en compte les différents type de question. + * passer en paramètre. On prend en compte les différents types de question. * * @param array $results * diff --git a/Source/Tests/TestBusinessClass/BoxQuestionTest.php b/Source/Tests/TestBusinessClass/BoxQuestionTest.php new file mode 100644 index 0000000..cae1a4f --- /dev/null +++ b/Source/Tests/TestBusinessClass/BoxQuestionTest.php @@ -0,0 +1,55 @@ +assertEquals($args[0], $boxQuestion->getPossibleResponses()); + $this->assertEquals($args[2], $boxQuestion->getCategories()); + } + + public function testSetPossibleResponses() + { + $args = [1, 'question']; + + $possibleResponses = ['response1', 'response2']; + $boxQuestion = new class(2, $args) extends BoxQuestion { + public function printStrategy(): string + { + return ''; + } + }; + $boxQuestion->setPossibleResponses($possibleResponses); + + $this->assertEquals($possibleResponses, $boxQuestion->getPossibleResponses()); + } + + public function testSetCategories() + { + $args = [1, 'question']; + + $categories = ['category1', 'category2']; + $boxQuestion = new class(2, $args) extends BoxQuestion { + public function printStrategy(): string + { + return ''; + } + }; + $boxQuestion->setCategories($categories); + + $this->assertEquals($categories, $boxQuestion->getCategories()); + } +} diff --git a/Source/Tests/FormTest.php b/Source/Tests/TestBusinessClass/FormTest.php similarity index 90% rename from Source/Tests/FormTest.php rename to Source/Tests/TestBusinessClass/FormTest.php index 1a7e704..e8cd11d 100644 --- a/Source/Tests/FormTest.php +++ b/Source/Tests/TestBusinessClass/FormTest.php @@ -1,7 +1,9 @@ Question'; + } + }; + + $this->assertEquals('
Question
', $strategy->printStrategy()); + } +} diff --git a/Source/Tests/TestBusinessClass/KeywordTest.php b/Source/Tests/TestBusinessClass/KeywordTest.php new file mode 100644 index 0000000..b042daa --- /dev/null +++ b/Source/Tests/TestBusinessClass/KeywordTest.php @@ -0,0 +1,31 @@ +assertEquals($id, $keyword->getId()); + $this->assertEquals($word, $keyword->getWord()); + } + + public function testSetWord() + { + $id = 1; + $word = 'example'; + $newWord = 'new example'; + $keyword = new Keyword($id, $word); + $keyword->setWord($newWord); + + $this->assertEquals($newWord, $keyword->getWord()); + } +} + diff --git a/Source/Tests/TestBusinessClass/QuestionTest.php b/Source/Tests/TestBusinessClass/QuestionTest.php new file mode 100644 index 0000000..687d0f8 --- /dev/null +++ b/Source/Tests/TestBusinessClass/QuestionTest.php @@ -0,0 +1,39 @@ +assertEquals($id, $question->getId()); + $this->assertEquals($content, $question->getContent()); + } + + public function testSetContent() + { + $content = 'What is your age?'; + $question = new class(1, 'question') extends Question { + public function printStrategy(): string + { + return ''; + } + }; + $question->setContent($content); + + $this->assertEquals($content, $question->getContent()); + } +} + diff --git a/Source/Tests/TestBusinessClass/ResponseTest.php b/Source/Tests/TestBusinessClass/ResponseTest.php new file mode 100644 index 0000000..238e9b8 --- /dev/null +++ b/Source/Tests/TestBusinessClass/ResponseTest.php @@ -0,0 +1,49 @@ + "Response 1", + "Question 2" => "Response 2" + ]; + + public function testGetters() + { + $response = new Response($this->id, $this->date, $this->titleForm, $this->questionsResponses); + + $this->assertEquals($this->id, $response->getId()); + $this->assertEquals($this->date, $response->getDate()); + $this->assertEquals($this->titleForm, $response->getTitleForm()); + $this->assertEquals($this->questionsResponses, $response->getQuestionsResponses()); + } + + public function testSetters() + { + $response = new Response($this->id, $this->date, $this->titleForm, $this->questionsResponses); + + $newDate = "2023-03-18"; + $response->setDate($newDate); + $this->assertEquals($newDate, $response->getDate()); + + $newTitleForm = "New Form"; + $response->setTitleForm($newTitleForm); + $this->assertEquals($newTitleForm, $response->getTitleForm()); + + $newQuestionsResponses = [ + "Question 1" => "New Response 1", + "Question 2" => "New Response 2" + ]; + $response->setQuestionsResponses($newQuestionsResponses); + $this->assertEquals($newQuestionsResponses, $response->getQuestionsResponses()); + } +} + + diff --git a/Source/Tests/TestBusinessClass/TextQuestionTest.php b/Source/Tests/TestBusinessClass/TextQuestionTest.php new file mode 100644 index 0000000..58c8326 --- /dev/null +++ b/Source/Tests/TestBusinessClass/TextQuestionTest.php @@ -0,0 +1,25 @@ + +
$content
+

+ +

+ \n"; + $this->assertEquals($expectedOutput, $textQuestion->printStrategy()); + } +} + + diff --git a/Source/Tests/TestConfig/AltoRouterTest.php b/Source/Tests/TestConfig/AltoRouterTest.php new file mode 100644 index 0000000..c71dcbd --- /dev/null +++ b/Source/Tests/TestConfig/AltoRouterTest.php @@ -0,0 +1,73 @@ +router = new AltoRouter(); + } + + /** + * @throws Exception + */ + public function testAddRoutesThrowsExceptionForInvalidInput() + { + $this->expectException(RuntimeException::class); + $this->router->addRoutes('invalid input'); + } + + public function testGetRoutesReturnsArrayOfRoutes() + { + $this->assertIsArray($this->router->getRoutes()); + } + + public function testSetBasePathSetsBasePath() + { + $this->router->setBasePath('/test'); + $this->assertEquals('/test', $this->router->getBasePath()); + } + + public function testAddMatchTypesAddsMatchTypes() + { + $this->router->addMatchTypes(['test' => 'regex']); + $this->assertArrayHasKey('test', $this->router->getMatchTypes()); + } + + /** + * @throws Exception + */ + public function testMapAddsRouteToRoutesArray() + { + $this->router->map('GET', '/test', 'handler'); + $this->assertEquals([['GET', '/test', 'handler', null]], $this->router->getRoutes()); + } + + /** + * @throws Exception + */ + public function testMapAddsNamedRouteToNamedRoutesArray() + { + $this->router->map('GET', '/test', 'handler', 'test'); + $this->assertEquals('/test', $this->router->getNamedRoutes()['test']); + } + + /** + * @throws Exception + */ + public function testMapThrowsExceptionForDuplicateNamedRoutes() + { + $this->expectException(RuntimeException::class); + $this->router->map('GET', '/test', 'handler', 'test'); + $this->router->map('GET', '/test2', 'handler', 'test'); + } +} diff --git a/Source/Tests/TestConfig/AutoloadTest.php b/Source/Tests/TestConfig/AutoloadTest.php new file mode 100644 index 0000000..5e9a873 --- /dev/null +++ b/Source/Tests/TestConfig/AutoloadTest.php @@ -0,0 +1,29 @@ +expectException(RuntimeException::class); + $this->expectExceptionMessage('Config\Autoload is already started'); + + Autoload::charger(); + Autoload::charger(); + } + + public function testShutDown() + { + Autoload::shutDown(); + Autoload::charger(); + Autoload::shutDown(); + + $this->assertNull(Autoload::getInstance()); + } +} + diff --git a/Source/Tests/TestConfig/CleanTest.php b/Source/Tests/TestConfig/CleanTest.php new file mode 100644 index 0000000..5b7294a --- /dev/null +++ b/Source/Tests/TestConfig/CleanTest.php @@ -0,0 +1,47 @@ + Test avec des espaces !

'; + $expected = 'Test avec des espaces !'; + $this->assertEquals($expected, Clean::simpleString($string)); + + // Test avec une chaîne de caractères qui contient des caractères spéciaux + $string = 'Ceci est une chaîne & avec des "caractères" spéciaux !'; + $expected = 'Ceci est une chaîne & avec des "caractères" spéciaux !'; + $this->assertEquals($expected, Clean::simpleString($string)); + } + + public function testEmail() + { + // Test avec une adresse email valide + $email = 'john.doe@example.com'; + $expected = 'john.doe@example.com'; + $this->assertEquals($expected, Clean::email($email)); + + // Test avec une adresse email invalide + $email = 'john.doe@example.com'; + $this->assertEquals($expected, Clean::email($email)); + } + + public function testInt() + { + // Test avec un entier valide + $int = '1234'; + $expected = 1234; + $this->assertEquals($expected, Clean::int($int)); + + // Test avec un entier invalide + $int = '1234abc'; + $this->assertEquals($expected, Clean::int($int)); + } +} + diff --git a/Source/Tests/TestConfig/ValidateTest.php b/Source/Tests/TestConfig/ValidateTest.php new file mode 100644 index 0000000..c6d9848 --- /dev/null +++ b/Source/Tests/TestConfig/ValidateTest.php @@ -0,0 +1,70 @@ +assertTrue(Validate::email('john.doe@example.com')); + $this->assertFalse(Validate::email('john.doe@')); + $this->assertFalse(Validate::email('john.doe@example.commmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm')); + } + + public function testLogin() + { + $this->assertTrue(Validate::login('john123')); + $this->assertFalse(Validate::login('joh')); + $this->assertFalse(Validate::login('joh!')); + $this->assertFalse(Validate::login('john123456789012345555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555')); + } + + public function testPassword() + { + $this->assertTrue(Validate::password('Pa$$w0rd')); + $this->assertFalse(Validate::password('password')); + $this->assertFalse(Validate::password('12345678')); + $this->assertFalse(Validate::password('pa$$word')); + $this->assertFalse(Validate::password('P@$$worddddddddddddddddddddddddddddddddddddddddddd')); + } + + public function testKeyWord() + { + $this->assertTrue(Validate::keyWord('keyword')); + $this->assertFalse(Validate::keyWord('ke')); + $this->assertFalse(Validate::keyWord('keyworddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd')); + } + + public function testTitle() + { + $this->assertTrue(Validate::title('Title')); + $this->assertFalse(Validate::title('Ti')); + $this->assertFalse(Validate::title('titleddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd')); + } + + public function testType() + { + $this->assertTrue(Validate::type('Type')); + $this->assertFalse(Validate::type('Ty')); + $this->assertFalse(Validate::type('typeddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd')); + } + + public function testResponse() + { + $this->assertTrue(Validate::response('Response')); + $this->assertFalse(Validate::response('')); + $this->assertFalse(Validate::response('responseddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd')); + } + + public function testUsername() + { + $this->assertTrue(Validate::username('john123')); + $this->assertFalse(Validate::username('jo')); + $this->assertFalse(Validate::username('joh!')); + $this->assertFalse(Validate::username('john1234567890123455555555555555555555555555555555555555555555555555555555555555555555555555555555555555555')); + } +} diff --git a/Source/Tests/TestController/.gitkeep b/Source/Tests/TestController/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Source/Tests/TestModel/.gitkeep b/Source/Tests/TestModel/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Source/Tests/coverage.xml b/Source/Tests/coverage.xml new file mode 100644 index 0000000..8dde3d9 --- /dev/null +++ b/Source/Tests/coverage.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source/coverage.xml b/Source/coverage.xml deleted file mode 100644 index 0c71dc8..0000000 --- a/Source/coverage.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - -