-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from masterix21/feature-queue-config
Jobs (not?) tenant aware using the config
- Loading branch information
Showing
6 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Spatie\Multitenancy\Tests\Feature\TenantAwareJobs; | ||
|
||
use Illuminate\Contracts\Bus\Dispatcher; | ||
use Spatie\Multitenancy\Models\Tenant; | ||
use Spatie\Multitenancy\Tests\Feature\TenantAwareJobs\TestClasses\TestJob; | ||
use Spatie\Multitenancy\Tests\TestCase; | ||
use Spatie\Valuestore\Valuestore; | ||
|
||
class TenantAwareJobsByConfig extends TestCase | ||
{ | ||
protected Tenant $tenant; | ||
|
||
protected Valuestore $valuestore; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
config()->set('multitenancy.queues_are_tenant_aware_by_default', false); | ||
config()->set('queue.default', 'sync'); | ||
config()->set('mail.default', 'log'); | ||
|
||
$this->tenant = factory(Tenant::class)->create(); | ||
$this->valuestore = Valuestore::make($this->tempFile('tenantAware.json'))->flush(); | ||
} | ||
|
||
/** @test */ | ||
public function it_success_with_jobs_in_tenant_aware_jobs_list(): void | ||
{ | ||
config()->set('multitenancy.tenant_aware_jobs', [ TestJob::class ]); | ||
|
||
$this->tenant->makeCurrent(); | ||
|
||
app(Dispatcher::class)->dispatch(new TestJob($this->valuestore)); | ||
|
||
$this->assertTrue($this->valuestore->has('tenantIdInPayload')); | ||
$this->assertNotNull($this->valuestore->get('tenantIdInPayload')); | ||
} | ||
|
||
/** @test */ | ||
public function it_fails_with_jobs_in_not_tenant_aware_jobs_list(): void | ||
{ | ||
config()->set('multitenancy.not_tenant_aware_jobs', [ TestJob::class ]); | ||
|
||
$this->tenant->makeCurrent(); | ||
|
||
app(Dispatcher::class)->dispatch(new TestJob($this->valuestore)); | ||
|
||
$this->assertEquals($this->valuestore->get('tenantId'), $this->tenant->id); | ||
$this->assertTrue($this->valuestore->has('tenantIdInPayload')); | ||
$this->assertNull($this->valuestore->get('tenantIdInPayload')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters