engelsystem/tests/Unit/Renderer/Twig/Extensions/AssetsTest.php

48 lines
1.5 KiB
PHP
Raw Normal View History

2018-09-10 14:40:33 +02:00
<?php
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
use Engelsystem\Http\UrlGenerator;
use Engelsystem\Renderer\Twig\Extensions\Assets;
use PHPUnit\Framework\MockObject\MockObject;
class AssetsTest extends ExtensionTest
{
/**
* @covers \Engelsystem\Renderer\Twig\Extensions\Assets::__construct
* @covers \Engelsystem\Renderer\Twig\Extensions\Assets::getFunctions
*/
2021-08-17 15:10:31 +02:00
public function testGetFunctions()
2018-09-10 14:40:33 +02:00
{
/** @var UrlGenerator|MockObject $urlGenerator */
$urlGenerator = $this->createMock(UrlGenerator::class);
$extension = new Assets($urlGenerator);
$functions = $extension->getFunctions();
$this->assertExtensionExists('asset', [$extension, 'getAsset'], $functions);
}
/**
* @covers \Engelsystem\Renderer\Twig\Extensions\Assets::getAsset
*/
public function testGetAsset()
{
/** @var UrlGenerator|MockObject $urlGenerator */
$urlGenerator = $this->createMock(UrlGenerator::class);
$urlGenerator->expects($this->exactly(2))
->method('to')
->with('/assets/foo.css')
->willReturn('https://foo.bar/project/assets/foo.css');
$extension = new Assets($urlGenerator);
$return = $extension->getAsset('assets/foo.css');
$this->assertEquals('https://foo.bar/project/assets/foo.css', $return);
$return = $extension->getAsset('/assets/foo.css');
$this->assertEquals('https://foo.bar/project/assets/foo.css', $return);
}
}