From 466091efe64d9b3acdaa4a62af066121a8991fba Mon Sep 17 00:00:00 2001 From: Radia Fali Date: Mon, 6 Jan 2025 00:48:05 +0100 Subject: [PATCH] tests unitaires --- api/.env.test | 2 + api/tests/ImpotTest.php | 145 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) mode change 100755 => 100644 api/.env.test create mode 100644 api/tests/ImpotTest.php diff --git a/api/.env.test b/api/.env.test old mode 100755 new mode 100644 index e3d5d8b..3db756c --- a/api/.env.test +++ b/api/.env.test @@ -7,3 +7,5 @@ PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots # API Platform distribution TRUSTED_HOSTS=^example\.com|localhost$ +DATABASE_URL="postgresql://app:!ChangeMe!@localhost:5432/app_test?serverVersion=16&charset=utf8" +TEST_TOKEN=test \ No newline at end of file diff --git a/api/tests/ImpotTest.php b/api/tests/ImpotTest.php new file mode 100644 index 0000000..5acb780 --- /dev/null +++ b/api/tests/ImpotTest.php @@ -0,0 +1,145 @@ +request('GET', '/impots/AllYears'); + + $this->assertResponseStatusCodeSame(200); + + $this->assertJsonContains([ + ['year' => 2012], + ['year' => 2013], + ['year' => 2014], + ['year' => 2015], + ['year' => 2016], + ['year' => 2017], + ['year' => 2018], + ['year' => 2019], + ['year' => 2020], + ['year' => 2021], + ['year' => 2022], + ]); + } + + public function testAllTypes(): void + { + $client = static::createClient(); + + $response = $client->request('GET', '/impots/AllTypes'); + + $this->assertResponseStatusCodeSame(200); + + $this->assertJsonContains([ + ['type' => 'CFE'], + ['type' => 'TFB'], + ['type' => 'TFNB'], + ['type' => "Taxe d'habitation"], + ]); + } + + public function testAllDepartement(): void + { + $client = static::createClient(); + + $response = $client->request('GET', '/impots/AllDepartements'); + + $this->assertResponseStatusCodeSame(200); + $departements = json_decode($response->getContent(), true); + $found = false; + foreach ($departements as $departement) { + if ($departement["department"] === "SEINE-MARITIME") { + $found = true; + break; + } + } + $this->assertTrue($found, "Le département 'SEINE-MARITIME' est présent."); + } + + public function testRelationTauxEtVolume(): void + { + $client = static::createClient(); // Assurez-vous que $client est initialisé + $type = 'CFE'; + $year = '2022'; + $departement = 'SEINE-MARITIME'; + + $response = $client->request('GET', '/impots/taux-volume/'.$type.'/'.$year.'/'.$departement); + + $datas = json_decode($response->getContent(), true); + + $found = false; + + foreach ($datas as $data) { + if ($data["department"] === "SEINE-MARITIME" && $data["taxRate"] === 42.769999980927 && $data["volumeCollected"] === 432823 && $data["commune"] === "GONNEVILLE LA MALLET") { + $found = true; + break; + } + } + + $this->assertResponseStatusCodeSame(200); + + $this->assertTrue($found, "La ligne de test est bien présente dans le retour de la requête."); + } + + public function testVolumeParRegion(): void + { + $client = static::createClient(); // Assurez-vous que $client est initialisé + $type = 'CFE'; + $year = '2022'; + + $response = $client->request('GET', '/impots/volume-par-region/'.$type.'/'.$year); + + $datas = json_decode($response->getContent(), true); + + $found = false; + + foreach ($datas as $data) { + if ($data["region"] === "AUVERGNE-RHONE-ALPES" && $data["percentage"] === 11.635363362116781) { + $found = true; + break; + } + } + + $this->assertResponseStatusCodeSame(200); + + $this->assertTrue($found, "La ligne de test est bien présente dans le retour de la requête."); + } + + public function testTaxeMoyenneParRegion(): void + { + $client = static::createClient(); + $type = 'CFE'; + $year1 = '2021'; + $year2 = '2022'; + + $response = $client->request('GET', 'impots/taxe-moyenne-par-region/'.$type.'/'.$year1.'/'.$year2); + + $datas = json_decode($response->getContent(), true); + + $found2021 = false; + $found2022 = false; + + foreach ($datas as $data) { + if ($data["region"] === "AUVERGNE-RHONE-ALPES" && $data["year"] == 2021) { + $found2021 = true; + } + if ($data["region"] === "AUVERGNE-RHONE-ALPES" && $data["year"] == 2022) { + $found2022 = true; + } + } + + $this->assertResponseStatusCodeSame(200); + + $this->assertTrue($found2021, "La ligne pour 2021 est bien présente dans le retour de la requête."); + $this->assertTrue($found2022, "La ligne pour 2022 est bien présente dans le retour de la requête."); + } + + +} \ No newline at end of file -- GitLab