[DEV] Ajout des tests

master
Cédric BOUHOURS 1 year ago
parent 31c06ea9b7
commit 6b1460fb64

@ -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

@ -0,0 +1,44 @@
<?php
use PHPUnit\Framework\TestCase;
include_once __DIR__."/../Model/WS_Util.php";
include_once __DIR__."/../../common.php";
class WS_UtilTest extends TestCase
{
public function testCallWebService()
{
$base_url = BASE_URL_LIBRARY;
$endpoint = GET_BOOKS_BY_TITLE;
$method = 'GET';
$queryParams = ['title' => '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']);
}
}

@ -0,0 +1,5 @@
{
"require-dev": {
"phpunit/phpunit": "^10"
}
}
Loading…
Cancel
Save