mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 14:34:04 +00:00
[4.x] Don't use onDeleteCascade in the migrations (#883)
* removed `cascade` on delete for domains * removed only `onDelete` cascade * keep impersonation migrations unchanged * domains set null on delete * Update 2019_09_15_000020_create_domains_table.php * Added DeleteDomain Job while deleting tenant. * Update assets/TenancyServiceProvider.stub.php Co-authored-by: Samuel Štancl <samuel@archte.ch> * renamed class * Update DeleteDomains.php * onDelete restrict * revert nullable * removed `shouldQueue` interface * Update TenancyServiceProvider.stub.php * fetch and delete domains individually * Update DeleteDomains.php * tests for `DeleteDomains` job Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
4aec6bfda2
commit
627233d07a
4 changed files with 85 additions and 2 deletions
42
tests/DeleteDomainsJobTest.php
Normal file
42
tests/DeleteDomainsJobTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Stancl\Tenancy\Database\Concerns\HasDomains;
|
||||
use Stancl\Tenancy\Jobs\DeleteDomains;
|
||||
|
||||
class DeleteDomainsJobTest extends TestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
config(['tenancy.tenant_model' => DatabaseAndDomainTenant::class]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function job_delete_domains_successfully()
|
||||
{
|
||||
$tenant = DatabaseAndDomainTenant::create();
|
||||
|
||||
$tenant->domains()->create([
|
||||
'domain' => 'foo.localhost',
|
||||
]);
|
||||
$tenant->domains()->create([
|
||||
'domain' => 'bar.localhost',
|
||||
]);
|
||||
|
||||
$this->assertSame($tenant->domains()->count(), 2);
|
||||
|
||||
(new DeleteDomains($tenant))->handle();
|
||||
|
||||
$this->assertSame($tenant->refresh()->domains()->count(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
class DatabaseAndDomainTenant extends Etc\Tenant
|
||||
{
|
||||
use HasDomains;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue