Using Laravel helpers in package

367 Views Asked by At

I'm trying to write tests for my laravel package and it depends on Laravel helper dispatch. But package itself don't contains this function.
So I have an error when run tests

Is there a solution for this case? Or should I use DI and inject Illuminate\Contracts\Bus\Dispatcher instead of using a helper?

1

There are 1 best solutions below

1
On

Laravel Testing Helper for Packages Development: https://github.com/orchestral/testbench

Package allows to run tests in laravel-like environment. You can use database, facades, helpers etc.

When writing a Laravel application, it generally does not matter if you use contracts or facades since both provide essentially equal levels of testability. However, when writing packages, your package will not typically have access to all of Laravel's testing helpers. If you would like to be able to write your package tests as if they existed inside a typical Laravel application, you may use the Orchestral Testbench package.

Here is example of real usage: https://github.com/Maatwebsite/Laravel-Excel