90 if (!preg_match(
'/\.test$/', $file)) {
94 if ($legacyTests xor
false !== strpos($file->getRealpath(),
'.legacy.test')) {
98 $test = file_get_contents($file->getRealpath());
100 if (preg_match(
'/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx',
$test, $match)) {
102 $condition = $match[2];
103 $templates = self::parseTemplates($match[3]);
104 $exception = $match[5];
105 $outputs = array(array(null, $match[4], null,
''));
106 } elseif (preg_match(
'/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s',
$test, $match)) {
108 $condition = $match[2];
109 $templates = self::parseTemplates($match[3]);
111 preg_match_all(
'/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s',
$test, $outputs, PREG_SET_ORDER);
116 $tests[] = array(str_replace($fixturesDir.
'/',
'', $file),
$message, $condition, $templates, $exception, $outputs);
119 if ($legacyTests && empty(
$tests)) {
121 return array(array(
'not',
'-',
'', array(),
'', array()));
129 return $this->
getTests(
'testLegacyIntegration',
true);
135 $this->markTestSkipped(
'no legacy tests to run');
139 eval(
'$ret = '.$condition.
';');
141 $this->markTestSkipped($condition);
147 foreach ($outputs as
$i => $match) {
150 'strict_variables' =>
true,
151 ), $match[2] ? eval($match[2].
';') : array());
153 $twig->addGlobal(
'global',
'global');
155 $twig->addRuntimeLoader($runtimeLoader);
159 $twig->addExtension($extension);
163 $twig->addFilter($filter);
167 $twig->addTest($test);
171 $twig->addFunction($function);
176 if (PHP_VERSION_ID >= 50300) {
177 $p =
new ReflectionProperty($twig,
'templateClassPrefix');
178 $p->setAccessible(
true);
179 $p->setValue($twig,
'__TwigTemplate_'.
hash(
'sha256', uniqid(mt_rand(),
true),
false).
'_');
183 $template = $twig->loadTemplate(
'index.twig');
185 if (
false !== $exception) {
187 $this->assertSame(trim($exception), trim(sprintf(
'%s: %s', get_class($e),
$message)));
189 $this->assertTrue(
'.' === $last ||
'?' === $last,
$message,
'Exception message must end with a dot or a question mark.');
194 throw new Twig_Error(sprintf(
'%s: %s', get_class($e), $e->getMessage()), -1, $file, $e);
200 if (
false !== $exception) {
201 $this->assertSame(trim($exception), trim(sprintf(
'%s: %s', get_class($e), $e->getMessage())));
206 $e =
new Twig_Error(sprintf(
'%s: %s', get_class($e), $e->getMessage()), -1, $file, $e);
208 $output = trim(sprintf(
'%s: %s', get_class($e), $e->getMessage()));
211 if (
false !== $exception) {
212 list($class) = explode(
':', $exception);
213 $constraintClass = class_exists(
'PHPUnit\Framework\Constraint\Exception') ?
'PHPUnit\Framework\Constraint\Exception' :
'PHPUnit_Framework_Constraint_Exception';
214 $this->assertThat(null,
new $constraintClass($class));
217 $expected = trim($match[3],
"\n ");
220 printf(
"Compiled templates that failed on case %d:\n",
$i + 1);
222 foreach (array_keys($templates) as
$name) {
223 echo "Template: $name\n";
224 $loader = $twig->getLoader();
228 $source = $loader->getSourceContext($name);
230 echo $twig->compile($twig->parse($twig->tokenize(
$source)));
239 $templates = array();
240 preg_match_all(
'/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s',
$test, $matches, PREG_SET_ORDER);
241 foreach ($matches as $match) {
242 $templates[($match[1] ? $match[1] :
'index.twig')] = $match[2];
249 class_alias(
'Twig_Test_IntegrationTestCase',
'Twig\Test\IntegrationTestCase',
false);
static parseTemplates($test)
testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs)
getLegacyTests legacy
testIntegration($file, $message, $condition, $templates, $exception, $outputs)
getTests
catch(Exception $e) $message
Adds a getSourceContext() method for loaders.
doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs)
Holds information about a non-compiled Twig template.
Stores the Twig configuration.
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Loads a template from an array.
getTests($name, $legacyTests=false)