getExpr()->args[0]->value, $event->getStatementsSource() )); } }; $statementsAnalyzer = self::createStatementsAnalyzer($assertionHook); $statementsAnalyzer->analyze($statements, new Context()); } public function provideExpressions(): array { return [ ['dummy("expected.twig");'], ['dummy(\'expected.twig\');'], ['$a = "expected.twig"; dummy($a);'], ['$a = "expected"; $b = ".twig"; dummy($a.$b);'], ['$a = "pected"; dummy("ex".$a.".twig");'], ]; } public function testItThrowsAnExceptionWhenTryingToExtractTemplateNameFromAnUnsupportedExpression() { $hasErrors = false; $code = 'getExpr()->args[0]->value, $event->getStatementsSource() ); } }; $statementsAnalyzer = self::createStatementsAnalyzer($assertionHook); $this->expectException(RuntimeException::class); $statementsAnalyzer->analyze($statements, new Context()); } private static function createStatementsAnalyzer(AfterEveryFunctionCallAnalysisInterface $hook): StatementsAnalyzer { /** @var Config $config */ $config = (function () { return new self(); })->bindTo(null, Config::class)(); $config->eventDispatcher->registerClass(get_class($hook)); $nullFileAnalyzer = new FileAnalyzer(new ProjectAnalyzer($config, new Providers(new FileProvider())), '', ''); $nullFileAnalyzer->codebase->functions->addGlobalFunction('dummy', new FunctionStorage()); $nullFileAnalyzer->codebase->file_storage_provider->create(''); $nodeData = new NodeDataProvider(); (function () use ($nodeData) { $this->node_data = $nodeData; })->bindTo($nullFileAnalyzer, $nullFileAnalyzer)(); return new StatementsAnalyzer($nullFileAnalyzer, $nodeData); } }