Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] TypeError when using the Bus fake #34223

Closed
gbuckingham89 opened this issue Sep 9, 2020 · 0 comments
Closed

[8.x] TypeError when using the Bus fake #34223

gbuckingham89 opened this issue Sep 9, 2020 · 0 comments

Comments

@gbuckingham89
Copy link
Contributor

gbuckingham89 commented Sep 9, 2020

  • Laravel Version: 8.0.0
  • PHP Version: 7.4.5
  • Database Driver & Version: N/A

Description:

I'm seeing a TypeError when using the Bus fake in my tests (checking that a batch job has been dispatched):

TypeError: Argument 7 passed to Illuminate\Bus\Batch::__construct() must be of the type int, array given, called in /home/vagrant/sites/xxxx/vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/BatchRepositoryFake.php on line 56

The fake (Illuminate\Support\Testing\Fakes\BatchRepositoryFake) appears to passing an array, $batch->options as the 7th argument, where as the Illuminate\Bus\Batch class expects the 7th argument to be an integer, $failedJobs.

Steps To Reproduce:

  1. Dispatch a batchable job from somewhere (in my case, from an Artisan command):
public function handle()
{
	$batch = Bus::batch([
	    new MyJob($my_model)
	])->then(function(Batch $batch) use($my_model) {
	    // Do something
	})->catch(function(Batch $batch, Throwable $e) use($my_model) {
	    // Do something
	})->finally(function(Batch $batch) use($my_model) {
	    // Do something
	})->name('my-batch')->dispatch();
}
  1. Run a test that asserts using the Bus fake:
public function test_batch_dispatch()
{
    Bus::fake();

    //
    // Trigger dispatching of job (see above)
    //

    Bus::assertDispatched(MyJob::class, function(MyJob $job) use($my_model) {
	    return $job->my_model->id===$my_model->id;
	});
	Bus::assertDispatchedTimes(MyJob::class, 1);
}
@nunomaduro nunomaduro changed the title [8.X] TypeError when using the Bus fake [8.x] TypeError when using the Bus fake Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants