pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.48k stars 343 forks source link

[Feature] Architecture toUseTrait() #1084

Closed etlam closed 5 months ago

etlam commented 8 months ago

We try to write tests to ensure our internal coding guidelines are followed. For example, we would like to ensure that a given trait is not used in some namespaces:

test('Ensure actions do not implement the AsAction trait')
    ->expect('App\Actions')
    ->classes()
    ->not
    ->totUseTrait(\Lorisleiva\Actions\Concerns\AsAction::class);

Would this be nice? Please share your thoughts, so we may create a pull request with our implementation.

EPGDigital-MW commented 7 months ago

I'm trying to implement something similar at the moment, checking uuid's are used on models, so looking for HasUuids trait

JonPurvis commented 7 months ago

Why not just use toUse()?

@EPGDigital-MW you can also just use toUse() for that

EPGDigital-MW commented 7 months ago

I'm sure I tried toUse and it didn't work, but I've just tried again and it's working no idea why it didn't work first time ;)

I think toUseTrait would be useful still as provides clarity on what you are testing.

JonPurvis commented 7 months ago

I'm pretty sure there's a PR to add that as an Expectation but it was closed and the solution was to just use toUse(). You can try again but no promises it'll be accepted.

etlam commented 5 months ago

Yes, the pull request was closed: https://github.com/pestphp/pest/pull/960 So I will use toUse():

test('Ensure actions do not implement the all in one AsAction trait.')
    ->expect('App\Actions')
    ->not
    ->toUse(\Lorisleiva\Actions\Concerns\AsAction::class);