<?php

declare(strict_types=1);

namespace App\Tests;

use PHPUnit\Framework\TestCase;
use App\Template\TwigExtension;
use Twig\TwigFilter;

final class TwigExtensionTest extends \PHPUnit\Framework\TestCase
{
    public function testGetFilters(): void
    {
        $obj = new TwigExtension();
        $filters = $obj->getFilters();
        $this->assertNotEmpty($filters, "Filters must not be empty");
        $this->assertContainsOnlyInstancesOf(TwigFilter::class, $filters);
    }


    public function testformatBytes(): void
    {
        $obj = new TwigExtension();
        $this->assertEquals('1.00B', $obj->formatBytes(1, 2));
        $this->assertEquals('2.00B', $obj->formatBytes(2, 2));
        $this->assertEquals('10.00B', $obj->formatBytes(10, 2));
        $this->assertEquals('0.98kB', $obj->formatBytes(1000, 2));
        $this->assertEquals('1.00kB', $obj->formatBytes(1024, 2));
        $this->assertEquals('512.00MB', $obj->formatBytes(1024 ** 3 / 2, 2));
        $this->assertEquals('1.00GB', $obj->formatBytes(1024 ** 3 - 1, 2));
        $this->assertEquals('1.00GB', $obj->formatBytes(1024 ** 3, 2));
        $this->assertEquals('512.00GB', $obj->formatBytes(1024 ** 4 / 2, 2));
        $this->assertEquals('1.00TB', $obj->formatBytes(1024 ** 4, 2));

        $this->assertEquals('1.00B', $obj->formatBytes(1));
        $this->assertEquals('1.00TB', $obj->formatBytes(1024 ** 4));
    }
}