wevian's avatar

Problem with multiples Event::Fake calls

Hi Everyone.

I have application in Laravel 9 and I'm working on migration to Laravel 10.

I have in my abstract setUp class Event::fake[EventA::class]. In my child class, I have Event::fake[EventB::class].

With my current version of Laravel, everything works. But after upgrade to Laravel 10, EventB is faked but not EventA.

Has anyone ever had issue with Event::Fake when there's multiple ones ?

Thanks

0 likes
2 replies
kevinbui's avatar

I have just finished reading the source code for the Illuminate\Support\Facades\Event::fake() method, and that is about right. You cannot do that anymore.

I would do something like this:


namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
Illuminate\Support\Facades\Event;

class TestCase extends BaseTestCase
{
    protected $defaultEventsToFake = [EventA::class];

    protected function fakeEvents(array $eventsToFake = [])
    {
        Event::fake(
            array_merge($this->defaultEventsToFake, $eventsToFake)
        );
    }
}
1 like
wevian's avatar

All right, I thought there was an another "native" solution. Thanks for your time !

Please or to participate in this conversation.