mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:54:03 +00:00
Merge db creation & deletion tests
This commit is contained in:
parent
9417e0acf2
commit
0bb18bb11a
1 changed files with 14 additions and 36 deletions
|
|
@ -11,41 +11,7 @@ use Stancl\Tenancy\Jobs\QueuedTenantDatabaseDeleter;
|
||||||
class TenantDatabaseManagerTest extends TestCase
|
class TenantDatabaseManagerTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @test */
|
/** @test */
|
||||||
public function sqlite_database_is_created()
|
public function sqlite_database_can_be_created_and_deleted()
|
||||||
{
|
|
||||||
$db_name = 'testdatabase' . $this->randomString(10) . '.sqlite';
|
|
||||||
app(DatabaseManager::class)->create($db_name, 'sqlite');
|
|
||||||
$this->assertFileExists(database_path($db_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @test */
|
|
||||||
public function mysql_database_is_created()
|
|
||||||
{
|
|
||||||
if (! $this->isTravis()) {
|
|
||||||
$this->markTestSkipped('As to not bloat your MySQL instance with test databases, this test is not run by default.');
|
|
||||||
}
|
|
||||||
|
|
||||||
config()->set('database.default', 'mysql');
|
|
||||||
|
|
||||||
$db_name = 'testdatabase' . $this->randomString(10);
|
|
||||||
app(DatabaseManager::class)->create($db_name, 'mysql');
|
|
||||||
$this->assertNotEmpty(DB::select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$db_name'"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @test */
|
|
||||||
public function database_creation_can_be_queued()
|
|
||||||
{
|
|
||||||
Queue::fake();
|
|
||||||
|
|
||||||
config()->set('tenancy.queue_database_creation', true);
|
|
||||||
$db_name = 'testdatabase' . $this->randomString(10) . '.sqlite';
|
|
||||||
app(DatabaseManager::class)->create($db_name, 'sqlite');
|
|
||||||
|
|
||||||
Queue::assertPushed(QueuedTenantDatabaseCreator::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @test */
|
|
||||||
public function sqlite_database_is_deleted()
|
|
||||||
{
|
{
|
||||||
$db_name = 'testdatabase' . $this->randomString(10) . '.sqlite';
|
$db_name = 'testdatabase' . $this->randomString(10) . '.sqlite';
|
||||||
app(DatabaseManager::class)->create($db_name, 'sqlite');
|
app(DatabaseManager::class)->create($db_name, 'sqlite');
|
||||||
|
|
@ -56,7 +22,7 @@ class TenantDatabaseManagerTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function mysql_database_is_deleted()
|
public function mysql_database_can_be_created_and_deleted()
|
||||||
{
|
{
|
||||||
if (! $this->isTravis()) {
|
if (! $this->isTravis()) {
|
||||||
$this->markTestSkipped('As to not bloat your MySQL instance with test databases, this test is not run by default.');
|
$this->markTestSkipped('As to not bloat your MySQL instance with test databases, this test is not run by default.');
|
||||||
|
|
@ -72,6 +38,18 @@ class TenantDatabaseManagerTest extends TestCase
|
||||||
$this->assertEmpty(DB::select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$db_name'"));
|
$this->assertEmpty(DB::select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$db_name'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function database_creation_can_be_queued()
|
||||||
|
{
|
||||||
|
Queue::fake();
|
||||||
|
|
||||||
|
config()->set('tenancy.queue_database_creation', true);
|
||||||
|
$db_name = 'testdatabase' . $this->randomString(10) . '.sqlite';
|
||||||
|
app(DatabaseManager::class)->create($db_name, 'sqlite');
|
||||||
|
|
||||||
|
Queue::assertPushed(QueuedTenantDatabaseCreator::class);
|
||||||
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function database_deletion_can_be_queued()
|
public function database_deletion_can_be_queued()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue