mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:14:03 +00:00
[1.7.0] Add DB storage driver (#82)
This commit is contained in:
parent
674f4b3f9a
commit
9df78eb9c2
13 changed files with 375 additions and 25 deletions
|
|
@ -3,19 +3,14 @@
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Stancl\Tenancy\StorageDrivers\RedisStorageDriver;
|
||||
use Stancl\Tenancy\StorageDrivers\DatabaseStorageDriver;
|
||||
|
||||
abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||
{
|
||||
public $autoCreateTenant = true;
|
||||
public $autoInitTenancy = true;
|
||||
|
||||
private function checkRequirements(): void
|
||||
{
|
||||
parent::checkRequirements();
|
||||
|
||||
dd($this->getAnnotations());
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the test environment.
|
||||
*
|
||||
|
|
@ -28,6 +23,12 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
Redis::connection('tenancy')->flushdb();
|
||||
Redis::connection('cache')->flushdb();
|
||||
|
||||
$this->loadMigrationsFrom([
|
||||
'--path' => realpath(__DIR__ . '/../assets/migrations'),
|
||||
'--database' => 'central',
|
||||
]);
|
||||
config(['database.default' => 'sqlite']); // fix issue caused by loadMigrationsFrom
|
||||
|
||||
if ($this->autoCreateTenant) {
|
||||
$this->createTenant();
|
||||
}
|
||||
|
|
@ -37,6 +38,13 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
}
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
// config(['database.default' => 'central']);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function createTenant($domain = 'localhost')
|
||||
{
|
||||
tenant()->create($domain);
|
||||
|
|
@ -59,6 +67,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
\Dotenv\Dotenv::create(__DIR__ . '/..')->load();
|
||||
}
|
||||
|
||||
fclose(fopen(database_path('central.sqlite'), 'w'));
|
||||
|
||||
$app['config']->set([
|
||||
'database.redis.cache.host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'),
|
||||
'database.redis.default.host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'),
|
||||
|
|
@ -72,6 +82,10 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
'database' => env('TENANCY_TEST_REDIS_DB', 14),
|
||||
'prefix' => 'abc', // todo unrelated to tenancy, but this doesn't seem to have an effect? try to replicate in a fresh laravel installation
|
||||
],
|
||||
'database.connections.central' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => database_path('central.sqlite'),
|
||||
],
|
||||
'tenancy.database' => [
|
||||
'based_on' => 'sqlite',
|
||||
'prefix' => 'tenant',
|
||||
|
|
@ -90,11 +104,27 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
'tenancy.redis.prefixed_connections' => ['default'],
|
||||
'tenancy.migrations_directory' => database_path('../migrations'),
|
||||
]);
|
||||
|
||||
if (env('TENANCY_TEST_STORAGE_DRIVER', 'redis') === 'redis') {
|
||||
$app['config']->set([
|
||||
'tenancy.storage_driver' => RedisStorageDriver::class,
|
||||
]);
|
||||
|
||||
tenancy()->storage = $app->make(RedisStorageDriver::class);
|
||||
} elseif (env('TENANCY_TEST_STORAGE_DRIVER', 'redis') === 'db') {
|
||||
$app['config']->set([
|
||||
'tenancy.storage_driver' => DatabaseStorageDriver::class,
|
||||
]);
|
||||
|
||||
tenancy()->storage = $app->make(DatabaseStorageDriver::class);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [\Stancl\Tenancy\TenancyServiceProvider::class];
|
||||
return [
|
||||
\Stancl\Tenancy\TenancyServiceProvider::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getPackageAliases($app)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue