laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

IDE support for test fakes #1679

Open brendt opened 5 years ago

brendt commented 5 years ago

It would be possible to add IDE support for test fake methods by adding a mixin docblock to the original facades like this:

/**
 * …
 * @mixin \Illuminate\Support\Testing\Fakes\EventFake
 */
class Event extends Facade

This would allow autocompletion on fake methods. Would you be open for a PR that adds this on fakeable facades?

timacdonald commented 5 years ago

The Mail facade already has a bunch of stuff to make this possible. Looks like it might just take someone to go through and standardise it across all the Facades.

https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Facades/Mail.php

brendt commented 5 years ago

Would @mixin be preferred? This allows the Fakes to change their method signatures without having to update the Facade's docblocks.

timacdonald commented 5 years ago

I would think so. But I also wonder if, because the methods aren't available until your call the Event::fake(), if it would be better to ensure they all return the fake class and do...

$eventFake = Event::fake();

$eventFake->assertWhatever(...);

But that doesn't feel as nice as being able to continue to use the Facade.