laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.48k stars 419 forks source link

dispatch helper function error within unit test #959

Closed carbontwelve closed 5 years ago

carbontwelve commented 5 years ago

Description:

When using the dispatch($job) helper function (source) I get the following error: PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Bus\Dispatcher] is not instantiable. in ... I have included the releveant call stack below:

Call Stack:
    0.0004     402984   1. {main}() C:\Users\User\PhpstormProjects\deploy\vendor\phpunit\phpunit\phpunit:0
    0.0231    2272856   2. PHPUnit\TextUI\Command::main() C:\Users\User\PhpstormProjects\deploy\vendor\phpunit\phpunit\phpunit:61
    0.0231    2272968   3. PHPUnit\TextUI\Command->run() C:\Users\User\PhpstormProjects\deploy\vendor\phpunit\phpunit\src\TextUI\Command.php:162
    0.0905    6816520   4. PHPUnit\TextUI\TestRunner->doRun() C:\Users\User\PhpstormProjects\deploy\vendor\phpunit\phpunit\src\TextUI\Command.php:206

Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Bus\Dispatcher] is not instantiable. in C:\Users\User\PhpstormProjects\deploy\vendor\illuminate\container\Container.php on line 960

Steps To Reproduce:

Use the dispatch($job) helper function and have PHPUnit 8 run the code via unit test. This may actually fail outside of PHPUnit but I haven't tested that yet. What seems to work is replacing it with app('Illuminate\Contracts\Bus\Dispatcher')->dispatch($job) which I obtained from the Lumen controller helper trait here.

driesvints commented 5 years ago

Heya, this works for me on my local lumen install with the version you mentioned above.

Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to report back and I'll gladly help you out and re-open this issue.

Thanks!