mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 09:54:03 +00:00
Cache prefixing logic rewrite, session scoping improvements, tests refactor (#43)
* Run cache tests on all supported drivers * update ci healthcheck for memcached * remove memcached healthcheck * fix typos in test comments, expand internal.md [ci skip] * add empty line [ci skip] * switch to using $store->setPrefix() * add dynamodb * refactor try-finally to try-catch * remove unnecessary clearResolvedInstances() call * add dual Cache:: and cache() assertions * add apc * Flush APCu cache in test setup * Revert "add dual Cache:: and cache() assertions" This reverts commit a0bab162fbe2dd0d25e7056ceca4fb7ce54efc77. * phpstan fix * Add logic for scoping 'file' disks to FilesystemTenancyBootstrapper * minor changes, add todos * refactor how the session.connection is used in the DB session bootstrapper * add session forgery prevention logic to the db session bootstrapper * only use the fs bootstrapper for file disk in 'cache data is separated' dataset * minor session scoping test changes * Add session scoping logic to FilesystemTenancyBootstrapper, correctly update disk roots even with storage_path_tenancy disabled * Fix code style (php-cs-fixer) * update docblock * make not-null check more explicit * separate bootstrapper tests, fix swapped test names for two tests * refactor cache bootstrapper tests * resolve global cache todo * expand tests: session separation tests, more filesystem separation assertions; change prefix_base-type config keys to templates/formats * add apc session scoping test, various session separation bugfixes * phpstan + minor logic fixes * prefix_format -> prefix * fix database session separation test * revert composer.json changes, update laravel dependencies to expected next release * only run session scoping logic in cache bootstrapper for redis, memcached, dynamodb, apc; update gitattributes * tenancy.central_domains -> tenancy.identification.central_domains * db session separation test: add datasets --------- Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
This commit is contained in:
parent
943b960718
commit
eecf6f21c8
40 changed files with 1856 additions and 1177 deletions
|
|
@ -4,12 +4,13 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Aws\DynamoDb\DynamoDbClient;
|
||||
use PDO;
|
||||
use Dotenv\Dotenv;
|
||||
use Stancl\Tenancy\Tenancy;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Stancl\Tenancy\Bootstrappers\BroadcastChannelPrefixBootstrapper;
|
||||
use Stancl\Tenancy\Facades\GlobalCache;
|
||||
use Stancl\Tenancy\TenancyServiceProvider;
|
||||
|
|
@ -34,6 +35,46 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
|
||||
Redis::connection('default')->flushdb();
|
||||
Redis::connection('cache')->flushdb();
|
||||
Artisan::call('cache:clear memcached'); // flush memcached
|
||||
Artisan::call('cache:clear file'); // flush file cache
|
||||
apcu_clear_cache(); // flush APCu cache
|
||||
|
||||
// re-create dynamodb `cache` table
|
||||
$dynamodb = new DynamoDbClient([
|
||||
'region' => 'us-east-1',
|
||||
'version' => 'latest',
|
||||
'endpoint' => 'http://dynamodb:8000',
|
||||
'credentials' => [
|
||||
'key' => env('TENANCY_TEST_DYNAMODB_KEY', 'DUMMYIDEXAMPLE'),
|
||||
'secret' => env('TENANCY_TEST_DYNAMODB_KEY', 'DUMMYEXAMPLEKEY'),
|
||||
],
|
||||
]);
|
||||
|
||||
try {
|
||||
$dynamodb->deleteTable([
|
||||
'TableName' => 'cache',
|
||||
]);
|
||||
} catch (\Throwable) {}
|
||||
|
||||
$dynamodb->createTable([
|
||||
'TableName' => 'cache',
|
||||
'KeySchema' => [
|
||||
[
|
||||
'AttributeName' => 'key', // Partition key
|
||||
'KeyType' => 'HASH',
|
||||
]
|
||||
],
|
||||
'AttributeDefinitions' => [
|
||||
[
|
||||
'AttributeName' => 'key',
|
||||
'AttributeType' => 'S', // String
|
||||
]
|
||||
],
|
||||
'ProvisionedThroughput' => [
|
||||
'ReadCapacityUnits' => 100,
|
||||
'WriteCapacityUnits' => 100,
|
||||
],
|
||||
]);
|
||||
|
||||
file_put_contents(database_path('central.sqlite'), '');
|
||||
pest()->artisan('migrate:fresh', [
|
||||
|
|
@ -67,10 +108,18 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
$app['config']->set([
|
||||
'database.default' => 'central',
|
||||
'cache.default' => 'redis',
|
||||
'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'),
|
||||
'session.driver' => 'redis',
|
||||
'database.redis.cache.host' => env('TENANCY_TEST_REDIS_HOST', 'redis'),
|
||||
'database.redis.default.host' => env('TENANCY_TEST_REDIS_HOST', 'redis'),
|
||||
'database.redis.options.prefix' => 'foo',
|
||||
'database.redis.client' => 'predis',
|
||||
'cache.stores.memcached.servers.0.host' => env('TENANCY_TEST_MEMCACHED_HOST', 'memcached'),
|
||||
'cache.stores.dynamodb.key' => env('TENANCY_TEST_DYNAMODB_KEY', 'DUMMYIDEXAMPLE'),
|
||||
'cache.stores.dynamodb.secret' => env('TENANCY_TEST_DYNAMODB_SECRET', 'DUMMYEXAMPLEKEY'),
|
||||
'cache.stores.dynamodb.endpoint' => 'http://dynamodb:8000',
|
||||
'cache.stores.dynamodb.region' => 'us-east-1',
|
||||
'cache.stores.dynamodb.table' => 'cache',
|
||||
'cache.stores.apc' => ['driver' => 'apc'],
|
||||
'database.connections.central' => [
|
||||
'driver' => 'mysql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
|
|
@ -114,7 +163,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
'--realpath' => true,
|
||||
'--force' => true,
|
||||
],
|
||||
'tenancy.central_domains' => ['localhost', '127.0.0.1'],
|
||||
'tenancy.identification.central_domains' => ['localhost', '127.0.0.1'],
|
||||
'tenancy.bootstrappers' => [],
|
||||
'queue.connections.central' => [
|
||||
'driver' => 'sync',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue