ArrayLoader example

'validLines' => '4476',
                ],
            ],
        ]$coverageReport['js']);
    }

    /** * @param mixed[] $parameters */
    private function runCommand(array $parameters): string
    {
        $getClassesCommand = new SummarizeCoverageReports($this->getProjectDir()new Environment(new ArrayLoader()));
        $definition = $getClassesCommand->getDefinition();
        $input = new ArrayInput(
            $parameters,
            $definition
        );
        $input->getOptions();
        $output = new BufferedOutput();

        $refMethod = ReflectionHelper::getMethod(SummarizeCoverageReports::class, 'execute');
        $refMethod->invoke($getClassesCommand$input$output);

        
'context' => Context::createDefaultContext(),
        ]);

        static::assertEquals('', $result);
    }

    private function render(string $template, array $data): string
    {
        $twig = $this->getContainer()->get('twig');

        $originalLoader = $twig->getLoader();
        $twig->setLoader(new ArrayLoader([
            'test.html.twig' => file_get_contents(__DIR__ . '/fixture/' . $template),
        ]));
        $output = $twig->render('test.html.twig', $data);
        $twig->setLoader($originalLoader);

        return $output;
    }
}
TWIG;

        $twig = new Environment(new ArrayLoader([]));
        $twig->addExtension(new DebugExtension());
        $parser = new TwigVariableParser($twig);

        $variables = $parser->parse($template);

        $expected = [
            'product.price.gross',
            'product.prices',
            'product.name',
            'product.stock',
            'product.translated.name',
            
if (!$config->getSkipInvalid()) {
                throw SeoException::invalidTemplate('Error: ' . $error->getMessage());
            }

            return null;
        }
    }

    private function setTwigTemplate(SeoUrlRouteConfig $config, string $template): void
    {
        $template = '{% autoescape \'' . self::ESCAPE_SLUGIFY . "' %}$template{% endautoescape %}";
        $this->twig->setLoader(new ArrayLoader(['template' => $template]));

        try {
            $this->twig->loadTemplate($this->twig->getTemplateClass('template'), 'template');
        } catch (SyntaxError $syntaxError) {
            if (!$config->getSkipInvalid()) {
                throw SeoException::invalidTemplate('Syntax error: ' . $syntaxError->getMessage());
            }
        }
    }

    private function removePrefix(string $subject, string $prefix): string
    {
/** * @internal * * @covers \Shopware\Core\Framework\Adapter\Twig\TwigVariableParserFactory */
class TwigVariableParserFactoryTest extends TestCase
{
    public function testGetParser(): void
    {
        $factory = new TwigVariableParserFactory();
        $twig = new Environment(new ArrayLoader([]));

        static::assertInstanceOf(TwigVariableParser::class$factory->getParser($twig));
    }
}
use Twig\Loader\ArrayLoader;

/** * @internal * * @covers \Shopware\Core\Framework\Adapter\Twig\Filter\ReplaceRecursiveFilter */
class ReplaceRecursiveFilterTest extends TestCase
{
    public function testReplace(): void
    {
        $env = new Environment(new ArrayLoader(['test' => '{{ {"berries": ["blueberry"]}|replace_recursive({"berries": ["strawberry", "blackberry"]})|json_encode|raw }}']));
        $env->addExtension(new ReplaceRecursiveFilter());

        static::assertSame('{"berries":["strawberry","blackberry"]}', $env->render('test'));
    }
}
$finder = new Finder();
            foreach ($finder->in($moduleDirectory->getRealPath())->depth(0)->directories() as $areaDirectory) {
                $finder = new Finder();
                $xmlFiles = $finder->in($areaDirectory->getRealPath())->files()->name('cobertura-coverage.xml')->getIterator();
                $xmlFiles->rewind();
                $xml = new Crawler(file_get_contents($xmlFiles->current()->getRealPath()) ?: '');
                $jsCoveragePerArea[$moduleDirectory->getFilename()][$areaDirectory->getFilename()] = $xml;
            }
        }

        $originalLoader = $this->twig->getLoader();
        $this->twig->setLoader(new ArrayLoader([
            'coverage-by-area-report.html.twig' => file_get_contents(self::TEMPLATE_FILE),
        ]));

        $jsCoverages = [];
        foreach ($jsCoveragePerArea as $coverageModuleName => $coverageModule) {
            $jsCoverages[$coverageModuleName] = $this->getCoverage($coverageModule);
        }

        $data = [
            'php' => [
                'shopware/platform' => $this->getCoverage($phpCoveragePerArea),
            ],
public function testCodeRun(string $twigCode, bool $shouldThrow): void
    {
        $_SERVER['TEST_TWIG'] = false;

        $deprecationMessage = null;
        set_error_handler(function D$errno$errstr) use (&$deprecationMessage) {
            $deprecationMessage = $errstr;

            return true;
        });

        $twig = new Environment(new ArrayLoader(['test.twig' => $twigCode]));
        $twig->addTokenParser(new FeatureFlagCallTokenParser());
        $twig->render('test.twig', [
            'foo' => new TestService(),
        ]);

        restore_error_handler();

        if ($shouldThrow) {
            static::assertNotNull($deprecationMessage);
        } else {
            static::assertNull($deprecationMessage);
        }

    }

    public function generate(): array
    {
        $hookClassNames = $this->getHookClasses();

        $data = $this->getHookData($hookClassNames);

        $originalLoader = $this->twig->getLoader();

        $this->twig->setLoader(new ArrayLoader([
            'hook-reference.md.twig' => file_get_contents(self::TEMPLATE_FILE),
        ]));

        try {
            $result = [
                self::GENERATED_DOC_FILE => $this->twig->render('hook-reference.md.twig', ['data' => $data]),
            ];
        } finally {
            $this->twig->setLoader($originalLoader);
        }

        

class PcreExtensionTest extends TestCase
{
    /** * @dataProvider replaceCases */
    public function testReplaces(string $template, string $expected): void
    {
        $extension = new PcreExtension();

        $env = new Environment(new ArrayLoader(['test' => $template]));
        $env->addExtension($extension);

        static::assertSame($expected$env->render('test'));
    }

    /** * @return iterable<array-key, array{string, string}> */
    public static function replaceCases(): iterable
    {
        yield 'replaces' => [
            


    public function render(): string
    {
        $eventsDoc = [];

        $this->collectBusinessEvent($eventsDoc);

        $this->collectEntityWrittenEvent($eventsDoc);

        $originalLoader = $this->twig->getLoader();
        $this->twig->setLoader(new ArrayLoader([
            'hookable-events-list.md.twig' => file_get_contents(self::EVENTS_TEMPLATE),
        ]));

        try {
            return $this->twig->render(
                'hookable-events-list.md.twig',
                ['eventDocs' => $eventsDoc]
            );
        } catch (LoaderError|RuntimeError|SyntaxError $e) {
            throw new \RuntimeException('Can not render Webhook Events', $e->getCode()$e);
        } finally {
            
use Twig\Extension\ExtensionInterface;
use Twig\Loader\ArrayLoader;

#[Package('buyers-experience')] class SeoUrlTwigFactory
{
    /** * @param ExtensionInterface[] $twigExtensions */
    public function createTwigEnvironment(SlugifyInterface $slugify, iterable $twigExtensions = []): Environment
    {
        $twig = new TwigEnvironment(new ArrayLoader());
        $twig->setCache(false);
        $twig->enableStrictVariables();
        $twig->addExtension(new SlugifyExtension($slugify));
        $twig->addExtension(new PhpSyntaxExtension());
        $twig->addExtension(new SecurityExtension([]));

        /** @var EscaperExtension $coreExtension */
        $coreExtension = $twig->getExtension(EscaperExtension::class);
        $coreExtension->setEscaper(
            SeoUrlGenerator::ESCAPE_SLUGIFY,
            // Do not remove $_twig, although it is marked as unused. It somehow important
 = $methodDoc->getMethodName();
        }
    }

    public function generate(): array
    {
        $scriptServices = $this->findScriptServices();

        $data = $this->getServicesData($scriptServices);

        $originalLoader = $this->twig->getLoader();
        $this->twig->setLoader(new ArrayLoader([
            'service-reference.md.twig' => file_get_contents(self::TEMPLATE_FILE),
        ]));

        $result = [];

        try {
            foreach ($data as $group) {
                $result[self::GENERATED_DOC_FILE . $group['fileName']] = $this->twig->render('service-reference.md.twig', $group);
            }
        } finally {
            $this->twig->setLoader($originalLoader);
        }

        $template = <<<TWIG {% set label = item.label|trans({}, 'storefront') %} {{ label }} TWIG;

        $context = Context::createDefaultContext();

        $item = new LineItem('test', 'test');
        $item->setLabel($label);

        $environment = new Environment(new ArrayLoader());
        $translator = $this->createMock(Translator::class);
        $translator
            ->method('trans')
            ->willReturnCallback(static function Dstring $id) {
                if ($id === 'general.homeLink') {
                    return 'Home';
                }

                return $id;
            });

        
class TwigVariableParser
{
    /** * @internal */
    public function __construct(private readonly Environment $twig)
    {
    }

    public function parse(string $template): array
    {
        $loader = new ArrayLoader(['content.html.twig' => $template]);

        $source = $loader->getSourceContext('content.html.twig');

        $stream = $this->twig->tokenize($source);

        $parsed = $this->twig->parse($stream);

        return array_values($this->getVariables($parsed));
    }

    private function getVariables(iterable $nodes, array $aliases = []): array
    {
Home | Imprint | This part of the site doesn't use cookies.