1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 14:34:04 +00:00

[3.x] DB users (#382)

* Initial draft

* Apply fixes from StyleCI

* Use CI on master branch too

* Pass correct argument to queued DB creators/deleters

* Apply fixes from StyleCI

* Remove new interface from MySQLDBManager

* Make phpunit run

* Apply fixes from StyleCI

* Fix static property

* Default databaseName

* Use database transactions for creating users & granting permissions

* Apply fixes from StyleCI

* Get old tests to pass

* Apply fixes from StyleCI

* Add tests for PermissionControlledMySQLDatabaseManager

* Apply fixes from StyleCI

* Write test for extra config, fix bug with extra config

* Apply fixes from StyleCI
This commit is contained in:
Samuel Štancl 2020-05-03 18:12:27 +02:00 committed by GitHub
parent 60665517a0
commit 3bb2759fe2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 756 additions and 286 deletions

View file

@ -9,8 +9,8 @@ use Stancl\Tenancy\Tenant;
abstract class TestCase extends \Orchestra\Testbench\TestCase
{
public $autoCreateTenant = true;
public $autoInitTenancy = true;
public $autoCreateTenant = false;
public $autoInitTenancy = false;
/**
* Setup the test environment.
@ -24,12 +24,12 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
Redis::connection('tenancy')->flushdb();
Redis::connection('cache')->flushdb();
$originalConnection = config('database.default');
$this->loadMigrationsFrom([
'--path' => realpath(__DIR__ . '/../assets/migrations'),
'--database' => 'central',
file_put_contents(database_path('central.sqlite'), '');
$this->artisan('migrate:fresh', [
'--force' => true,
'--path' => __DIR__ . '/../assets/migrations',
'--realpath' => true,
]);
config(['database.default' => $originalConnection]); // fix issue caused by loadMigrationsFrom
if ($this->autoCreateTenant) {
$this->createTenant();
@ -62,9 +62,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
\Dotenv\Dotenv::create(__DIR__ . '/..')->load();
}
fclose(fopen(database_path('central.sqlite'), 'w'));
$app['config']->set([
'database.default' => 'central',
'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'),
'database.redis.options.prefix' => 'foo',
@ -80,9 +79,10 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
'database.connections.central' => [
'driver' => 'sqlite',
'database' => database_path('central.sqlite'),
// 'database' => ':memory:',
],
'tenancy.database' => [
'based_on' => 'sqlite',
'template_connection' => 'central',
'prefix' => 'tenant',
'suffix' => '.sqlite',
],
@ -97,7 +97,11 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
'tenancy.redis.tenancy' => env('TENANCY_TEST_REDIS_TENANCY', true),
'database.redis.client' => env('TENANCY_TEST_REDIS_CLIENT', 'phpredis'),
'tenancy.redis.prefixed_connections' => ['default'],
'tenancy.migration_paths' => [database_path('../migrations')],
'tenancy.migration_parameters' => [
'--path' => [database_path('../migrations')],
'--realpath' => true,
'--force' => true,
],
'tenancy.storage_drivers.db.connection' => 'central',
'tenancy.bootstrappers.redis' => \Stancl\Tenancy\TenancyBootstrappers\RedisTenancyBootstrapper::class,
'queue.connections.central' => [