12use PHPUnit\Framework\TestCase;
 
   89        foreach (
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
 
   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];
 
  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];
 
  111                preg_match_all(
'/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', 
$test, $outputs, PREG_SET_ORDER);
 
  113                throw new InvalidArgumentException(sprintf(
'Test "%s" is not valid.', str_replace($fixturesDir.
'/', 
'', $file)));
 
  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');
 
  184            } 
catch (Exception $e) {
 
  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);
 
  199            } 
catch (Exception $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();
 
  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];
 
  249class_alias(
'Twig_Test_IntegrationTestCase', 
'Twig\Test\IntegrationTestCase', 
false);
 
An exception for terminatinating execution or to throw for unit testing.
Stores the Twig configuration.
Loads a template from an array.
Holds information about a non-compiled Twig template.
testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs)
@dataProvider getLegacyTests @group legacy
testIntegration($file, $message, $condition, $templates, $exception, $outputs)
@dataProvider getTests
getTests($name, $legacyTests=false)
static parseTemplates($test)
doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs)
Adds a getSourceContext() method for loaders.
catch(Exception $e) $message
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.