From 6b1460fb6470a6123c25d7ae552869c4c9af69f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20BOUHOURS?= Date: Wed, 6 Sep 2023 00:15:23 +0200 Subject: [PATCH] [DEV] Ajout des tests --- README.md | 25 +++++++++++++++++++- common/Tests/WS_UtilTest.php | 44 ++++++++++++++++++++++++++++++++++++ composer.json | 5 ++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 common/Tests/WS_UtilTest.php create mode 100644 composer.json diff --git a/README.md b/README.md index f80981d..8d2aa94 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,25 @@ -# CICD_WebPage +# WebPage +This project proposes a website allowing you to manage your library. It allows you to search for books in [OpenLibrary](https://openlibrary.org/), add them to your own library and manage loans. + +## Getting Started + +If you want to test this project locally, simply ```git clone``` this project on a apache/php8 system + +## Running the tests + +You can run some unit tests but there are few. So, you must use [phpUnit](https://phpunit.de/). + +Tests are in common/Tests + +In the context of continous integration, you have to deploy phpUnit. Next, simply execute tests on a php8 image with commands like : + +_vendor/bin/phpunit --filter "/([METHOD_TO_TEST])( .*)?$/" [path to the test classes]_ + +You can find more details in the [Drone documentation](https://docs.drone.io/) + +## Authors +Cédric Bouhours + +## Acknowledgements +Marc Chevaldonné and Camille Petitalot \ No newline at end of file diff --git a/common/Tests/WS_UtilTest.php b/common/Tests/WS_UtilTest.php new file mode 100644 index 0000000..33d28b5 --- /dev/null +++ b/common/Tests/WS_UtilTest.php @@ -0,0 +1,44 @@ + 'a', 'index' => '0', 'count' => 5]; + $requestBody = []; + $login = ""; + $pwd = ""; + + $response = WS_Util::CallWebService($base_url, $endpoint, $method, $queryParams, $requestBody, $login, $pwd); + $this->assertIsArray($response); + } + + public function testAllKeysToUppercase() + { + $data = [ + 'name' => 'John', + 'age' => 30, + 'address' => [ + 'city' => 'Paris', + 'country' => 'France' + ] + ]; + + $result = WS_Util::AllKeysToUppercase($data); + + $this->assertIsArray($result); + $this->assertArrayHasKey('NAME', $result); + $this->assertArrayHasKey('AGE', $result); + $this->assertArrayHasKey('ADDRESS', $result); + $this->assertArrayHasKey('CITY', $result['ADDRESS']); + $this->assertArrayHasKey('COUNTRY', $result['ADDRESS']); + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..821753e --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require-dev": { + "phpunit/phpunit": "^10" + } +}