mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 13:34:04 +00:00
Merge branch 'archtechx:3.x' into 3.x
This commit is contained in:
commit
394d6ad338
15 changed files with 88 additions and 26 deletions
|
|
@ -196,10 +196,12 @@ class CommandsTest extends TestCase
|
|||
{
|
||||
$tenantId1 = Tenant::create()->getTenantKey();
|
||||
$tenantId2 = Tenant::create()->getTenantKey();
|
||||
$tenantId3 = Tenant::create()->getTenantKey();
|
||||
Artisan::call('tenants:migrate-fresh');
|
||||
|
||||
$this->artisan("tenants:run foo --tenants=$tenantId1 --tenants=$tenantId2 --argument='a=foo' --option='b=bar' --option='c=xyz'")
|
||||
->expectsOutput('Tenant: ' . $tenantId1)
|
||||
->expectsOutput('Tenant: ' . $tenantId2);
|
||||
->expectsOutput('Tenant: ' . $tenantId2)
|
||||
->doesntExpectOutput('Tenant: ' . $tenantId3);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Spatie\Valuestore\Valuestore;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
|
@ -25,7 +23,6 @@ use Illuminate\Queue\Events\JobProcessed;
|
|||
use Illuminate\Queue\Events\JobProcessing;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use PDO;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||
|
|
@ -59,6 +56,7 @@ class QueueTest extends TestCase
|
|||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
$this->valuestore->flush();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,9 +57,11 @@ 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'),
|
||||
'database.redis.options.prefix' => 'foo',
|
||||
'database.redis.client' => 'predis',
|
||||
'database.connections.central' => [
|
||||
'driver' => 'mysql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
|
|
@ -80,6 +82,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
]) : [],
|
||||
],
|
||||
'database.connections.sqlite.database' => ':memory:',
|
||||
'database.connections.mysql.charset' => 'utf8mb4',
|
||||
'database.connections.mysql.collation' => 'utf8mb4_unicode_ci',
|
||||
'database.connections.mysql.host' => env('TENANCY_TEST_MYSQL_HOST', '127.0.0.1'),
|
||||
'database.connections.pgsql.host' => env('TENANCY_TEST_PGSQL_HOST', '127.0.0.1'),
|
||||
'tenancy.filesystem.disks' => [
|
||||
|
|
|
|||
|
|
@ -63,4 +63,46 @@ class UniversalRouteTest extends TestCase
|
|||
->assertSuccessful()
|
||||
->assertSee('acme');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function universal_route_works_when_middleware_is_inserted_via_controller_middleware()
|
||||
{
|
||||
Route::middlewareGroup('universal', []);
|
||||
config(['tenancy.features' => [UniversalRoutes::class]]);
|
||||
|
||||
Route::get('/foo', [UniversalRouteController::class, 'show']);
|
||||
|
||||
$this->get('http://localhost/foo')
|
||||
->assertSuccessful()
|
||||
->assertSee('Tenancy is not initialized.');
|
||||
|
||||
$tenant = Tenant::create([
|
||||
'id' => 'acme',
|
||||
]);
|
||||
$tenant->domains()->create([
|
||||
'domain' => 'acme.localhost',
|
||||
]);
|
||||
|
||||
$this->get('http://acme.localhost/foo')
|
||||
->assertSuccessful()
|
||||
->assertSee('Tenancy is initialized.');
|
||||
}
|
||||
}
|
||||
|
||||
class UniversalRouteController
|
||||
{
|
||||
public function getMiddleware()
|
||||
{
|
||||
return array_map(fn($middleware) => [
|
||||
'middleware' => $middleware,
|
||||
'options' => [],
|
||||
], ['universal', InitializeTenancyByDomain::class]);
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
return tenancy()->initialized
|
||||
? 'Tenancy is initialized.'
|
||||
: 'Tenancy is not initialized.';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue