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

Fix Redis scan for predis, make phpunit use multiple configs (e.g. different Redis drivers)

This commit is contained in:
Samuel Štancl 2019-08-04 20:04:25 +02:00
parent fe6ce82045
commit 0dc8c80a02
6 changed files with 37 additions and 13 deletions

View file

@ -24,6 +24,10 @@ class BootstrapsTenancyTest extends TestCase
/** @test */
public function redis_is_prefixed()
{
if (! config('tenancy.redis.tenancy')) {
$this->markTestSkipped('Redis tenancy disabled.');
}
$this->initTenancy();
foreach (config('tenancy.redis.prefixed_connections', ['default']) as $connection) {
$prefix = config('tenancy.redis.prefix_base') . tenant('uuid');
@ -35,6 +39,7 @@ class BootstrapsTenancyTest extends TestCase
/** @test */
public function predis_is_supported()
{
// No setDriver() before that version.
if (app()->version() < 'v5.8.27') {
$this->markTestSkipped();
}

View file

@ -66,6 +66,10 @@ class DataSeparationTest extends TestCase
/** @test */
public function redis_is_separated()
{
if (! config('tenancy.redis.tenancy')) {
$this->markTestSkipped('Redis tenancy disabled.');
}
tenancy()->create('tenant1.localhost');
tenancy()->create('tenant2.localhost');

View file

@ -186,4 +186,12 @@ class TenantManagerTest extends TestCase
$tenant = tenant()->create('foo.localhost');
$this->assertSame([$tenant], tenancy()->all()->toArray());
}
/** @test */
public function all_returns_a_list_of_all_tenants()
{
$tenant1 = tenant()->create('foo.localhost');
$tenant2 = tenant()->create('bar.localhost');
$this->assertEqualsCanonicalizing([$tenant1, $tenant2], tenant()->all()->toArray());
}
}

View file

@ -63,6 +63,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
'database.redis.client' => 'phpredis',
'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',
'database.redis.tenancy' => [
'host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'),
'password' => env('TENANCY_TEST_REDIS_PASSWORD', null),
@ -70,6 +71,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
// Use the #14 Redis database unless specified otherwise.
// Make sure you don't store anything in this db!
'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
],
'tenancy.database' => [
'based_on' => 'sqlite',
@ -92,14 +94,14 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
switch ((string) env('STANCL_TENANCY_TEST_VARIANT', '1')) {
case '2':
$app['config']->set([
'tenancy.redis.tenancy' => true,
'database.redis.client' => 'phpredis',
'tenancy.redis.tenancy' => false,
'database.redis.client' => 'predis',
]);
break;
default:
$app['config']->set([
'tenancy.redis.tenancy' => false,
'database.redis.client' => 'predis',
'tenancy.redis.tenancy' => true,
'database.redis.client' => 'phpredis',
]);
}
}