1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-09-20 14:14:03 +00:00

minor test improvements

This commit is contained in:
Samuel Stancl 2026-08-25 19:17:24 -07:00
parent 11811285f1
commit f4464797f3
No known key found for this signature in database
GPG key ID: BA146259A1E16C57
2 changed files with 19 additions and 15 deletions

View file

@ -300,7 +300,7 @@ test('scoped disks are scoped per tenant', function () {
expect(file_get_contents(storage_path() . "/tenant{$tenant->id}/app/public/scoped_disk_prefix/foo.txt"))->toBe('tenant'); expect(file_get_contents(storage_path() . "/tenant{$tenant->id}/app/public/scoped_disk_prefix/foo.txt"))->toBe('tenant');
}); });
test('file cache stores get their path scoped on bootstrap and restored back on revert', function () { test('file cache stores get their paths scoped on bootstrap and restored back on revert', function () {
$fooPath = storage_path('framework/cache/foo_file'); $fooPath = storage_path('framework/cache/foo_file');
$barPath = storage_path('framework/cache/bar_file'); $barPath = storage_path('framework/cache/bar_file');
File::deleteDirectory($fooPath); File::deleteDirectory($fooPath);
@ -342,8 +342,8 @@ test('file cache stores get their path scoped on bootstrap and restored back on
Cache::store('bar_file')->flush(); Cache::store('bar_file')->flush();
// Only bar_file was flushed // Only bar_file was flushed
expect(Cache::store('bar_file')->get('key'))->toBeNull();
expect(Cache::store('foo_file')->get('key'))->toBe('tenant foo'); expect(Cache::store('foo_file')->get('key'))->toBe('tenant foo');
expect(Cache::store('bar_file')->get('key'))->toBeNull();
tenancy()->end(); tenancy()->end();
@ -376,11 +376,6 @@ test('only file driver cache stores get scoped', function () {
Cache::store('redis')->put('key', 'central'); Cache::store('redis')->put('key', 'central');
// 'redis' and 'nonexistent_store' are skipped by the driver check in scopeCache(), before it reads their path.
// Without the skipping logic, the `$this->originalCachePaths[$name] = $store['path']`
// line in scopeCache() would throw an ErrorException while initializing tenancy
// (with 'redis', we'd get an 'Undefined array key "path"' exception, and with 'nonexistent_store',
// we'd get 'Trying to access array offset on null').
tenancy()->initialize($tenant = Tenant::create()); tenancy()->initialize($tenant = Tenant::create());
// Only the file store's path gets scoped // Only the file store's path gets scoped
@ -398,7 +393,7 @@ test('only file driver cache stores get scoped', function () {
File::deleteDirectory($fooPath); File::deleteDirectory($fooPath);
}); });
test('cache scoping can be disabled using the scope_cache config', function () { test('cache scoping can be toggled using the scope_cache config', function (bool $scopeCache) {
$fooPath = storage_path('framework/cache/foo_file'); $fooPath = storage_path('framework/cache/foo_file');
File::deleteDirectory($fooPath); File::deleteDirectory($fooPath);
@ -411,25 +406,34 @@ test('cache scoping can be disabled using the scope_cache config', function () {
'driver' => 'file', 'driver' => 'file',
'path' => $fooPath, 'path' => $fooPath,
], ],
'tenancy.filesystem.scope_cache' => false, 'tenancy.filesystem.scope_cache' => $scopeCache,
]); ]);
Cache::store('foo_file')->put('key', 'central'); Cache::store('foo_file')->put('key', 'central');
tenancy()->initialize(Tenant::create()); tenancy()->initialize(Tenant::create());
if ($scopeCache) {
expect(config('cache.stores.foo_file.path'))->not()->toBe($fooPath);
expect(Cache::store('foo_file')->get('key'))->toBe(null);
} else {
// The store keeps using its central path, so the cache is shared between contexts // The store keeps using its central path, so the cache is shared between contexts
expect(config('cache.stores.foo_file.path'))->toBe($fooPath); expect(config('cache.stores.foo_file.path'))->toBe($fooPath);
expect(Cache::store('foo_file')->get('key'))->toBe('central'); expect(Cache::store('foo_file')->get('key'))->toBe('central');
}
Cache::store('foo_file')->put('key', 'written in tenant context'); Cache::store('foo_file')->put('key', 'written in tenant context');
tenancy()->end(); tenancy()->end();
if ($scopeCache) {
expect(Cache::store('foo_file')->get('key'))->toBe('central');
} else {
expect(Cache::store('foo_file')->get('key'))->toBe('written in tenant context'); expect(Cache::store('foo_file')->get('key'))->toBe('written in tenant context');
}
File::deleteDirectory($fooPath); File::deleteDirectory($fooPath);
}); })->with([true, false]);
test('scopeCache ignores changes to tenancy.cache.stores made in tenant context', function () { test('scopeCache ignores changes to tenancy.cache.stores made in tenant context', function () {
$fooPath = storage_path('framework/cache/foo_file'); $fooPath = storage_path('framework/cache/foo_file');

View file

@ -126,7 +126,7 @@ test('file sessions are separated when a custom session path is configured', fun
expect(File::files($tenantSessionPath))->toHaveCount(1); expect(File::files($tenantSessionPath))->toHaveCount(1);
expect(File::files($configuredSessionPath))->toHaveCount(0); expect(File::files($configuredSessionPath))->toHaveCount(0);
// End tenancy to test the revert behavior (= the central session file gets created to the original configured path) // End tenancy to test the revert behavior (= the central session file gets created at the original configured path)
tenancy()->end(); tenancy()->end();
pest()->get('/central'); pest()->get('/central');