function IntegrationTestCase::doIntegrationTest
2 calls to IntegrationTestCase::doIntegrationTest()
- IntegrationTestCase::testIntegration in vendor/
twig/ twig/ src/ Test/ IntegrationTestCase.php - @dataProvider getTests
- IntegrationTestCase::testLegacyIntegration in vendor/
twig/ twig/ src/ Test/ IntegrationTestCase.php - @dataProvider getLegacyTests
File
-
vendor/
twig/ twig/ src/ Test/ IntegrationTestCase.php, line 168
Class
- IntegrationTestCase
- Integration test helper.
Namespace
Twig\TestCode
protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') {
if (!$outputs) {
$this->markTestSkipped('no tests to run');
}
if ($condition) {
$ret = '';
eval('$ret = ' . $condition . ';');
if (!$ret) {
$this->markTestSkipped($condition);
}
}
foreach ($outputs as $i => $match) {
$config = array_merge([
'cache' => false,
'strict_variables' => true,
], $match[2] ? eval($match[2] . ';') : []);
// make sure that template are always compiled even if they are the same (useful when testing with more than one data/expect sections)
foreach ($templates as $j => $template) {
$templates[$j] = $template . str_repeat(' ', $i);
}
$loader = new ArrayLoader($templates);
$twig = new Environment($loader, $config);
$twig->addGlobal('global', 'global');
foreach ($this->getRuntimeLoaders() as $runtimeLoader) {
$twig->addRuntimeLoader($runtimeLoader);
}
foreach ($this->getExtensions() as $extension) {
$twig->addExtension($extension);
}
foreach ($this->getTwigFilters() as $filter) {
$twig->addFilter($filter);
}
foreach ($this->getTwigTests() as $test) {
$twig->addTest($test);
}
foreach ($this->getTwigFunctions() as $function) {
$twig->addFunction($function);
}
$deprecations = [];
try {
$prevHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$prevHandler) {
if (\E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
return true;
}
return $prevHandler ? $prevHandler($type, $msg, $file, $line, $context) : false;
});
$template = $twig->load('index.twig');
} catch (\Exception $e) {
if (false !== $exception) {
$message = $e->getMessage();
$this->assertSame(trim($exception), trim(\sprintf('%s: %s', \get_class($e), $message)));
$last = substr($message, \strlen($message) - 1);
$this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.');
return;
}
throw new Error(\sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e);
} finally {
restore_error_handler();
}
$this->assertSame($deprecation, implode("\n", $deprecations));
try {
$output = trim($template->render(eval($match[1] . ';')), "\n ");
} catch (\Exception $e) {
if (false !== $exception) {
$this->assertStringMatchesFormat(trim($exception), trim(\sprintf('%s: %s', \get_class($e), $e->getMessage())));
return;
}
$e = new Error(\sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e);
$output = trim(\sprintf('%s: %s', \get_class($e), $e->getMessage()));
}
if (false !== $exception) {
[
$class,
] = explode(':', $exception);
$constraintClass = class_exists('PHPUnit\\Framework\\Constraint\\Exception') ? 'PHPUnit\\Framework\\Constraint\\Exception' : 'PHPUnit_Framework_Constraint_Exception';
$this->assertThat(null, new $constraintClass($class));
}
$expected = trim($match[3], "\n ");
if ($expected !== $output) {
printf("Compiled templates that failed on case %d:\n", $i + 1);
foreach (array_keys($templates) as $name) {
echo "Template: {$name}\n";
echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()
->getSourceContext($name))));
}
}
$this->assertEquals($expected, $output, $message . ' (in ' . $file . ')');
}
}