Split extension into extension and runtime classes to match how the maker bundle creates twig extensions

This commit is contained in:
Brabli
2023-05-31 11:51:36 +01:00
parent 08d906260a
commit 493f0c275b
4 changed files with 38 additions and 31 deletions

View File

@@ -4,12 +4,12 @@ declare(strict_types=1);
namespace Pcm\IconBundle\Tests\Twig\Functions;
use Pcm\IconBundle\Twig\Functions\IconExtension;
use Pcm\IconBundle\Twig\Functions\IconNotFound;
use Pcm\IconBundle\Twig\Functions\ColourNotFound;
use Pcm\IconBundle\Exception\ColourNotFound;
use Pcm\IconBundle\Exception\IconNotFound;
use Pcm\IconBundle\Twig\Runtime\IconRuntime;
use PHPUnit\Framework\TestCase;
class IconExtensionTest extends TestCase
class IconRuntimeTest extends TestCase
{
private const ICON = 'test';
@@ -32,11 +32,14 @@ class IconExtensionTest extends TestCase
]
];
private IconExtension $icon;
private IconRuntime $icon;
protected function setUp(): void
{
$this->icon = new IconExtension(['tests/icons'], self::COLOURS);
$this->icon = new IconRuntime(
directories: ['tests/icons'],
colours: self::COLOURS
);
}
public function testThrowsWhenPassedAnInvalidIconName(): void
@@ -119,7 +122,7 @@ class IconExtensionTest extends TestCase
public function testDefaultSizeIsSetOnSvgIfNoSizeOptionPassed(): void
{
$defaultSize = IconExtension::DEFAULT_SIZE;
$defaultSize = IconRuntime::DEFAULT_SIZE;
$content = $this->icon->renderIcon(['icon' => self::ICON]);
$regex = "/^<svg.+?width=\"{$defaultSize}\"/";
@@ -131,7 +134,7 @@ class IconExtensionTest extends TestCase
public function testDefaultSizeIsOnlySetOnce(): void
{
$defaultSize = IconExtension::DEFAULT_SIZE;
$defaultSize = IconRuntime::DEFAULT_SIZE;
$content = $this->icon->renderIcon(['icon' => self::ICON]);
$widthRegex = "/width=\"{$defaultSize}\"/";