mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 00:54:05 +00:00
Make database creation queueable (#17)
* SOLIDify database creation * Return the result of fclose in SQLiteDBCreator * Make database creation queueable * Add DatabaseCreationTest * Make comment more descriptive [ci skip] * Add composer script to copy .env.example to .env * Minor tweaks * Fix env section * Fix DB_PASSWORD for Travis
This commit is contained in:
parent
136862369d
commit
c53a05cff4
13 changed files with 186 additions and 24 deletions
45
tests/DatabaseCreationTest.php
Normal file
45
tests/DatabaseCreationTest.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Stancl\Tenancy\DatabaseManager;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Stancl\Tenancy\Jobs\QueuedDatabaseCreator;
|
||||
|
||||
class DatabaseCreationTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function sqlite_database_is_created()
|
||||
{
|
||||
$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(QueuedDatabaseCreator::class);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue