Skip to content

Add new HasTrait/NotHasTrait Rules #424

Open
@borisson

Description

@borisson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions