pest icon indicating copy to clipboard operation
pest copied to clipboard

[Feature] Architecture toUseTrait()

Open etlam opened this issue 1 year ago • 4 comments

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.

etlam avatar Jan 31 '24 23:01 etlam

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

EPGDigital-MW avatar Feb 09 '24 09:02 EPGDigital-MW

Why not just use toUse()?

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

JonPurvis avatar Feb 15 '24 23:02 JonPurvis

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.

EPGDigital-MW avatar Feb 19 '24 08:02 EPGDigital-MW

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.

JonPurvis avatar Feb 20 '24 22:02 JonPurvis

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);

etlam avatar Apr 11 '24 09:04 etlam