Skip to content

fix: skip the frames of Pest by its own directory, not by the name of the checkout - #1913

Open
jfatr wants to merge 2 commits into
pestphp:5.xfrom
jfatr:fix/backtrace-checkout-directory
Open

jfatr wants to merge 2 commits into
pestphp:5.xfrom
jfatr:fix/backtrace-checkout-directory

Conversation

@jfatr

@jfatr jfatr commented Sep 15, 2026

Copy link
Copy Markdown

What happens

Backtrace::backtrace() decides which frames belong to Pest itself by looking for a substring in the path of each frame: pest/src when Pest runs its own test suite, and /pestphp/pest/src when it runs from vendor.

Clone this repository into a directory with any other name, pest5 for example, and run the unit suite:

FAILED  Tests\Unit\Support\Backtrace > it gets file name from called file
Failed asserting that two strings are identical.
-'/home/you/pest5/tests/Unit/Support/Backtrace.php'
+'/home/you/pest5/src/Support/Backtrace.php'

The path pest5/src/Support/Backtrace.php does not contain pest/src, so the first frame is not skipped and Backtrace::file() returns its own file instead of the file of the caller. The same happens for any checkout name, a fork, a worktree, or a CI job that clones into a directory named after the branch.

The fix

Compare each frame against the directory that holds Backtrace.php instead of a name:

if (str_starts_with($trace['file'], dirname(__DIR__).DIRECTORY_SEPARATOR)) {
    continue;
}

dirname(__DIR__) is the src directory of Pest in every layout: the checkout of this repository, whatever it is called, and vendor/pestphp/pest/src in a project that installs Pest. One check replaces the two substring checks.

$GLOBALS['__PEST_INTERNAL_TEST_SUITE'] existed to enable the first substring check during the internal suite. Nothing reads it now, so tests/Pest.php no longer sets it.

Verification

  • tests/Unit/Support/Backtrace.php passes from a checkout named pest5.
  • pest --exclude-group=integration: 1582 passed, 0 failed.
  • rector, pint, phpstan and type coverage at 100 % pass.

🤖 Generated with Claude Code

jfatr and others added 2 commits September 15, 2026 14:08
… the checkout

`Backtrace::backtrace()` skipped a frame when its path held `pest/src`, so
a checkout of this repository in a directory with any other name, such as
`pest5`, returned `src/Support/Backtrace.php` as the file of the caller and
`tests/Unit/Support/Backtrace.php` failed. The frame check now compares
against the directory that holds this file, which is the same directory
whether Pest runs from its own checkout or from `vendor/pestphp/pest`, and
the global that marked the internal test suite has no reader left.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant