diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef40e072..91699f08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: include: - - laravel: "^11.0" + - laravel: "^12.0" php: "8.4" steps: diff --git a/.github/workflows/queue.yml b/.github/workflows/queue.yml index 2b3a63c5..cb3937e0 100644 --- a/.github/workflows/queue.yml +++ b/.github/workflows/queue.yml @@ -10,11 +10,19 @@ jobs: steps: - name: Prepare composer version constraint prefix run: | - BRANCH=${GITHUB_REF#refs/heads/} - if [[ $BRANCH =~ ^[0-9]\.x$ ]]; then - echo "VERSION_PREFIX=${BRANCH}-dev" >> $GITHUB_ENV + if [[ $GITHUB_REF == refs/tags/* ]]; then + # For refs like "refs/tags/v3.9.0", remove "refs/tags/v" prefix to get just "3.9.0" + VERSION=${GITHUB_REF#refs/tags/v} + echo "VERSION_PREFIX=${VERSION}" >> $GITHUB_ENV else - echo "VERSION_PREFIX=dev-${BRANCH}" >> $GITHUB_ENV + BRANCH=${GITHUB_REF#refs/heads/} + if [[ $BRANCH =~ ^[0-9]\.x$ ]]; then + # Branches starting with %d.x need to use -dev suffix + echo "VERSION_PREFIX=${BRANCH}-dev" >> $GITHUB_ENV + else + # All other branches use dev-${branch} prefix + echo "VERSION_PREFIX=dev-${BRANCH}" >> $GITHUB_ENV + fi fi - name: Clone test suite diff --git a/composer.json b/composer.json index 18326bac..e3a7faf4 100644 --- a/composer.json +++ b/composer.json @@ -18,25 +18,24 @@ "require": { "php": "^8.4", "ext-json": "*", - "illuminate/support": "^10.1|^11.3", + "illuminate/support": "^12.0", "laravel/tinker": "^2.0", "facade/ignition-contracts": "^1.0.2", "spatie/ignition": "^1.4", "ramsey/uuid": "^4.7.3", - "stancl/jobpipeline": "2.0.0-rc2", - "stancl/virtualcolumn": "dev-master", + "stancl/jobpipeline": "2.0.0-rc5", + "stancl/virtualcolumn": "^1.5.0", "spatie/invade": "*", "laravel/prompts": "0.*" }, "require-dev": { - "laravel/framework": "^10.1|^11.3", - "orchestra/testbench": "^8.0|^9.0", + "laravel/framework": "^12.0", + "orchestra/testbench": "^10.0", "league/flysystem-aws-s3-v3": "^3.12.2", "doctrine/dbal": "^3.6.0", "spatie/valuestore": "^1.2.5", - "pestphp/pest": "^2.0", - "larastan/larastan": "^3.0", - "aws/aws-sdk-php-laravel": "~3.0" + "pestphp/pest": "^3.0", + "larastan/larastan": "^3.0" }, "autoload": { "psr-4": { diff --git a/src/RLS/PolicyManagers/TableRLSManager.php b/src/RLS/PolicyManagers/TableRLSManager.php index 098e8015..61c62f94 100644 --- a/src/RLS/PolicyManagers/TableRLSManager.php +++ b/src/RLS/PolicyManagers/TableRLSManager.php @@ -75,7 +75,10 @@ class TableRLSManager implements RLSPolicyManager $builder = $this->database->getSchemaBuilder(); // We loop through each table in the database - foreach ($builder->getTableListing() as $table) { + foreach ($builder->getTableListing(schema: $this->database->getConfig('search_path')) as $table) { + // E.g. "public.table_name" -> "table_name" + $table = str($table)->afterLast('.')->toString(); + // For each table, we get a list of all foreign key columns $foreignKeys = collect($builder->getForeignKeys($table))->map(function ($foreign) use ($table) { return $this->formatForeignKey($foreign, $table); diff --git a/tests/AutomaticModeTest.php b/tests/AutomaticModeTest.php index f34aa7f1..fbeb06fc 100644 --- a/tests/AutomaticModeTest.php +++ b/tests/AutomaticModeTest.php @@ -9,6 +9,8 @@ use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; +use function Stancl\Tenancy\Tests\withTenantDatabases; beforeEach(function () { Event::listen(TenancyInitialized::class, BootstrapTenancy::class); diff --git a/tests/Bootstrappers/BootstrapperTest.php b/tests/Bootstrappers/BootstrapperTest.php index 10120f85..c4fed90c 100644 --- a/tests/Bootstrappers/BootstrapperTest.php +++ b/tests/Bootstrappers/BootstrapperTest.php @@ -23,6 +23,7 @@ use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { $this->mockConsoleOutput = false; diff --git a/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php b/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php index 4c3ea30a..785430f5 100644 --- a/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php +++ b/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php @@ -15,6 +15,7 @@ use Stancl\Tenancy\Tests\Etc\TestingBroadcaster; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\BroadcastChannelPrefixBootstrapper; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { Event::listen(TenancyInitialized::class, BootstrapTenancy::class); diff --git a/tests/Bootstrappers/CacheTagsBootstrapperTest.php b/tests/Bootstrappers/CacheTagsBootstrapperTest.php index fa63fc6c..660be1a7 100644 --- a/tests/Bootstrappers/CacheTagsBootstrapperTest.php +++ b/tests/Bootstrappers/CacheTagsBootstrapperTest.php @@ -9,6 +9,7 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Bootstrappers\CacheTagsBootstrapper; use Stancl\Tenancy\Events\TenancyEnded; use Stancl\Tenancy\Listeners\RevertToCentralContext; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { config(['tenancy.bootstrappers' => [CacheTagsBootstrapper::class]]); diff --git a/tests/Bootstrappers/DatabaseSessionBootstrapperTest.php b/tests/Bootstrappers/DatabaseSessionBootstrapperTest.php index f249c975..a6faa9a8 100644 --- a/tests/Bootstrappers/DatabaseSessionBootstrapperTest.php +++ b/tests/Bootstrappers/DatabaseSessionBootstrapperTest.php @@ -13,6 +13,7 @@ use Stancl\Tenancy\Jobs\CreateDatabase; use Stancl\Tenancy\Listeners; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; /** * This collection of regression tests verifies that SessionTenancyBootstrapper diff --git a/tests/Bootstrappers/DatabaseTenancyBootstrapper.php b/tests/Bootstrappers/DatabaseTenancyBootstrapper.php index 8c8259cd..14109500 100644 --- a/tests/Bootstrappers/DatabaseTenancyBootstrapper.php +++ b/tests/Bootstrappers/DatabaseTenancyBootstrapper.php @@ -6,6 +6,9 @@ use Stancl\Tenancy\Events\TenancyEnded; use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; +use Stancl\Tenancy\Tests\Etc\Tenant; + +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { Event::listen(TenancyInitialized::class, BootstrapTenancy::class); diff --git a/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php b/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php index 06aad296..d6b6a231 100644 --- a/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php +++ b/tests/Bootstrappers/FilesystemTenancyBootstrapperTest.php @@ -16,6 +16,7 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\DeleteTenantStorage; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { Event::listen(TenancyInitialized::class, BootstrapTenancy::class); diff --git a/tests/BroadcastingTest.php b/tests/BroadcastingTest.php index ba221307..c3509426 100644 --- a/tests/BroadcastingTest.php +++ b/tests/BroadcastingTest.php @@ -19,6 +19,7 @@ use Illuminate\Broadcasting\Broadcasters\NullBroadcaster; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\BroadcastingConfigBootstrapper; use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract; +use function Stancl\Tenancy\Tests\withTenantDatabases; beforeEach(function () { withTenantDatabases(); diff --git a/tests/CachedTenantResolverTest.php b/tests/CachedTenantResolverTest.php index 0ca9553f..02d935c5 100644 --- a/tests/CachedTenantResolverTest.php +++ b/tests/CachedTenantResolverTest.php @@ -12,8 +12,8 @@ use Stancl\Tenancy\Resolvers\DomainTenantResolver; use Illuminate\Support\Facades\Route as RouteFacade; use Illuminate\Support\Facades\Schema; use Stancl\Tenancy\Middleware\InitializeTenancyByPath; -use Stancl\Tenancy\PathIdentificationManager; use Stancl\Tenancy\Resolvers\RequestDataTenantResolver; +use function Stancl\Tenancy\Tests\pest; test('tenants can be resolved using cached resolvers', function (string $resolver) { $tenant = Tenant::create(['id' => $tenantKey = 'acme']); diff --git a/tests/CloneActionTest.php b/tests/CloneActionTest.php index 8be8881b..3706f31e 100644 --- a/tests/CloneActionTest.php +++ b/tests/CloneActionTest.php @@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Route as RouteFacade; use Stancl\Tenancy\Tests\Etc\HasMiddlewareController; use Stancl\Tenancy\Middleware\InitializeTenancyByPath; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; +use function Stancl\Tenancy\Tests\pest; test('a route can be universal using path identification', function (array $routeMiddleware, array $globalMiddleware) { foreach ($globalMiddleware as $middleware) { diff --git a/tests/CombinedDomainAndSubdomainIdentificationTest.php b/tests/CombinedDomainAndSubdomainIdentificationTest.php index 85f11182..1cae6408 100644 --- a/tests/CombinedDomainAndSubdomainIdentificationTest.php +++ b/tests/CombinedDomainAndSubdomainIdentificationTest.php @@ -3,10 +3,9 @@ declare(strict_types=1); use Illuminate\Support\Facades\Route; -use Stancl\Tenancy\Database\Concerns\HasDomains; use Stancl\Tenancy\Middleware\InitializeTenancyByDomainOrSubdomain; -use Stancl\Tenancy\Database\Models; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { Route::group([ diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index aecbb07c..7ebb07a8 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -26,6 +26,7 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; use Stancl\Tenancy\Database\Exceptions\TenantDatabaseDoesNotExistException; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { if (file_exists($schemaPath = 'tests/Etc/tenant-schema-test.dump')) { diff --git a/tests/DatabaseUsersTest.php b/tests/DatabaseUsersTest.php index d10aca57..aed487ac 100644 --- a/tests/DatabaseUsersTest.php +++ b/tests/DatabaseUsersTest.php @@ -24,6 +24,7 @@ use Stancl\Tenancy\Database\TenantDatabaseManagers\PermissionControlledMySQLData use Stancl\Tenancy\Database\TenantDatabaseManagers\PermissionControlledPostgreSQLSchemaManager; use Stancl\Tenancy\Database\TenantDatabaseManagers\PermissionControlledPostgreSQLDatabaseManager; use Stancl\Tenancy\Database\TenantDatabaseManagers\PermissionControlledMicrosoftSQLServerDatabaseManager; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { config([ diff --git a/tests/DomainTest.php b/tests/DomainTest.php index cb104532..e393f538 100644 --- a/tests/DomainTest.php +++ b/tests/DomainTest.php @@ -10,6 +10,7 @@ use Stancl\Tenancy\Exceptions\DomainOccupiedByOtherTenantException; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Resolvers\DomainTenantResolver; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { InitializeTenancyByDomain::$onFail = null; diff --git a/tests/EarlyIdentificationTest.php b/tests/EarlyIdentificationTest.php index 4fbf6e3a..48ac4d12 100644 --- a/tests/EarlyIdentificationTest.php +++ b/tests/EarlyIdentificationTest.php @@ -24,6 +24,7 @@ use Stancl\Tenancy\Middleware\InitializeTenancyByOriginHeader; use Stancl\Tenancy\Tests\Etc\EarlyIdentification\ControllerWithMiddleware; use Stancl\Tenancy\Tests\Etc\EarlyIdentification\ControllerWithRouteMiddleware; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { config()->set([ diff --git a/tests/EventListenerTest.php b/tests/EventListenerTest.php index d88d63de..5aeb4769 100644 --- a/tests/EventListenerTest.php +++ b/tests/EventListenerTest.php @@ -19,6 +19,7 @@ use Stancl\Tenancy\Events\BootstrappingTenancy; use Stancl\Tenancy\Listeners\QueueableListener; use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { FooListener::$shouldQueue = false; diff --git a/tests/Features/NoAttachTest.php b/tests/Features/NoAttachTest.php index e82f3eb4..a1588a24 100644 --- a/tests/Features/NoAttachTest.php +++ b/tests/Features/NoAttachTest.php @@ -18,6 +18,7 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Middleware\InitializeTenancyByPath; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; test('sqlite ATTACH statements can be blocked', function (bool $disallow) { if (php_uname('m') == 'aarch64') { diff --git a/tests/Features/RedirectTest.php b/tests/Features/RedirectTest.php index 7aca2e92..a4102070 100644 --- a/tests/Features/RedirectTest.php +++ b/tests/Features/RedirectTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); use Illuminate\Support\Facades\Route; use Stancl\Tenancy\Features\CrossDomainRedirect; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; test('tenant redirect macro replaces only the hostname', function () { config([ diff --git a/tests/Features/TenantConfigTest.php b/tests/Features/TenantConfigTest.php index 5c12c5f0..b06ddba9 100644 --- a/tests/Features/TenantConfigTest.php +++ b/tests/Features/TenantConfigTest.php @@ -9,6 +9,7 @@ use Stancl\Tenancy\Features\TenantConfig; use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; afterEach(function () { TenantConfig::$storageToConfigMap = []; diff --git a/tests/MailTest.php b/tests/MailTest.php index c41b5578..be651765 100644 --- a/tests/MailTest.php +++ b/tests/MailTest.php @@ -10,6 +10,8 @@ use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Bootstrappers\MailConfigBootstrapper; +use function Stancl\Tenancy\Tests\pest; +use function Stancl\Tenancy\Tests\withTenantDatabases; beforeEach(function() { config(['mail.default' => 'smtp']); diff --git a/tests/MaintenanceModeTest.php b/tests/MaintenanceModeTest.php index 59024c96..9c90f0d3 100644 --- a/tests/MaintenanceModeTest.php +++ b/tests/MaintenanceModeTest.php @@ -8,6 +8,7 @@ use Stancl\Tenancy\Database\Concerns\MaintenanceMode; use Illuminate\Support\Facades\Route; use Stancl\Tenancy\Middleware\CheckTenantForMaintenanceMode; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; +use function Stancl\Tenancy\Tests\pest; use Stancl\Tenancy\Tests\Etc\Tenant; beforeEach(function () { diff --git a/tests/ManualModeTest.php b/tests/ManualModeTest.php index f9983cf7..2e723586 100644 --- a/tests/ManualModeTest.php +++ b/tests/ManualModeTest.php @@ -11,7 +11,8 @@ use Stancl\Tenancy\Jobs\CreateDatabase; use Stancl\Tenancy\Listeners\CreateTenantConnection; use Stancl\Tenancy\Listeners\UseCentralConnection; use Stancl\Tenancy\Listeners\UseTenantConnection; -use \Stancl\Tenancy\Tests\Etc\Tenant; +use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; test('manual tenancy initialization works', function () { Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) { diff --git a/tests/OriginHeaderIdentificationTest.php b/tests/OriginHeaderIdentificationTest.php index 83737f1f..071aa493 100644 --- a/tests/OriginHeaderIdentificationTest.php +++ b/tests/OriginHeaderIdentificationTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); use Stancl\Tenancy\Tests\Etc\Tenant; use Illuminate\Support\Facades\Route; use Stancl\Tenancy\Middleware\InitializeTenancyByOriginHeader; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { InitializeTenancyByOriginHeader::$onFail = null; diff --git a/tests/PathIdentificationTest.php b/tests/PathIdentificationTest.php index 9fbaf68b..1df74092 100644 --- a/tests/PathIdentificationTest.php +++ b/tests/PathIdentificationTest.php @@ -12,6 +12,7 @@ use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByPathException; use Stancl\Tenancy\Middleware\InitializeTenancyByPath; use Stancl\Tenancy\Resolvers\PathTenantResolver; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { // Make sure the tenant parameter is set to 'tenant' diff --git a/tests/PendingTenantsTest.php b/tests/PendingTenantsTest.php index 26fd5c34..3339baaf 100644 --- a/tests/PendingTenantsTest.php +++ b/tests/PendingTenantsTest.php @@ -11,6 +11,7 @@ use Stancl\Tenancy\Events\PendingTenantCreated; use Stancl\Tenancy\Events\PendingTenantPulled; use Stancl\Tenancy\Events\PullingPendingTenant; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; test('tenants are correctly identified as pending', function (){ Tenant::createPending(); diff --git a/tests/Pest.php b/tests/Pest.php index 5380da0a..cd18d174 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,5 +1,7 @@ in(__DIR__); -function pest(): TestCase -{ - return Pest\TestSuite::getInstance()->test; -} - function withTenantDatabases() { Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) { return $event->tenant; })->toListener()); } + +function pest(): TestCase +{ + return \Pest\TestSuite::getInstance()->test; +} diff --git a/tests/PreventAccessFromUnwantedDomainsTest.php b/tests/PreventAccessFromUnwantedDomainsTest.php index 99d0c2fe..9c4764d2 100644 --- a/tests/PreventAccessFromUnwantedDomainsTest.php +++ b/tests/PreventAccessFromUnwantedDomainsTest.php @@ -11,6 +11,7 @@ use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain; use Stancl\Tenancy\Middleware\PreventAccessFromUnwantedDomains; use Stancl\Tenancy\Middleware\InitializeTenancyByDomainOrSubdomain; use Stancl\Tenancy\Tests\Etc\EarlyIdentification\ControllerWithMiddleware; +use function Stancl\Tenancy\Tests\pest; test('correct routes are accessible in route-level identification', function (RouteMode $defaultRouteMode) { config()->set([ diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 2095cc84..25ab320e 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -24,6 +24,8 @@ use Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\PersistentQueueTenancyBootstrapper; use Stancl\Tenancy\Listeners\QueueableListener; +use function Stancl\Tenancy\Tests\pest; +use function Stancl\Tenancy\Tests\withTenantDatabases; beforeEach(function () { config([ diff --git a/tests/RLS/PolicyTest.php b/tests/RLS/PolicyTest.php index 7c7165bc..7278776a 100644 --- a/tests/RLS/PolicyTest.php +++ b/tests/RLS/PolicyTest.php @@ -17,6 +17,7 @@ use Stancl\Tenancy\Commands\CreateUserWithRLSPolicies; use Stancl\Tenancy\RLS\PolicyManagers\TableRLSManager; use Stancl\Tenancy\RLS\PolicyManagers\TraitRLSManager; use Stancl\Tenancy\Bootstrappers\PostgresRLSBootstrapper; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { TraitRLSManager::$excludedModels = [Article::class]; diff --git a/tests/RLS/TableManagerTest.php b/tests/RLS/TableManagerTest.php index 84689a72..4a8ac058 100644 --- a/tests/RLS/TableManagerTest.php +++ b/tests/RLS/TableManagerTest.php @@ -19,6 +19,7 @@ use Stancl\Tenancy\Commands\CreateUserWithRLSPolicies; use Stancl\Tenancy\RLS\PolicyManagers\TableRLSManager; use Stancl\Tenancy\Bootstrappers\PostgresRLSBootstrapper; use Stancl\Tenancy\Database\Exceptions\RecursiveRelationshipException; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { TableRLSManager::$scopeByDefault = true; diff --git a/tests/RLS/TraitManagerTest.php b/tests/RLS/TraitManagerTest.php index 7a7dd37a..af2f6f84 100644 --- a/tests/RLS/TraitManagerTest.php +++ b/tests/RLS/TraitManagerTest.php @@ -25,6 +25,7 @@ use Stancl\Tenancy\Commands\CreateUserWithRLSPolicies; use Stancl\Tenancy\RLS\PolicyManagers\TraitRLSManager; use Stancl\Tenancy\Bootstrappers\PostgresRLSBootstrapper; use Stancl\Tenancy\Database\Concerns\BelongsToPrimaryModel; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { TraitRLSManager::$implicitRLS = true; diff --git a/tests/RequestDataIdentificationTest.php b/tests/RequestDataIdentificationTest.php index 70792adb..f04d99a7 100644 --- a/tests/RequestDataIdentificationTest.php +++ b/tests/RequestDataIdentificationTest.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Route; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByRequestDataException; use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { config([ diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index 34a6ba14..a1870e86 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -43,6 +43,7 @@ use Stancl\Tenancy\ResourceSyncing\Events\CentralResourceDetachedFromTenant; use Stancl\Tenancy\Tests\Etc\ResourceSyncing\CentralUser as BaseCentralUser; use Stancl\Tenancy\ResourceSyncing\CentralResourceNotAvailableInPivotException; use Stancl\Tenancy\ResourceSyncing\Events\SyncedResourceSavedInForeignDatabase; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { config(['tenancy.bootstrappers' => [ diff --git a/tests/ScopeSessionsTest.php b/tests/ScopeSessionsTest.php index 5a8a9e51..e62fa370 100644 --- a/tests/ScopeSessionsTest.php +++ b/tests/ScopeSessionsTest.php @@ -8,6 +8,7 @@ use Stancl\Tenancy\Exceptions\TenancyNotInitializedException; use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain; use Stancl\Tenancy\Middleware\ScopeSessions; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { Route::group([ diff --git a/tests/SessionSeparationTest.php b/tests/SessionSeparationTest.php index 6706a18e..02b018d1 100644 --- a/tests/SessionSeparationTest.php +++ b/tests/SessionSeparationTest.php @@ -23,6 +23,7 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Middleware\InitializeTenancyByPath; use Stancl\Tenancy\Middleware\PreventAccessFromUnwantedDomains; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; // todo@tests write similar low-level tests for the cache bootstrapper? including the database driver in a single-db setup diff --git a/tests/SingleDatabaseTenancyTest.php b/tests/SingleDatabaseTenancyTest.php index c71e6d38..c0d3aef3 100644 --- a/tests/SingleDatabaseTenancyTest.php +++ b/tests/SingleDatabaseTenancyTest.php @@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Stancl\Tenancy\Database\Concerns\BelongsToTenant; use Stancl\Tenancy\Database\Concerns\BelongsToPrimaryModel; use Stancl\Tenancy\Database\Concerns\HasScopedValidationRules; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { Schema::create('posts', function (Blueprint $table) { diff --git a/tests/SingleDomainTenantTest.php b/tests/SingleDomainTenantTest.php index 3a68ee8b..49bd7d95 100644 --- a/tests/SingleDomainTenantTest.php +++ b/tests/SingleDomainTenantTest.php @@ -11,6 +11,7 @@ use Illuminate\Database\UniqueConstraintViolationException; use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException; use Stancl\Tenancy\Middleware\PreventAccessFromUnwantedDomains; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { config(['tenancy.models.tenant' => SingleDomainTenant::class]); diff --git a/tests/SubdomainTest.php b/tests/SubdomainTest.php index 9ddc48ba..a7cc58ae 100644 --- a/tests/SubdomainTest.php +++ b/tests/SubdomainTest.php @@ -7,6 +7,7 @@ use Stancl\Tenancy\Database\Concerns\HasDomains; use Stancl\Tenancy\Exceptions\NotASubdomainException; use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain; use Stancl\Tenancy\Database\Models; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { // Global state cleanup after some tests diff --git a/tests/TenantAssetTest.php b/tests/TenantAssetTest.php index bcdc701b..5c223fe2 100644 --- a/tests/TenantAssetTest.php +++ b/tests/TenantAssetTest.php @@ -19,6 +19,7 @@ use Stancl\Tenancy\Controllers\TenantAssetController; use Stancl\Tenancy\Events\TenancyEnded; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Overrides\TenancyUrlGenerator; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { config(['tenancy.bootstrappers' => [ diff --git a/tests/TenantAwareCommandTest.php b/tests/TenantAwareCommandTest.php index fe49685e..764e5a9b 100644 --- a/tests/TenantAwareCommandTest.php +++ b/tests/TenantAwareCommandTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Stancl\Tenancy\Tests\Etc\Tenant; +use function Stancl\Tenancy\Tests\pest; test('commands run globally are tenant aware and return valid exit code', function () { $tenant1 = Tenant::create(); diff --git a/tests/TenantDatabaseManagerTest.php b/tests/TenantDatabaseManagerTest.php index b10d5ac3..c41ea35a 100644 --- a/tests/TenantDatabaseManagerTest.php +++ b/tests/TenantDatabaseManagerTest.php @@ -28,6 +28,7 @@ use Stancl\Tenancy\Database\TenantDatabaseManagers\PermissionControlledMySQLData use Stancl\Tenancy\Database\TenantDatabaseManagers\PermissionControlledPostgreSQLSchemaManager; use Stancl\Tenancy\Database\TenantDatabaseManagers\PermissionControlledPostgreSQLDatabaseManager; use Stancl\Tenancy\Database\TenantDatabaseManagers\PermissionControlledMicrosoftSQLServerDatabaseManager; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { SQLiteDatabaseManager::$path = null; diff --git a/tests/TenantModelTest.php b/tests/TenantModelTest.php index f6e04cbb..796f92f4 100644 --- a/tests/TenantModelTest.php +++ b/tests/TenantModelTest.php @@ -22,6 +22,7 @@ use Stancl\Tenancy\Exceptions\TenancyNotInitializedException; use Stancl\Tenancy\UniqueIdentifierGenerators\RandomHexGenerator; use Stancl\Tenancy\UniqueIdentifierGenerators\RandomIntGenerator; use Stancl\Tenancy\UniqueIdentifierGenerators\RandomStringGenerator; +use function Stancl\Tenancy\Tests\pest; afterEach(function () { RandomIntGenerator::$min = 0; diff --git a/tests/TenantUserImpersonationTest.php b/tests/TenantUserImpersonationTest.php index 8d4f5794..8c9c4124 100644 --- a/tests/TenantUserImpersonationTest.php +++ b/tests/TenantUserImpersonationTest.php @@ -25,6 +25,7 @@ use Stancl\Tenancy\Middleware\InitializeTenancyByPath; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Exceptions\StatefulGuardRequiredException; +use function Stancl\Tenancy\Tests\pest; beforeEach(function () { pest()->artisan('migrate', [ diff --git a/tests/TestCase.php b/tests/TestCase.php index 7fc1813b..6a167c46 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -23,6 +23,7 @@ use Stancl\Tenancy\Bootstrappers\UrlGeneratorBootstrapper; use Stancl\Tenancy\Bootstrappers\BroadcastingConfigBootstrapper; use Stancl\Tenancy\Bootstrappers\BroadcastChannelPrefixBootstrapper; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; +use function Stancl\Tenancy\Tests\pest; abstract class TestCase extends \Orchestra\Testbench\TestCase { diff --git a/tests/UniversalRouteTest.php b/tests/UniversalRouteTest.php index 528d46bf..c8df0ab0 100644 --- a/tests/UniversalRouteTest.php +++ b/tests/UniversalRouteTest.php @@ -2,8 +2,6 @@ declare(strict_types=1); -use Stancl\Tenancy\Tenancy; -use Illuminate\Http\Request; use Stancl\Tenancy\Enums\RouteMode; use Stancl\Tenancy\Tests\Etc\Tenant; use Illuminate\Contracts\Http\Kernel; @@ -11,16 +9,14 @@ use Stancl\Tenancy\Resolvers\PathTenantResolver; use Illuminate\Routing\Controller as BaseController; use Illuminate\Support\Facades\Route as RouteFacade; use Stancl\Tenancy\Tests\Etc\HasMiddlewareController; -use Stancl\Tenancy\Middleware\IdentificationMiddleware; -use Stancl\Tenancy\Resolvers\RequestDataTenantResolver; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; -use Stancl\Tenancy\Concerns\UsableWithEarlyIdentification; use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain; use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData; use Stancl\Tenancy\Middleware\PreventAccessFromUnwantedDomains; use Stancl\Tenancy\Middleware\InitializeTenancyByDomainOrSubdomain; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByRequestDataException; +use function Stancl\Tenancy\Tests\pest; test('a route can be universal using domain identification', function (array $routeMiddleware, array $globalMiddleware) { foreach ($globalMiddleware as $middleware) {