1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 11:14:03 +00:00

Terminating pipeline tests

This commit is contained in:
Samuel Štancl 2020-11-15 16:19:53 +01:00
parent f20bb55022
commit e4c672d9d9

View file

@ -17,6 +17,7 @@ use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Events\TenantCreated;
use Stancl\Tenancy\Events\UpdatingDomain;
use Stancl\Tenancy\Jobs\CreateDatabase;
use Stancl\Tenancy\Jobs\MigrateDatabase;
use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\QueueableListener;
use Stancl\Tenancy\Tenancy;
@ -127,6 +128,77 @@ class EventListenerTest extends TestCase
$this->assertSame([DatabaseTenancyBootstrapper::class], array_map('get_class', tenancy()->getBootstrappers()));
}
/** @test */
public function individual_job_pipelines_can_terminate_while_leaving_others_running()
{
$executed = [];
Event::listen(
TenantCreated::class,
JobPipeline::make([
function () use (&$executed) {
$executed[] = 'P1J1';
},
function () use (&$executed) {
$executed[] = 'P1J2';
},
])->send(function (TenantCreated $event) {
return $event->tenant;
})->toListener()
);
Event::listen(
TenantCreated::class,
JobPipeline::make([
function () use (&$executed) {
$executed[] = 'P2J1';
return false;
},
function () use (&$executed) {
$executed[] = 'P2J2';
},
])->send(function (TenantCreated $event) {
return $event->tenant;
})->toListener()
);
Tenant::create();
$this->assertSame([
'P1J1',
'P1J2',
'P2J1', // termminated after this
// P2J2 was not reached
], $executed);
}
/** @test */
public function database_is_not_migrated_if_creation_is_disabled()
{
Event::listen(
TenantCreated::class,
JobPipeline::make([
CreateDatabase::class,
function () {
$this->fail("The job pipeline didn't exit.");
},
MigrateDatabase::class,
])->send(function (TenantCreated $event) {
return $event->tenant;
})->toListener()
);
Tenant::create([
'tenancy_create_database' => false,
'tenancy_db_name' => 'already_created',
]);
$this->assertFalse($this->hasFailed());
}
}
class FooListener extends QueueableListener