setFileExtension('html'); // no theme, no custom dirs self::assertLoaderPaths( [(string) realpath(__DIR__ . '/../../lib/Templates/default/html')], TwigEnvironmentFactory::createTwigEnvironment($configuration) ); } public function testTemplateDirectoriesThemeAndDirectories(): void { $configuration = new Configuration(); $configuration->setFileExtension('html'); $configuration->setTheme('cool_theme'); $dir1 = $this->tmpPath . '/dir1'; $dir2 = $this->tmpPath . '/dir2'; $nonExistentDir = $this->tmpPath . '/dir3'; // dir1 has all directories $this->filesystem->mkdir($dir1); $this->filesystem->mkdir($dir1 . '/default/html'); $this->filesystem->mkdir($dir1 . '/cool_theme/html'); // dir2 has just the theme $this->filesystem->mkdir($dir2); $this->filesystem->mkdir($dir2 . '/cool_theme/html'); $configuration->setCustomTemplateDirs([$dir1, $dir2, $nonExistentDir]); // no theme, no custom dirs self::assertLoaderPaths( [ $dir1 . '/cool_theme/html', $dir2 . '/cool_theme/html', $dir1 . '/default/html', (string) realpath(__DIR__ . '/../../lib/Templates/default/html'), ], TwigEnvironmentFactory::createTwigEnvironment($configuration) ); } /** @param string[] $expectedPaths */ private static function assertLoaderPaths(array $expectedPaths, Environment $twig): void { $loader = $twig->getLoader(); if (! $loader instanceof FilesystemLoader) { throw new Exception('Wrong loader instance'); } self::assertSame($expectedPaths, $loader->getPaths()); } protected function setUp(): void { $this->tmpPath = sys_get_temp_dir() . '/_rst_twig_tests'; $this->filesystem = new Filesystem(); } protected function tearDown(): void { $this->filesystem->remove($this->tmpPath); } }