Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I believe I'm correct in my thinking here, this error started cropping up which at first I thought was an issue with my app but after further testing, I believe it relates to the lines mentioned in this PR.
This key-value pair is not always set within the payload. This occurs if either the tenant is not set when dispatching the job (line 31-33), or the job is a Tenant Unaware job (line 27-39).
However, this PR breaks the following tests -
Spatie\Multitenancy\Tests\Feature\TenantAwareJobs\QueueIsTenantAwareByDefaultTest::it_will_not_break_when_no_tenant_is_set
Spatie\Multitenancy\Tests\Feature\TenantAwareJobs\QueueIsTenantAwareByDefaultTest::it_will_not_make_jobs_tenant_aware_if_the_config_setting_is_set_to_false
Spatie\Multitenancy\Tests\Feature\TenantAwareJobs\QueueIsTenantAwareByDefaultTest::it_will_not_make_a_job_tenant_aware_if_it_implement_NotTenantAware
With regards to the
it_will_not_break_when_no_tenant_is_set
test, I believe what is happening here is you're actually triggering the same error I am during your testing, but instead of it being outputted it's causing the Job to fail and therefore returning a null response to the test, which is what it's expecting.If I add
$this->doesntExpectEvents(JobFailed::class);
to the top of that test, it then starts to fail. As the job is actually failing and triggering a JobFailed event.Admittedly I've not looked into the other two tests as I want to be sure I've understood the logic and how the test I have looked into should work first.