function BrowserHtmlDebugTrait::getTestMethodCaller

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php \Drupal\Tests\BrowserHtmlDebugTrait::getTestMethodCaller()
  2. 10 core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php \Drupal\Tests\BrowserHtmlDebugTrait::getTestMethodCaller()
  3. 11.x core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php \Drupal\Tests\BrowserHtmlDebugTrait::getTestMethodCaller()

Retrieves the current calling line in the class under test.

Return value

array An associative array with keys 'file', 'line' and 'function'.

1 call to BrowserHtmlDebugTrait::getTestMethodCaller()
BrowserHtmlDebugTrait::getResponseLogHandler in core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php
Provides a Guzzle middleware handler to log every response received.
1 method overrides BrowserHtmlDebugTrait::getTestMethodCaller()
BrowserTestBase::getTestMethodCaller in core/tests/Drupal/Tests/BrowserTestBase.php
Retrieves the current calling line in the class under test.

File

core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php, line 217

Class

BrowserHtmlDebugTrait
Provides the debug functions for browser tests.

Namespace

Drupal\Tests

Code

protected function getTestMethodCaller() {
    $backtrace = debug_backtrace();
    // Find the test class that has the test method.
    while ($caller = Error::getLastCaller($backtrace)) {
        if (isset($caller['class']) && $caller['class'] === static::class) {
            break;
        }
        // If the test method is implemented by a test class's parent then the
        // class name of $this will not be part of the backtrace.
        // In that case we process the backtrace until the caller is not a
        // subclass of $this and return the previous caller.
        if (isset($last_caller) && (!isset($caller['class']) || !is_subclass_of($this, $caller['class']))) {
            // Return the last caller since that has to be the test class.
            $caller = $last_caller;
            break;
        }
        // Otherwise we have not reached our test class yet: save the last caller
        // and remove an element from to backtrace to process the next call.
        $last_caller = $caller;
        array_shift($backtrace);
    }
    return $caller;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.