Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new HasTrait/NotHasTrait Rules #424

Open
borisson opened this issue Mar 21, 2024 · 0 comments
Open

Add new HasTrait/NotHasTrait Rules #424

borisson opened this issue Mar 21, 2024 · 0 comments

Comments

@borisson
Copy link

Feature Request

I would like to be able to ensure that all our tests use the DatabaseTransactions trait in Laravel and that we are not using RefreshDatabase.

Q A
New Feature yes
RFC yes/no
BC Break no

Summary

$rules[] = Rule::allClasses()
    ->that(new ResideInOneOfTheseNamespaces('Tests\Feature'))
    ->should(new HaveTrait(DatabaseTransactions::class))
    ->because('We want all Feature tests to run transactions');

$rules[] = Rule::allClasses()
    ->that(new ResideInOneOfTheseNamespaces('Tests\Feature'))
    ->should(new NotHaveTrait(RefreshDatabase::class))
    ->because('We want all Feature tests to never refresh the database for performance reasons');

This should all us to be strict about the type of traits that are implemented.
I think we could also use this to enforce uuids on class (by adding HaveTrait(HasUuid::class) as a rule.

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

No branches or pull requests

1 participant