You are here

protected function BrowserHtmlDebugTrait::getTestMethodCaller in Drupal 8

Same name and namespace in other branches
  1. 9 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 208

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'] === get_class($this)) {
      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;
}