Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. IntegrationTestCase.php

function IntegrationTestCase::getTests

@final since Twig 3.13

1 call to IntegrationTestCase::getTests()
IntegrationTestCase::getLegacyTests in vendor/twig/twig/src/Test/IntegrationTestCase.php
@final since Twig 3.13

File

vendor/twig/twig/src/Test/IntegrationTestCase.php, line 108

Class

IntegrationTestCase
Integration test helper.

Namespace

Twig\Test

Code

public function getTests($name, $legacyTests = false) {
    try {
        $fixturesDir = static::getFixturesDirectory();
    } catch (\BadMethodCallException) {
        trigger_deprecation('twig/twig', '3.13', 'Not overriding "%s::getFixturesDirectory()" in "%s" is deprecated. This method will be abstract in 4.0.', self::class, static::class);
        $fixturesDir = $this->getFixturesDir();
    }
    $fixturesDir = realpath($fixturesDir);
    $tests = [];
    foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
        if (!preg_match('/\\.test$/', $file)) {
            continue;
        }
        if ($legacyTests xor str_contains($file->getRealpath(), '.legacy.test')) {
            continue;
        }
        $test = file_get_contents($file->getRealpath());
        if (preg_match('/--TEST--\\s*(.*?)\\s*(?:--CONDITION--\\s*(.*))?\\s*(?:--DEPRECATION--\\s*(.*?))?\\s*((?:--TEMPLATE(?:\\(.*?\\))?--(?:.*?))+)\\s*(?:--DATA--\\s*(.*))?\\s*--EXCEPTION--\\s*(.*)/sx', $test, $match)) {
            $message = $match[1];
            $condition = $match[2];
            $deprecation = $match[3];
            $templates = self::parseTemplates($match[4]);
            $exception = $match[6];
            $outputs = [
                [
                    null,
                    $match[5],
                    null,
                    '',
                ],
            ];
        }
        elseif (preg_match('/--TEST--\\s*(.*?)\\s*(?:--CONDITION--\\s*(.*))?\\s*(?:--DEPRECATION--\\s*(.*?))?\\s*((?:--TEMPLATE(?:\\(.*?\\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) {
            $message = $match[1];
            $condition = $match[2];
            $deprecation = $match[3];
            $templates = self::parseTemplates($match[4]);
            $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[str_replace($fixturesDir . '/', '', $file)] = [
            str_replace($fixturesDir . '/', '', $file),
            $message,
            $condition,
            $templates,
            $exception,
            $outputs,
            $deprecation,
        ];
    }
    if ($legacyTests && !$tests) {
        // add a dummy test to avoid a PHPUnit message
        return [
            [
                'not',
                '-',
                '',
                [],
                '',
                [],
            ],
        ];
    }
    return $tests;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal