You are here

public function Twig_Test_IntegrationTestCase::getTests in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/twig/twig/lib/Twig/Test/IntegrationTestCase.php \Twig_Test_IntegrationTestCase::getTests()
2 calls to Twig_Test_IntegrationTestCase::getTests()
Twig_Tests_LegacyIntegrationTest::getTests in vendor/twig/twig/test/Twig/Tests/LegacyIntegrationTest.php
Twig_Test_IntegrationTestCase::getLegacyTests in vendor/twig/twig/lib/Twig/Test/IntegrationTestCase.php
1 method overrides Twig_Test_IntegrationTestCase::getTests()
Twig_Tests_LegacyIntegrationTest::getTests in vendor/twig/twig/test/Twig/Tests/LegacyIntegrationTest.php

File

vendor/twig/twig/lib/Twig/Test/IntegrationTestCase.php, line 74

Class

Twig_Test_IntegrationTestCase
Integration test helper.

Code

public function getTests($name, $legacyTests = false) {
  $fixturesDir = realpath($this
    ->getFixturesDir());
  $tests = array();
  foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
    if (!preg_match('/\\.test$/', $file)) {
      continue;
    }
    if ($legacyTests xor false !== strpos($file
      ->getRealpath(), '.legacy.test')) {
      continue;
    }
    $test = file_get_contents($file
      ->getRealpath());
    if (preg_match('/--TEST--\\s*(.*?)\\s*(?:--CONDITION--\\s*(.*))?\\s*((?:--TEMPLATE(?:\\(.*?\\))?--(?:.*?))+)\\s*(?:--DATA--\\s*(.*))?\\s*--EXCEPTION--\\s*(.*)/sx', $test, $match)) {
      $message = $match[1];
      $condition = $match[2];
      $templates = self::parseTemplates($match[3]);
      $exception = $match[5];
      $outputs = array(
        array(
          null,
          $match[4],
          null,
          '',
        ),
      );
    }
    elseif (preg_match('/--TEST--\\s*(.*?)\\s*(?:--CONDITION--\\s*(.*))?\\s*((?:--TEMPLATE(?:\\(.*?\\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) {
      $message = $match[1];
      $condition = $match[2];
      $templates = self::parseTemplates($match[3]);
      $exception = false;
      preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\\-\\-DATA\\-\\-|$)/s', $test, $outputs, PREG_SET_ORDER);
    }
    else {
      throw new InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir . '/', '', $file)));
    }
    $tests[] = array(
      str_replace($fixturesDir . '/', '', $file),
      $message,
      $condition,
      $templates,
      $exception,
      $outputs,
    );
  }
  if ($legacyTests && empty($tests)) {

    // add a dummy test to avoid a PHPUnit message
    return array(
      array(
        'not',
        '-',
        '',
        array(),
        '',
        array(),
      ),
    );
  }
  return $tests;
}