<?php

namespace App\Tests\Unit\Service\Twig;

use App\Service\File\FileManager;
use App\Service\Twig\AssetsExtension;
use App\Service\Utils\PathUtils;
use PHPUnit\Framework\TestCase;

class AssetsExtensionTest extends TestCase
{
    private FileManager $fileManager;

    public function setUp(): void
    {
        $this->fileManager = $this->getMockBuilder(FileManager::class)->disableOriginalConstructor()->getMock();
    }

    public function testGetFunctions(): void
    {
        $assetsExtension = $this
            ->getMockBuilder(AssetsExtension::class)
            ->setConstructorArgs([$this->fileManager])
            ->setMethodsExcept(['getFunctions'])
            ->getMock();

        $functions = $assetsExtension->getFunctions();

        $this->assertCount(2, $functions);

        $this->assertEquals('absPath', $functions[0]->getName());
        $this->assertEquals('fileImagePath', $functions[1]->getName());
    }

    public function testAbsPath(): void
    {
        $assetsExtension = $this
            ->getMockBuilder(AssetsExtension::class)
            ->setConstructorArgs([$this->fileManager])
            ->setMethodsExcept(['absPath'])
            ->getMock();

        $publicDir = PathUtils::getProjectDir().'/public';

        $this->assertEquals(
            $publicDir.'/foo',
            $assetsExtension->absPath('foo')
        );

        $this->assertEquals(
            $publicDir.'/foo/bar',
            $assetsExtension->absPath('foo/bar')
        );

        $this->assertEquals(
            $publicDir.'/',
            $assetsExtension->absPath('')
        );
    }
}
