Skip to content
Snippets Groups Projects
Commit d498a392 authored by catch's avatar catch
Browse files

Issue #2822387 by jhedstrom, Wim Leers, klausi: Undefined offset 1 in...

Issue #2822387 by jhedstrom, Wim Leers, klausi: Undefined offset 1 in BrowserTestBase::getMethodCaller()
parent 44227b16
No related branches found
No related tags found
No related merge requests found
<?php
namespace Drupal\FunctionalTests;
use Drupal\Tests\BrowserTestBase;
/**
* Test for BrowserTestBase::getTestMethodCaller() in child classes.
*
* @group browsertestbase
*/
class GetTestMethodCallerExtendsTest extends GetTestMethodCallerTest {
/**
* A test method that is not present in the parent class.
*/
public function testGetTestMethodCallerChildClass() {
$method_caller = $this->getTestMethodCaller();
$expected = [
'file' => __FILE__,
'line' => 18,
'function' => __CLASS__ . '->' . __FUNCTION__ . '()',
'class' => BrowserTestBase::class,
'object' => $this,
'type' => '->',
'args' => [],
];
$this->assertEquals($expected, $method_caller);
}
}
<?php
namespace Drupal\FunctionalTests;
use Drupal\Tests\BrowserTestBase;
/**
* Explicit test for BrowserTestBase::getTestMethodCaller().
*
* @group browsertestbase
*/
class GetTestMethodCallerTest extends BrowserTestBase {
/**
* Tests BrowserTestBase::getTestMethodCaller().
*/
function testGetTestMethodCaller() {
$method_caller = $this->getTestMethodCaller();
$expected = [
'file' => __FILE__,
'line' => 18,
'function' => __CLASS__ . '->' . __FUNCTION__ . '()',
'class' => BrowserTestBase::class,
'object' => $this,
'type' => '->',
'args' => [],
];
$this->assertEquals($expected, $method_caller);
}
}
......@@ -1845,16 +1845,27 @@ protected function getConfigSchemaExclusions() {
*/
protected function getTestMethodCaller() {
$backtrace = debug_backtrace();
// Remove all calls until we reach the current test class.
while (($caller = $backtrace[1]) &&
(!isset($caller['class']) || $caller['class'] !== get_class($this))
) {
// We remove that call.
// 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 Error::getLastCaller($backtrace);
return $caller;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment