Replies: 1 comment 3 replies
-
After some Tinkering I solved this by using namespaces to prevent name conflicts. I just include the filename in the namespace declaration to "trick" the autoloading. <?php
// tests/Feature/PostTest.php
namespace Tests\Feature\PostTest;
function createUser()
{
// ...
}
it('can create a Post', function() {
// ...
}); <?php
// tests/Feature/CommentTest.php
namespace Tests\Feature\CommentTest;
function createUser()
{
// ...
}
it('can create a Comment', function() {
// ...
}); As there are no classes within these files, I think this is OK and does not hurt the PSR-4 rule. What do you guys think? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi guys
In complex test scenarios I'd like to have small helper methods like before having private methods in PHPUnit test classes.
This works fine, as long these functions do not have the same name.
Is there any way having a
createUser()
method in more than one Pest test file?Otherwise, how could I achieve this similarly?
Here is an example of what I mean (I'm aware that this is a use case where we can use Factories, but there may be other and different things per test file I'd like to do in
createUser
method)Help appreciated 🙏
Beta Was this translation helpful? Give feedback.
All reactions