Skip to content

Tests: Add coverage for _wp_rest_get_debug_backtrace_caller(). - #1

Merged
ilclaudio merged 1 commit into
ilclaudio:fix/64260-rest-doing-it-wrong-logfrom
rvpatel:64260-rest-backtrace-caller-tests
Oct 19, 2026
Merged

ilclaudio merged 1 commit into
ilclaudio:fix/64260-rest-doing-it-wrong-logfrom
rvpatel:64260-rest-backtrace-caller-tests

Conversation

@rvpatel

@rvpatel rvpatel commented Oct 19, 2026

Copy link
Copy Markdown

Hi @ilclaudio! This adds PHPUnit coverage for the new _wp_rest_get_debug_backtrace_caller() helper in your PR WordPress#10537, so it can be merged straight into your branch. It only adds one test file and does not change your code.

Trac ticket: https://core.trac.wordpress.org/ticket/64260

What is covered

tests/phpunit/tests/rest-api/wpRestGetDebugBacktraceCaller.php, 8 tests:

  • A call from a named function reports called from func() in /path on line N.
  • Instance and static methods report Class->method() and Class::method().
  • A closure is reported as (anonymous function).
  • A call from a file's global scope reports only the location, not require/include.
  • The innermost frame inside WP_CONTENT_DIR is reported when several are.
  • A call from outside WP_CONTENT_DIR returns an empty string.
  • A sibling directory such as wp-content-backup is not treated as part of wp-content (the trailingslashit() fix from review).

Each test calls the helper from a fixture file written inside WP_CONTENT_DIR, the way a plugin would, and removes it afterwards.

Testing

npm run test:php -- tests/phpunit/tests/rest-api/wpRestGetDebugBacktraceCaller.php
  • All 8 tests pass on your branch (head 0f1ef94359). PHPCS is clean.
  • To check they catch regressions, I broke the helper four ways and the tests failed each time: removing trailingslashit(), the closure label, the include/require check, and the class prefix.
  • The restapi group has the same failures with and without this file, so it does not affect other tests.

The error_log() lines in the three handlers are not covered: the test suite does not define WP_DEBUG_LOG, so it is always false there and that path cannot be reached without a separate process.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Drafting the test cases and running the checks. I reviewed the tests and the results.

Covers the caller reported for a named function, an instance method, a static method, a closure, and a call from a file's global scope; that the innermost frame inside WP_CONTENT_DIR is used; that calls from outside WP_CONTENT_DIR report nothing; and that a sibling directory sharing the content directory's name prefix, such as wp-content-backup, is not treated as part of it.

Each test calls the function from a fixture file written inside WP_CONTENT_DIR, which is removed afterwards.

See #64260.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ravipatel.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ilclaudio
ilclaudio merged commit 20e8b97 into ilclaudio:fix/64260-rest-doing-it-wrong-log Oct 19, 2026
4 checks passed
@ilclaudio

Copy link
Copy Markdown
Owner

Merge done

ilclaudio pushed a commit that referenced this pull request Oct 19, 2026
…t is not set.

This resolves an error if `mysqli_num_fields()` is called before a successful SELECT-type query is performed:
{{{
mysqli_num_fields(): Argument #1 ($result) must be of type mysqli_result, false given
}}}

Developed in WordPress#13099.

Follow-up to r21472.

Props joehorntw, akshat2802, mukesh27, rejaulalomkhan, SergeyBiryukov.
Fixes #64130.

git-svn-id: https://develop.svn.wordpress.org/trunk@64458 602fd350-edb4-49c9-b593-d223f7449a82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants