diff --git a/composer-dependency-analyser.php b/composer-dependency-analyser.php index 95d1b58e..40b96a5a 100644 --- a/composer-dependency-analyser.php +++ b/composer-dependency-analyser.php @@ -31,6 +31,9 @@ ->ignoreErrorsOnPackage('twig/twig', [ ErrorType::DEV_DEPENDENCY_IN_PROD, ]) + ->ignoreErrorsOnPackage('symfony/asset', [ + ErrorType::DEV_DEPENDENCY_IN_PROD, + ]) ; if (\PHP_VERSION_ID < 80200) { // TODO: Requires PHP >= 8.2 diff --git a/composer.json b/composer.json index 61cbc3ec..52b09c09 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "require": { "php": ">=8.1", "ext-json": "*", + "ext-filter": "*", "psr/container": "^2.0", "psr/log": "^3.0", "symfony/config": "^6.4 || ^7.0", @@ -45,6 +46,7 @@ "phpstan/phpstan-symfony": "^2.0", "phpunit/phpunit": "^10.5.46", "shipmonk/composer-dependency-analyser": "^1.8", + "symfony/asset": "^6.4 || ^7.0", "symfony/error-handler": "^6.4 || ^7.0", "symfony/framework-bundle": "^6.4 || ^7.0", "symfony/http-client": "^6.4 || ^7.0", diff --git a/config/services.php b/config/services.php index 74d36414..649fd2b8 100644 --- a/config/services.php +++ b/config/services.php @@ -43,6 +43,7 @@ ->tag('twig.extension') ; $services->set('sensiolabs_gotenberg.twig.asset_runtime', GotenbergRuntime::class) + ->args([service('assets.packages')->nullOnInvalid()]) ->tag('twig.runtime') ; diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index f8b209e6..900e8227 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -24,9 +24,12 @@ public function getConfigTreeBuilder(): TreeBuilder $treeBuilder->getRootNode() ->addDefaultsIfNotSet() ->children() - ->scalarNode('assets_directory') + ->arrayNode('assets_directory') + ->normalizeKeys(false) + ->prototype('scalar')->end() ->info('Base directory will be used for assets, files, markdown') - ->defaultValue('%kernel.project_dir%/assets') + ->defaultValue(['%kernel.project_dir%/assets']) + ->beforeNormalization()->castToArray()->end() ->end() ->scalarNode('version') ->info('Version of Gotenberg') diff --git a/src/Formatter/AssetBaseDirFormatter.php b/src/Formatter/AssetBaseDirFormatter.php index 07715207..856730a8 100644 --- a/src/Formatter/AssetBaseDirFormatter.php +++ b/src/Formatter/AssetBaseDirFormatter.php @@ -2,6 +2,7 @@ namespace Sensiolabs\GotenbergBundle\Formatter; +use Symfony\Component\Filesystem\Exception\FileNotFoundException; use Symfony\Component\Filesystem\Path; /** @@ -9,25 +10,43 @@ */ final class AssetBaseDirFormatter { - private readonly string $baseDir; + /** @var string[] */ + private readonly array $baseDir; + /** + * @param string[] $baseDir + */ public function __construct( private readonly string $projectDir, - string $baseDir, + array $baseDir, ) { - $this->baseDir = rtrim($baseDir, '/\\'); + $this->baseDir = array_map(static fn ($value) => rtrim($value, '/\\'), $baseDir); } public function resolve(string $path): string { - if (Path::isAbsolute($path)) { + if (Path::isAbsolute($path) || filter_var($path, \FILTER_VALIDATE_URL)) { return $path; } - if (Path::isAbsolute($this->baseDir)) { - return Path::join($this->baseDir, $path); + foreach ($this->baseDir as $baseDir) { + if (Path::isAbsolute($baseDir)) { + $filename = Path::join($baseDir, $path); + if (!file_exists($filename)) { + continue; + } + + return $filename; + } + + $filename = Path::join($this->projectDir, $baseDir, $path); + if (!file_exists($filename)) { + continue; + } + + return $filename; } - return Path::join($this->projectDir, $this->baseDir, $path); + throw new FileNotFoundException(\sprintf('File "%s" not found in assets directories: "%s".', $path, implode('", "', $this->baseDir))); } } diff --git a/src/Test/Builder/GotenbergBuilderTestCase.php b/src/Test/Builder/GotenbergBuilderTestCase.php index dc085dae..ad559137 100644 --- a/src/Test/Builder/GotenbergBuilderTestCase.php +++ b/src/Test/Builder/GotenbergBuilderTestCase.php @@ -33,7 +33,7 @@ protected function setUp(): void $this->client = new GotenbergClientAsserter(); $this->container = new Container(); - $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(static::FIXTURE_DIR, static::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(static::FIXTURE_DIR, [static::FIXTURE_DIR])); $this->container->set('sensiolabs_gotenberg.client', $this->client); $this->container->set('sensiolabs_gotenberg.version_fetcher', new StaticVersionFetcher($this->gotenbergVersion)); } diff --git a/src/Twig/GotenbergRuntime.php b/src/Twig/GotenbergRuntime.php index f10dc05b..ddf76d86 100644 --- a/src/Twig/GotenbergRuntime.php +++ b/src/Twig/GotenbergRuntime.php @@ -3,6 +3,7 @@ namespace Sensiolabs\GotenbergBundle\Twig; use Sensiolabs\GotenbergBundle\Builder\BuilderAssetInterface; +use Symfony\Component\Asset\Packages; /** * @internal @@ -14,6 +15,10 @@ final class GotenbergRuntime { private BuilderAssetInterface|null $builder = null; + public function __construct(private readonly Packages|null $packages) + { + } + public function setBuilder(BuilderAssetInterface|null $builder): void { $this->builder = $builder; @@ -27,6 +32,7 @@ public function setBuilder(BuilderAssetInterface|null $builder): void */ public function getAssetUrl(string $path): string { + $path = $this->getVersionedPathIfExist($path); $this->addAsset($path, 'gotenberg_asset'); return basename($path); @@ -34,6 +40,7 @@ public function getAssetUrl(string $path): string public function getFontStyleTag(string $path, string $name): string { + $path = $this->getVersionedPathIfExist($path); $this->addAsset($path, 'gotenberg_font_style_tag'); return ''; @@ -41,6 +48,7 @@ public function getFontStyleTag(string $path, string $name): string public function getFontFace(string $path, string $name): string { + $path = $this->getVersionedPathIfExist($path); $this->addAsset($path, 'gotenberg_font_face'); return $this->generateFontFace($path, $name); @@ -62,4 +70,14 @@ private function addAsset(string $path, string $function): void $this->builder->addAsset($path); } + + private function getVersionedPathIfExist(string $path): string + { + $packages = $this->packages; + if (null !== $packages) { + $path = ltrim($packages->getUrl($path), '/'); + } + + return $path; + } } diff --git a/tests/Builder/Pdf/ConvertPdfBuilderTest.php b/tests/Builder/Pdf/ConvertPdfBuilderTest.php index 18d7a8ec..a4a2d425 100644 --- a/tests/Builder/Pdf/ConvertPdfBuilderTest.php +++ b/tests/Builder/Pdf/ConvertPdfBuilderTest.php @@ -26,6 +26,8 @@ final class ConvertPdfBuilderTest extends GotenbergBuilderTestCase /** @use WebhookTestCaseTrait */ use WebhookTestCaseTrait; + private const ASSETS_DIR = __DIR__.'/../../Fixtures/assets'; + protected function createBuilder(): ConvertPdfBuilder { return new ConvertPdfBuilder(); @@ -100,7 +102,7 @@ public function testFilesExtensionRequirement(): void $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); $this->getBuilder() - ->files('b.png') + ->files(self::ASSETS_DIR.'logo.png') ->generate() ; } diff --git a/tests/Builder/Pdf/FlattenPdfBuilderTest.php b/tests/Builder/Pdf/FlattenPdfBuilderTest.php index fcb49e7b..5dba26cc 100644 --- a/tests/Builder/Pdf/FlattenPdfBuilderTest.php +++ b/tests/Builder/Pdf/FlattenPdfBuilderTest.php @@ -22,6 +22,8 @@ final class FlattenPdfBuilderTest extends GotenbergBuilderTestCase /** @use WebhookTestCaseTrait */ use WebhookTestCaseTrait; + private const ASSETS_DIR = __DIR__.'/../../Fixtures/assets'; + protected function createBuilder(): FlattenPdfBuilder { return new FlattenPdfBuilder(); @@ -54,7 +56,7 @@ public function testFilesExtensionRequirement(): void $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); $this->getBuilder() - ->files('b.png') + ->files(self::ASSETS_DIR.'logo.png') ->generate() ; } diff --git a/tests/Builder/Pdf/HtmlPdfBuilderTest.php b/tests/Builder/Pdf/HtmlPdfBuilderTest.php index 25d1ba27..3034b134 100644 --- a/tests/Builder/Pdf/HtmlPdfBuilderTest.php +++ b/tests/Builder/Pdf/HtmlPdfBuilderTest.php @@ -50,7 +50,7 @@ public function testRequiredFormData(): void public function testOutputFilename(): void { - $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, [self::FIXTURE_DIR])); $this->getBuilder() ->contentFile('files/content.html') @@ -64,7 +64,7 @@ public function testOutputFilename(): void public function testWidth(): void { - $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, [self::FIXTURE_DIR])); $this->getBuilder() ->contentFile('files/content.html') @@ -83,7 +83,7 @@ public function testWidth(): void public function testWithTwigContentFile(): void { - $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, [self::FIXTURE_DIR])); $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ 'strict_variables' => true, @@ -92,7 +92,7 @@ public function testWithTwigContentFile(): void $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { public function load(string $class): object|null { - return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + return GotenbergRuntime::class === $class ? new GotenbergRuntime(null) : null; } }); @@ -123,7 +123,7 @@ public function load(string $class): object|null public function testWithTwigAndHeaderFooterParts(): void { - $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, [self::FIXTURE_DIR])); $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ 'strict_variables' => true, @@ -132,7 +132,7 @@ public function testWithTwigAndHeaderFooterParts(): void $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { public function load(string $class): object|null { - return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + return GotenbergRuntime::class === $class ? new GotenbergRuntime(null) : null; } }); @@ -195,7 +195,7 @@ public function load(string $class): object|null public function testFilesAsHeaderAndFooter(): void { - $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, [self::FIXTURE_DIR])); $this->getBuilder() ->headerFile('files/header.html') @@ -217,7 +217,7 @@ public function testWithInvalidTwigTemplate(): void { $this->expectException(PartRenderingException::class); - $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, [self::FIXTURE_DIR])); $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ 'strict_variables' => true, @@ -226,7 +226,7 @@ public function testWithInvalidTwigTemplate(): void $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { public function load(string $class): object|null { - return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + return GotenbergRuntime::class === $class ? new GotenbergRuntime(null) : null; } }); diff --git a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php index d9b170a7..014b6b79 100644 --- a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php +++ b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php @@ -22,6 +22,8 @@ final class MarkdownPdfBuilderTest extends GotenbergBuilderTestCase /** @use ChromiumPdfTestCaseTrait */ use ChromiumPdfTestCaseTrait; + private const ASSETS_DIR = __DIR__.'/../../Fixtures/assets'; + protected function createBuilder(): MarkdownPdfBuilder { return new MarkdownPdfBuilder(); @@ -59,7 +61,7 @@ public function testFileWithContent(): void $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { public function load(string $class): object|null { - return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + return GotenbergRuntime::class === $class ? new GotenbergRuntime(null) : null; } }); @@ -121,7 +123,7 @@ public function testFilesExtensionRequirement(): void $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); $this->getBuilder() - ->files('b.png') + ->files(self::ASSETS_DIR.'logo.png') ->generate() ; } diff --git a/tests/Builder/Pdf/MergePdfBuilderTest.php b/tests/Builder/Pdf/MergePdfBuilderTest.php index fd3f7447..65dbdbb5 100644 --- a/tests/Builder/Pdf/MergePdfBuilderTest.php +++ b/tests/Builder/Pdf/MergePdfBuilderTest.php @@ -34,6 +34,8 @@ final class MergePdfBuilderTest extends GotenbergBuilderTestCase /** @use WebhookTestCaseTrait */ use WebhookTestCaseTrait; + private const ASSETS_DIR = __DIR__.'/../../Fixtures/assets'; + protected function createBuilder(): MergePdfBuilder { return new MergePdfBuilder(); @@ -86,7 +88,7 @@ public function testFilesExtensionRequirement(): void $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); $this->getBuilder() - ->files('simple_pdf.pdf', 'b.png') + ->files(self::ASSETS_DIR.'logo.png') ->generate() ; } diff --git a/tests/Builder/Pdf/SplitPdfBuilderTest.php b/tests/Builder/Pdf/SplitPdfBuilderTest.php index 770c8cc2..8566153b 100644 --- a/tests/Builder/Pdf/SplitPdfBuilderTest.php +++ b/tests/Builder/Pdf/SplitPdfBuilderTest.php @@ -39,6 +39,8 @@ final class SplitPdfBuilderTest extends GotenbergBuilderTestCase /** @use WebhookTestCaseTrait */ use WebhookTestCaseTrait; + private const ASSETS_DIR = __DIR__.'/../../Fixtures/assets'; + protected function createBuilder(): SplitPdfBuilder { return new SplitPdfBuilder(); @@ -95,7 +97,7 @@ public function testFilesExtensionRequirement(): void $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); $this->getBuilder() - ->files('b.png') + ->files(self::ASSETS_DIR.'logo.png') ->splitMode(SplitMode::Pages) ->splitSpan('1-2') ->generate() diff --git a/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php b/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php index df680454..4435d969 100644 --- a/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php @@ -39,7 +39,7 @@ protected function initializeBuilder(BuilderInterface $builder, Container $conta public function testOutputFilename(): void { - $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, [self::FIXTURE_DIR])); $this->getBuilder() ->contentFile('files/content.html') @@ -60,7 +60,7 @@ public function testWithTwigContentFile(): void $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { public function load(string $class): object|null { - return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + return GotenbergRuntime::class === $class ? new GotenbergRuntime(null) : null; } }); diff --git a/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php b/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php index ffea6e72..a94e6fcd 100644 --- a/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php @@ -23,6 +23,8 @@ final class MarkdownScreenshotBuilderTest extends GotenbergBuilderTestCase /** @use ChromiumScreenshotTestCaseTrait */ use ChromiumScreenshotTestCaseTrait; + private const ASSETS_DIR = __DIR__.'/../../Fixtures/assets'; + protected function createBuilder(): MarkdownScreenshotBuilder { return new MarkdownScreenshotBuilder(); @@ -41,7 +43,7 @@ protected function initializeBuilder(BuilderInterface $builder, Container $conta public function testOutputFilename(): void { - $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, [self::FIXTURE_DIR])); $this->getBuilder() ->wrapperFile('files/content.html') @@ -75,7 +77,7 @@ public function testFileWithContent(): void $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { public function load(string $class): object|null { - return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + return GotenbergRuntime::class === $class ? new GotenbergRuntime(null) : null; } }); @@ -137,7 +139,7 @@ public function testFilesExtensionRequirement(): void $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); $this->getBuilder() - ->files('b.png') + ->files(self::ASSETS_DIR.'logo.png') ->generate() ; } diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 0563fe57..1fbfcd6b 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -216,7 +216,7 @@ public function testInvalidWebhookConfiguration(array $config): void /** * @return array{ - * 'assets_directory': string, + * 'assets_directory': string[], * 'http_client': string, * 'webhook': array, * 'default_options': array{ @@ -235,7 +235,7 @@ private static function getBundleDefaultConfig(): array { return [ 'version' => null, - 'assets_directory' => '%kernel.project_dir%/assets', + 'assets_directory' => ['%kernel.project_dir%/assets'], 'http_client' => 'http_client', 'webhook' => [], 'controller_listener' => true, diff --git a/tests/Formatter/AssetBaseDirFormatterTest.php b/tests/Formatter/AssetBaseDirFormatterTest.php index 932a46fe..6ce3bdd2 100644 --- a/tests/Formatter/AssetBaseDirFormatterTest.php +++ b/tests/Formatter/AssetBaseDirFormatterTest.php @@ -9,23 +9,36 @@ final class AssetBaseDirFormatterTest extends TestCase { + private const PROJECT_DIR = __DIR__.'/../'; + /** - * @return iterable> + * @return iterable|string>> */ public static function generateBaseDirectoryAndPath(): iterable { - yield 'absolute path and absolute base dir' => ['/mock/foo/file.md', '/mock/bar', '/mock/foo/file.md']; - yield 'absolute path and relative base dir' => ['/mock/foo/logo.png', '/bar', '/mock/foo/logo.png']; - yield 'relative path and relative base dir' => ['document.odt', 'bar/baz', '/mock/bar/baz/document.odt']; - yield 'relative path and absolute base dir' => ['foo/document.odt', '/mock/bar/baz', '/mock/bar/baz/foo/document.odt']; - yield 'relative path and relative base dir with end slash' => ['document.odt', 'bar/baz/', '/mock/bar/baz/document.odt']; + $projectDir = \dirname(self::PROJECT_DIR, 2); + + yield 'absolute path and absolute base dir' => [$projectDir.'/Fixtures/assets/file.md', [$projectDir.'/Fixtures/assets'], $projectDir.'/Fixtures/assets/file.md']; + yield 'absolute path and relative base dir' => [$projectDir.'/Fixtures/assets/file.md', ['assets'], $projectDir.'/Fixtures/assets/file.md']; + yield 'relative path and relative base dir' => ['file.md', ['Fixtures/assets'], $projectDir.'/Fixtures/assets/file.md']; + yield 'relative path and absolute base dir' => ['office/document.odt', [$projectDir.'/Fixtures/assets'], $projectDir.'/Fixtures/assets/office/document.odt']; + yield 'relative path and relative base dir with end slash' => ['document.odt', ['Fixtures/assets/office/'], $projectDir.'/Fixtures/assets/office/document.odt']; + yield 'URL path and absolute base dir' => ['https://sensiolabs.com/assets/images/sensiolabs/sensiolabs.fr-OAnPSf0.png', [$projectDir.'/Fixtures/assets'], 'https://sensiolabs.com/assets/images/sensiolabs/sensiolabs.fr-OAnPSf0.png']; + yield 'URL path and relative base dir' => ['https://sensiolabs.com/assets/images/sensiolabs/sensiolabs.fr-OAnPSf0.png', ['assets'], 'https://sensiolabs.com/assets/images/sensiolabs/sensiolabs.fr-OAnPSf0.png']; + yield 'absolute path and two absolute base dir' => [$projectDir.'/Fixtures/assets/office/document.odt', [$projectDir.'/Fixtures/assets', $projectDir.'/Fixtures/assets/office'], $projectDir.'/Fixtures/assets/office/document.odt']; + yield 'absolute path and two relative base dir' => [$projectDir.'/Fixtures/assets/office/document.odt', ['Fixtures/assets', 'Fixtures/assets/office'], $projectDir.'/Fixtures/assets/office/document.odt']; + yield 'relative path and two absolute base dir' => ['document.odt', [$projectDir.'/Fixtures/assets', $projectDir.'/Fixtures/assets/office'], $projectDir.'/Fixtures/assets/office/document.odt']; + yield 'relative path and two relative base dir' => ['document.odt', ['Fixtures/assets', 'Fixtures/assets/office'], $projectDir.'/Fixtures/assets/office/document.odt']; } + /** + * @param string[] $baseDirectories + */ #[DataProvider('generateBaseDirectoryAndPath')] #[TestDox('Resolve path when "$_dataName"')] - public function testResolvePathCorrectly(string $path, string $baseDirectory, string $expectedResult): void + public function testResolvePathCorrectly(string $path, array $baseDirectories, string $expectedResult): void { - $assetBaseDirFormatter = new AssetBaseDirFormatter('/mock', $baseDirectory); + $assetBaseDirFormatter = new AssetBaseDirFormatter(self::PROJECT_DIR, $baseDirectories); $resolvedPath = $assetBaseDirFormatter->resolve($path); self::assertSame($expectedResult, $resolvedPath); } diff --git a/tests/Twig/GotenbergRuntimeTest.php b/tests/Twig/GotenbergRuntimeTest.php index 509f8e6e..63ebfaa8 100644 --- a/tests/Twig/GotenbergRuntimeTest.php +++ b/tests/Twig/GotenbergRuntimeTest.php @@ -10,7 +10,7 @@ class GotenbergRuntimeTest extends TestCase { public function testGetAsset(): void { - $runtime = new GotenbergRuntime(); + $runtime = new GotenbergRuntime(null); $builder = $this->createMock(BuilderAssetInterface::class); $builder ->expects($this->once()) @@ -25,13 +25,13 @@ public function testGetAssetThrowsWhenBuilderIsNotSet(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('The gotenberg_asset function must be used in a Gotenberg context.'); - $runtime = new GotenbergRuntime(); + $runtime = new GotenbergRuntime(null); $runtime->getAssetUrl('foo'); } public function testGetFontFace(): void { - $runtime = new GotenbergRuntime(); + $runtime = new GotenbergRuntime(null); $builder = $this->createMock(BuilderAssetInterface::class); $builder ->expects($this->once()) @@ -47,7 +47,7 @@ public function testGetFontFace(): void public function testGetFontStyleTag(): void { - $runtime = new GotenbergRuntime(); + $runtime = new GotenbergRuntime(null); $builder = $this->createMock(BuilderAssetInterface::class); $builder ->expects($this->once())