Do not try to format size if 0

This commit is contained in:
Frederic Guillot 2017-02-04 18:25:41 -05:00
parent fe3ac50aca
commit 6307070507
2 changed files with 5 additions and 0 deletions

View File

@ -59,6 +59,10 @@ class TextHelper extends Base
*/
public function bytes($size, $precision = 2)
{
if ($size == 0) {
return 0;
}
$base = log($size) / log(1024);
$suffixes = array('', 'k', 'M', 'G', 'T');

View File

@ -107,6 +107,7 @@ class TextHelperTest extends Base
{
$textHelper = new TextHelper($this->container);
$this->assertEquals('0', $textHelper->bytes(0));
$this->assertEquals('1k', $textHelper->bytes(1024));
$this->assertEquals('33.71k', $textHelper->bytes(34520));
}