From fc9c088dc5a654fa6254c45dfd57976c668fc62d Mon Sep 17 00:00:00 2001 From: webeweb Date: Tue, 7 May 2024 10:05:59 +0200 Subject: [PATCH] Improve Host controller tests --- .../Tests/Controller/HostControllerTest.php | 86 ++++++++----------- 1 file changed, 36 insertions(+), 50 deletions(-) diff --git a/lib/common/Tests/Controller/HostControllerTest.php b/lib/common/Tests/Controller/HostControllerTest.php index 74a4b42b..6c083d86 100644 --- a/lib/common/Tests/Controller/HostControllerTest.php +++ b/lib/common/Tests/Controller/HostControllerTest.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\ServerBag; use WBW\Bundle\CommonBundle\Controller\HostController; use WBW\Bundle\CommonBundle\Tests\DefaultWebTestCase as AbstractWebTestCase; +use WBW\Library\Common\Serializer\SerializerKeys as BaseSerializerKeys; /** * Host controller test. @@ -43,24 +44,19 @@ public function testCpuAction(): void { $res = json_decode($client->getResponse()->getContent(), true); $this->assertCount(4, $res); - $this->assertArrayHasKey("success", $res); - $this->assertArrayHasKey("message", $res); - $this->assertArrayHasKey("errors", $res); - $this->assertArrayHasKey("data", $res); - - $this->assertTrue($res["success"]); - $this->assertNull($res["message"]); - $this->assertNull($res["errors"]); - $this->assertCount(8, $res["data"]); - - $this->assertArrayHasKey("us", $res["data"]); - $this->assertArrayHasKey("sy", $res["data"]); - $this->assertArrayHasKey("ni", $res["data"]); - $this->assertArrayHasKey("id", $res["data"]); - $this->assertArrayHasKey("wa", $res["data"]); - $this->assertArrayHasKey("hi", $res["data"]); - $this->assertArrayHasKey("si", $res["data"]); - $this->assertArrayHasKey("st", $res["data"]); + $this->assertTrue($res[BaseSerializerKeys::SUCCESS]); + $this->assertNull($res[BaseSerializerKeys::MESSAGE]); + $this->assertNull($res[BaseSerializerKeys::ERRORS]); + $this->assertCount(8, $res[BaseSerializerKeys::DATA]); + + $this->assertArrayHasKey(BaseSerializerKeys::US, $res[BaseSerializerKeys::DATA]); + $this->assertArrayHasKey(BaseSerializerKeys::SY, $res[BaseSerializerKeys::DATA]); + $this->assertArrayHasKey(BaseSerializerKeys::NI, $res[BaseSerializerKeys::DATA]); + $this->assertArrayHasKey(BaseSerializerKeys::ID, $res[BaseSerializerKeys::DATA]); + $this->assertArrayHasKey(BaseSerializerKeys::WA, $res[BaseSerializerKeys::DATA]); + $this->assertArrayHasKey(BaseSerializerKeys::HI, $res[BaseSerializerKeys::DATA]); + $this->assertArrayHasKey(BaseSerializerKeys::SI, $res[BaseSerializerKeys::DATA]); + $this->assertArrayHasKey(BaseSerializerKeys::ST, $res[BaseSerializerKeys::DATA]); } /** @@ -80,23 +76,18 @@ public function testHardDisksAction(): void { $res = json_decode($client->getResponse()->getContent(), true); $this->assertCount(4, $res); - $this->assertArrayHasKey("success", $res); - $this->assertArrayHasKey("message", $res); - $this->assertArrayHasKey("errors", $res); - $this->assertArrayHasKey("data", $res); - - $this->assertTrue($res["success"]); - $this->assertNull($res["message"]); - $this->assertNull($res["errors"]); - $this->assertNotCount(0, $res["data"]); - - $this->assertArrayHasKey("available", $res["data"][0]); - $this->assertArrayHasKey("fileSystem", $res["data"][0]); - $this->assertArrayHasKey("mountedOn", $res["data"][0]); - $this->assertArrayHasKey("name", $res["data"][0]); - $this->assertArrayHasKey("type", $res["data"][0]); - $this->assertArrayHasKey("used", $res["data"][0]); - $this->assertArrayHasKey("usePercent", $res["data"][0]); + $this->assertTrue($res[BaseSerializerKeys::SUCCESS]); + $this->assertNull($res[BaseSerializerKeys::MESSAGE]); + $this->assertNull($res[BaseSerializerKeys::ERRORS]); + $this->assertNotCount(0, $res[BaseSerializerKeys::DATA]); + + $this->assertArrayHasKey(BaseSerializerKeys::AVAILABLE, $res[BaseSerializerKeys::DATA][0]); + $this->assertArrayHasKey(BaseSerializerKeys::FILE_SYSTEM, $res[BaseSerializerKeys::DATA][0]); + $this->assertArrayHasKey(BaseSerializerKeys::MOUNTED_ON, $res[BaseSerializerKeys::DATA][0]); + $this->assertArrayHasKey(BaseSerializerKeys::NAME, $res[BaseSerializerKeys::DATA][0]); + $this->assertArrayHasKey(BaseSerializerKeys::TYPE, $res[BaseSerializerKeys::DATA][0]); + $this->assertArrayHasKey(BaseSerializerKeys::USED, $res[BaseSerializerKeys::DATA][0]); + $this->assertArrayHasKey(BaseSerializerKeys::USE_PERCENT, $res[BaseSerializerKeys::DATA][0]); } /** @@ -116,21 +107,16 @@ public function testMemoryAction(): void { $res = json_decode($client->getResponse()->getContent(), true); $this->assertCount(4, $res); - $this->assertArrayHasKey("success", $res); - $this->assertArrayHasKey("message", $res); - $this->assertArrayHasKey("errors", $res); - $this->assertArrayHasKey("data", $res); - - $this->assertTrue($res["success"]); - $this->assertNull($res["message"]); - $this->assertNull($res["errors"]); - $this->assertNotCount(0, $res["data"]); - - $this->assertArrayHasKey("MemAvailable", $res["data"]); - $this->assertArrayHasKey("MemFree", $res["data"]); - $this->assertArrayHasKey("MemTotal", $res["data"]); - $this->assertArrayHasKey("SwapFree", $res["data"]); - $this->assertArrayHasKey("SwapTotal", $res["data"]); + $this->assertTrue($res[BaseSerializerKeys::SUCCESS]); + $this->assertNull($res[BaseSerializerKeys::MESSAGE]); + $this->assertNull($res[BaseSerializerKeys::ERRORS]); + $this->assertNotCount(0, $res[BaseSerializerKeys::DATA]); + + $this->assertArrayHasKey("MemAvailable", $res[BaseSerializerKeys::DATA]); + $this->assertArrayHasKey("MemFree", $res[BaseSerializerKeys::DATA]); + $this->assertArrayHasKey("MemTotal", $res[BaseSerializerKeys::DATA]); + $this->assertArrayHasKey("SwapFree", $res[BaseSerializerKeys::DATA]); + $this->assertArrayHasKey("SwapTotal", $res[BaseSerializerKeys::DATA]); } /**