Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[FrameworkBundle] Move test cases into reusable traits for ease of supporting other testing frameworks#60612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
* | ||
* @see https://laravel.com/docs/5.7/dusk#available-assertions | ||
*/ | ||
trait BrowserKitAssertionsTrait |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I do not understand why we need to introduce new traits that look basically the same as the ones that are deprecated here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
They are the same files but renamed with a new namespace.
The goal is to make test cases more compositable (Pest, for example, does not need the assertion methods), while maintaining full backwards compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Moving the traits is a no go from my side as that puts a lot of burden on application developers without providing any benefits if I don’t miss anything substantial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can you give an example of the burden?
AsKernelTestCase
andWebTestCase
"contracts" to the end users remain unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Everyone using the traits themselves would have to update their code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Everyone using the traits themselves would have to update their code.
The orignal traits still exist and work though? They would only be removed in version 8.0, at the earliest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Sure, we don’t introduce such BC breaks in minor versions. But at some point this would still require update work and I fail to see the benefit apart from removing traits just for the sake of it.
Note that I am not against introducing new traits or adding new methods in traits if that improves reusability though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
OK, would you accept the following then:
- No "Traits" namespace.
- Keep all existing traits and ensure BC.
- Create in the base folder the following new traits:
- BrowserKitTrait
- DomCrawlerTrait
- HttpClientTrait
- MailerTrait
- NotifierTrait
- WebTrait
- KernelTrait
These new files would contain only the helper the methods like "getClientRequest".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The goal would be that someone not using PHPUnit would use one of the new trait and their helper methods but would never use the assertions? If that's the case, I would be 👎 on making any change at all. I have checked a few of those helper methods and none of them do not look complex enough for me to justify introducing new traits (that could potentially lead to confusion). For example, there's nothing wrong IMO in having to writeself::getClient()->getCrawler()
instead ofself::getCrawler()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I share@xabbuh's concerns and recommendation.
If you wanna give your proposal more time, the direction you're drawing could work. Not annoying ppl using phpunit with needless deprecations is a must to me also. Then, about the new helpers, that's yours to convince us :)
bac07f8
tof61fbcc
CompareLet me close this PR. Of course a new one with another approach is always possible. |
Makes sense. I'll rethink and come back with a much smaller change. Thanks for looking at this PR. |
codetetic commentedJun 3, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
For more context: The problem I'm trying to solve is reconciling Symfony's subject-less based assertions:
With Pest's subject-based assertions:
Ideally, both projects should be able to share test helpers and constraints. Pest is able to do this as it is built on top of PHPUnit. The goal of my project, then is to be a very small compatibility layer. As an example of PHPUnit:
Pest:
The
So I'll continue with the pure Pest and Symfony style and maybe use reflection or remove the midway style:
|
With the Pest style, I would implement it as But the |
Changes:
AbstractBrowser
for the$client
attribute inWebTestCase
.The above will allow:
For more examples:https://github.com/codetetic/pest-plugin-symfony.
Upgrade notes (for the *-7.4.md files):