Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

How to mock custom service class injected to a controller #33

@expondo

Description

@expondo

Hello,

I have some class called InvoiceDownloadService. This class is passed to a controller and injected automatically by laravel.
I prepared fake class for dusk test like below:

    $this->browse(function (Browser $browser) {
        $browser->registerFake(InvoiceDownloadService::class, InvoiceDownloadServiceFake::class);
        $browser->mock(InvoiceDownloadService::class);
        ....
    });

but it results with error:
ERROR: Call to undefined method InvoiceDownloadService::swap() {"exception":"[object] (Error(code: 0): Call to undefined method InvoiceDownloadService::swap() at vendor/noeldemartin/laravel-dusk-mocking/src/Driver.php:77)

As i'm understand you comment here #31 (comment) it should just works. But it don't.

It is possible or not? Or your comment are for serviceProviders who extends ServiceProvider (Laravel) only?

Regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions