3

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?

Tridev Shrestha
  • 447
  • 7
  • 21
  • Can you explain that further? If you depend on a method in a helper package, but that helper packages does not contain that method, where does it come from? – Nico Haase Feb 27 '19 at 08:43
  • [Here](https://github.com/laravel/framework/blob/e6c8aa0e39d8f91068ad1c299546536e9f25ef63/src/Illuminate/Foundation/helpers.php#L386) is helper function And it often used outside of laravel https://github.com/laravel/scout/blob/484ff556fe2def2eab9f8eb2e60becba36c439d9/src/Searchable.php#L66 Some people overide it in test https://github.com/laravel/scout/blob/484ff556fe2def2eab9f8eb2e60becba36c439d9/tests/SearchableTest.php#L81 –  Feb 27 '19 at 09:24
  • And how **exactly** does your code look like? Please share some example and the **exact** error message – Nico Haase Feb 27 '19 at 09:27
  • My code just call dispatch helper like [this](https://github.com/laravel/scout/blob/484ff556fe2def2eab9f8eb2e60becba36c439d9/src/Searchable.php#L66) Error is `function dispatch not found` –  Feb 27 '19 at 09:33
  • And how do you import these Laravel helpers in your project? – Nico Haase Feb 27 '19 at 09:41

1 Answers1

-2

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

Sanasol
  • 892
  • 8
  • 24