Unable to mock database calls

Vitan Ivanov posted 9 months ago

Hello guys,

I am trying to mock the Eloquent Builder calls to the database:

        $user = new User();
        $user->id = 3;
        $collection = new Collection();

        $mockedBuilder = Mockery::mock(Builder::class);
        App::instance(Builder::class, $mockedBuilder);
        $userAfterMocking = User::where('id',5)->first();

The problem is, instead of calling the mocked builder, the test actually queries the database. Any ideas?

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us