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

Breadcrumb

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

function PhptTestCase::getLocationHint

1 call to PhptTestCase::getLocationHint()
PhptTestCase::getLocationHintFromDiff in vendor/phpunit/phpunit/src/Runner/PhptTestCase.php

File

vendor/phpunit/phpunit/src/Runner/PhptTestCase.php, line 743

Class

PhptTestCase
@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

Namespace

PHPUnit\Runner

Code

private function getLocationHint(string $needle, array $sections) : array {
    $needle = trim($needle);
    if (empty($needle)) {
        return [
            [
                'file' => realpath($this->filename),
                'line' => 1,
            ],
        ];
    }
    $search = [
        // 'FILE',
'EXPECT',
        'EXPECTF',
        'EXPECTREGEX',
    ];
    foreach ($search as $section) {
        if (!isset($sections[$section])) {
            continue;
        }
        if (isset($sections[$section . '_EXTERNAL'])) {
            $externalFile = trim($sections[$section . '_EXTERNAL']);
            return [
                [
                    'file' => realpath(dirname($this->filename) . DIRECTORY_SEPARATOR . $externalFile),
                    'line' => 1,
                ],
                [
                    'file' => realpath($this->filename),
                    'line' => ($sections[$section . '_EXTERNAL_offset'] ?? 0) + 1,
                ],
            ];
        }
        $sectionOffset = $sections[$section . '_offset'] ?? 0;
        $offset = $sectionOffset + 1;
        foreach (preg_split('/\\r\\n|\\r|\\n/', $sections[$section]) as $line) {
            if (str_contains($line, $needle)) {
                return [
                    [
                        'file' => realpath($this->filename),
                        'line' => $offset,
                    ],
                ];
            }
            $offset++;
        }
    }
    return [
        [
            'file' => realpath($this->filename),
            'line' => 1,
        ],
    ];
}
RSS feed
Powered by Drupal