/**
* @dataProvider getTests
*/
public function testIntegration($file, $test, $message, $templates)
{
$loader = new Twig_Loader_Array($templates);
$twig = new Twig_Environment($loader, array('trim_blocks' => true, 'cache' => false));
$twig->addExtension(new Twig_Extension_Escaper());
$twig->addExtension(new TestExtension());
try {
$template = $twig->loadTemplate('index.twig');
} catch (Twig_SyntaxError $e) {
$e->setFilename($file);
throw $e;
} catch (Exception $e) {
throw new Twig_Error($e->getMessage() . ' (in ' . $file . ')');
}
preg_match_all('/--DATA--(.*?)--EXPECT--(.*?)(?=\\-\\-DATA\\-\\-|$)/s', $test, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$output = trim($template->render(eval($match[1] . ';')), "\n ");
$expected = trim($match[2], "\n ");
if ($expected != $output) {
echo 'Compiled template that failed:';
foreach (array_keys($templates) as $name) {
echo "Template: {$name}\n";
$source = $loader->getSource($name);
echo $twig->compile($twig->parse($twig->tokenize($source, $name)));
}
}
$this->assertEquals($expected, $output, $message . ' (in ' . $file . ')');
}
}