Fix: trait-only file-level binding no longer discards the directory binding - #10
Merged
MrPunyapal merged 1 commit intoAug 8, 2026
Conversation
Contributor
Author
|
Sorry, I didn’t notice this. It is probably a duplicate of #8. I’ll leave it up to the maintainer to decide which solution to choose. |
Collaborator
|
@webard have you tried latest 👀 |
Contributor
Author
|
Yes, I’m on the latest version. Actually, 5.0.1 (latest) introduces this problem, because it adds this file: PestTestCaseType.php |
MrPunyapal
approved these changes
Aug 8, 2026
Collaborator
|
Thanks 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a test file declares a binding of its own that names only a trait (
uses(SomeTrait::class)orpest()->use(SomeTrait::class)),PestTestCaseType::resolve()drops the test case class bound to that file's directory inPest.phpand falls back toPHPUnit\Framework\TestCase.Every method that exists only on the real base class — in Laravel that is
artisan(),get(),travelTo(),withoutExceptionHandling(),mock()— is then reported as undefined, and every method that also exists onPHPUnit\Framework\TestCaseis silently checked against the wrong class.Reproduction
tests/Pest.php:tests/Feature/ExampleTest.php:Expected:
MyTestCaseActual:
PHPUnit\Framework\TestCaseRemoving the
uses(SomeTrait::class)line makes the type correct again.Cause
src/Type/Pest/PestTestCaseType.php:File-level bindings replace directory-level bindings. A trait-only binding is non-empty, so the directory bindings are never read;
$classNamesends up empty and the fallback assignsPHPUnit\Framework\TestCase.Impact
The failure is quiet.
PHPUnit\Framework\TestCasecarries everyassert*method andexpect()is a global function, so most test files analyse identically under either type and report nothing. The downgrade only surfaces where a file happens to call a method exclusive to the bound base class.