From 5d6f293956071dd2801a1844d1638ef62d2edeec Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Wed, 13 Mar 2024 09:48:46 +0100 Subject: [PATCH 1/2] =?UTF-8?q?N=C2=B07302=20Report=20SetupUtilsTest::test?= =?UTF-8?q?HumanReadableSize=20in=20the=202.7=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unitary-tests/setup/SetupUtilsTest.php | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/tests/php-unit-tests/unitary-tests/setup/SetupUtilsTest.php b/tests/php-unit-tests/unitary-tests/setup/SetupUtilsTest.php index d38488bf6..392f7da7f 100644 --- a/tests/php-unit-tests/unitary-tests/setup/SetupUtilsTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/SetupUtilsTest.php @@ -35,8 +35,8 @@ class SetupUtilsTest extends ItopTestCase $this->assertContains($sLabel, $oCheck->sLabel); } - public function CheckGraphvizProvider(){ - if (substr(PHP_OS,0,3) === 'WIN'){ + public function CheckGraphvizProvider() { + if (substr(PHP_OS, 0, 3) === 'WIN') { return []; } @@ -64,5 +64,46 @@ class SetupUtilsTest extends ItopTestCase ]; } + /** + * @dataProvider HumanReadableSizeProvider + */ + public function testHumanReadableSize($fBytes, $sExpected) + { + $sOutput = SetupUtils::HumanReadableSize($fBytes); + $this->assertEquals($sExpected, $sOutput); + } + public function HumanReadableSizeProvider(): array + { + return [ + '10 bytes' => [ + 10, + '10 bytes', + ], + '10 kilobytes' => [ + 10 * 1024, + '10.24 kB', + ], + '10 megabytes' => [ + 10 * 1024 * 1024, + '10.49 MB', + ], + '10 gigabytes' => [ + 10 * 1024 * 1024 * 1024, + '10.74 GB', + ], + '10 terabytes' => [ + 10 * 1024 * 1024 * 1024 * 1024, + '11.00 TB', + ], + '10 petabytes' => [ + 10 * 1024 * 1024 * 1024 * 1024 * 1024, + '11.26 PB', + ], + '10 exabytes' => [ + 10 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, + '11.53 EB', + ], + ]; + } } From dbd5ba03773e9c6f7c194fc15bc2d43bad23abbc Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Wed, 13 Mar 2024 09:56:31 +0100 Subject: [PATCH 2/2] =?UTF-8?q?N=C2=B07302=20Fix=20SetupUtilsTest::testHum?= =?UTF-8?q?anReadableSize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup/setuputils.class.inc.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index cc49bcdc5..329a6b9f8 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -910,12 +910,16 @@ class SetupUtils { $aSizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB'); $index = 0; - while (($fBytes > 1000) && ($index < count($aSizes))) - { + while (($fBytes > 1000) && ($index < count($aSizes))) { $index++; $fBytes = $fBytes / 1000; } + if ($index == 0) { + // display int for bytes + return sprintf('%d %s', $fBytes, $aSizes[$index]); + } + return sprintf('%.2f %s', $fBytes, $aSizes[$index]); }