/** * work out who has called a piece of code * * @param array $backtrace * the debug_backtrace() return value * @param array $filterList * a list of namespaces and classes to skip over * @return StackFrame */ function get_caller_from_trace(array $backtrace, array $filterList = []) { return GetCaller::from($backtrace, $filterList); }
/** * @covers ::from */ public function testReturnsFirstStackFrameWhenEverythingElseFilteredOut() { // ---------------------------------------------------------------- // setup your test $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $partials = [__CLASS__, 'ReflectionMethod', 'PHPUnit_Framework_TestCase', 'PHPUnit_Framework_TestResult', 'PHPUnit_Framework_TestSuite', 'PHPUnit_TextUI_TestRunner', 'PHPUnit_TextUI_Command']; $expectedClass = 'ReflectionMethod'; $expectedMethod = 'invokeArgs'; // ---------------------------------------------------------------- // perform the change $result = GetCaller::from($backtrace, $partials); // ---------------------------------------------------------------- // test the results $this->assertInstanceOf(StackFrame::class, $result); $this->assertEquals($expectedClass, $result->getClass()); $this->assertEquals($expectedMethod, $result->getMethod()); }