FeatureCallSilentToken example

use Twig\Node\TextNode;

/** * @internal * * @covers \Shopware\Core\Framework\Adapter\Twig\Node\FeatureCallSilentToken */
class FeatureCallSilentTokenTest extends TestCase
{
    public function testCompile(): void
    {
        $token = new FeatureCallSilentToken('v6.5.0.0', new TextNode('test', 1), 1, 'sw_feature');

        $compiler = new Compiler(new Environment(new ArrayLoader()));

        $compiler->compile($token);

        $code = <<<'PHP' // line 1 \Shopware\Core\Framework\Feature::callSilentIfInactive('v6.5.0.0', function () use(&$context) { echo "test"; }); PHP;

        
$flagName = $flagToken->getValue();

        // The feature flag is followed by an endblock token, remove it from the stream         $stream->next();

        // Parse the body of the tag inside         $body = $this->parser->subparse($this->decideBlockEnd(...), true);

        // We read until the string of the end of the block. But we need to parse the end tag as well, so the parser is on clean state again.         $stream->next();

        return new FeatureCallSilentToken($flagName$body$flagToken->getLine()$this->getTag());
    }

    public function getTag(): string
    {
        return 'sw_silent_feature_call';
    }

    public function decideBlockEnd(Token $token): bool
    {
        return $token->test('endsw_silent_feature_call');
    }
}
Home | Imprint | This part of the site doesn't use cookies.