You are here

public function Twig_Test_IntegrationTestCase::getTests in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Test/IntegrationTestCase.php \Twig_Test_IntegrationTestCase::getTests()

File

vendor/Twig/Test/IntegrationTestCase.php, line 31

Class

Twig_Test_IntegrationTestCase
Integration test helper

Code

public function getTests() {
  $fixturesDir = realpath($this
    ->getFixturesDir());
  $tests = array();
  foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
    if (!preg_match('/\\.test$/', $file)) {
      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 = $this
        ->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 = $this
        ->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,
    );
  }
  return $tests;
}