0

I wanted in my laravel app in some job to run three jobs one by one, so I used Bus:chain like in code below

        Bus::chain([
            new CarJob(
                $this->carService,
                $this->userRepository,
                $this->carModel
            ),
            new UserJob(
                $userModel,
                $this->userService
            ),
            new CarJob(
                $this->carModel,
                $userModel
            ),
        ])->dispatch();

All logics work fine but when I want to create unit test in phpunit for it I have error. I have used Bus::fake(), mock all reporitories and services and create objects in memory using ->make() factory function.

Error says Exception: Serialization of 'ReflectionClass' is not allowed and is placed in ->dispatch() function.

Below is error path track

        \app\vendor\laravel\framework\src\Illuminate\Bus\Queueable.php:215
        \app\vendor\laravel\framework\src\Illuminate\Bus\Queueable.php:189
        \app\vendor\laravel\framework\src\Illuminate\Collections\Collection.php:642
        \app\vendor\laravel\framework\src\Illuminate\Bus\Queueable.php:190
        \app\vendor\laravel\framework\src\Illuminate\Support\Testing\Fake\PendingChainFake.php:50

More over when I remove second job UserJob the test works. What I do wrong?

Isild
  • 107
  • 1
  • 11

0 Answers0