From 8bd7c95fffa235400044962416af704d53c07cb4 Mon Sep 17 00:00:00 2001 From: Abrar Ahmad Date: Thu, 30 Jun 2022 13:12:34 +0500 Subject: [PATCH] removed `uses` from individual files and add it in `Pest` --- tests/AutomaticModeTest.php | 2 - tests/BootstrapperTest.php | 2 - tests/CacheManagerTest.php | 2 - tests/CachedTenantResolverTest.php | 2 - ...edDomainAndSubdomainIdentificationTest.php | 2 - tests/CommandsTest.php | 2 - tests/DatabasePreparationTest.php | 2 - tests/DatabaseUsersTest.php | 2 - tests/DomainTest.php | 2 - tests/EventListenerTest.php | 2 - tests/GlobalCacheTest.php | 2 - tests/MaintenanceModeTest.php | 2 - tests/PathIdentificationTest.php | 2 - tests/Pest.php | 41 +------------------ tests/QueueTest.php | 2 - tests/RequestDataIdentificationTest.php | 2 - tests/ResourceSyncingTest.php | 2 - tests/ScopeSessionsTest.php | 2 - tests/SingleDatabaseTenancyTest.php | 2 - tests/SubdomainTest.php | 2 - tests/TenantAssetTest.php | 2 - tests/TenantAwareCommandTest.php | 2 - tests/TenantDatabaseManagerTest.php | 2 - tests/TenantModelTest.php | 2 - tests/TenantUserImpersonationTest.php | 2 - tests/UniversalRouteTest.php | 4 +- 26 files changed, 2 insertions(+), 91 deletions(-) diff --git a/tests/AutomaticModeTest.php b/tests/AutomaticModeTest.php index 81d61863..f83a797a 100644 --- a/tests/AutomaticModeTest.php +++ b/tests/AutomaticModeTest.php @@ -10,8 +10,6 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class); diff --git a/tests/BootstrapperTest.php b/tests/BootstrapperTest.php index 90a98056..07c66647 100644 --- a/tests/BootstrapperTest.php +++ b/tests/BootstrapperTest.php @@ -22,8 +22,6 @@ use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { Event::listen( TenantCreated::class, diff --git a/tests/CacheManagerTest.php b/tests/CacheManagerTest.php index 19bfa566..7b34a7df 100644 --- a/tests/CacheManagerTest.php +++ b/tests/CacheManagerTest.php @@ -8,8 +8,6 @@ use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { config(['tenancy.bootstrappers' => [ CacheTenancyBootstrapper::class, diff --git a/tests/CachedTenantResolverTest.php b/tests/CachedTenantResolverTest.php index f8d1dbe1..e386ad57 100644 --- a/tests/CachedTenantResolverTest.php +++ b/tests/CachedTenantResolverTest.php @@ -6,8 +6,6 @@ use Illuminate\Support\Facades\DB; use Stancl\Tenancy\Resolvers\DomainTenantResolver; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - afterEach(function () { DomainTenantResolver::$shouldCache = false; }); diff --git a/tests/CombinedDomainAndSubdomainIdentificationTest.php b/tests/CombinedDomainAndSubdomainIdentificationTest.php index 5b6e2a43..b78cf48e 100644 --- a/tests/CombinedDomainAndSubdomainIdentificationTest.php +++ b/tests/CombinedDomainAndSubdomainIdentificationTest.php @@ -7,8 +7,6 @@ use Stancl\Tenancy\Database\Concerns\HasDomains; use Stancl\Tenancy\Middleware\InitializeTenancyByDomainOrSubdomain; use Stancl\Tenancy\Database\Models; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { Route::group([ 'middleware' => InitializeTenancyByDomainOrSubdomain::class, diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 8994520c..f601c4f0 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -17,8 +17,6 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Tests\Etc\ExampleSeeder; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) { return $event->tenant; diff --git a/tests/DatabasePreparationTest.php b/tests/DatabasePreparationTest.php index f66ebf1e..64fa1e0f 100644 --- a/tests/DatabasePreparationTest.php +++ b/tests/DatabasePreparationTest.php @@ -14,8 +14,6 @@ use Stancl\Tenancy\Tests\Etc\Tenant; use Illuminate\Foundation\Auth\User as Authenticable; use Stancl\Tenancy\Tests\Etc\TestSeeder; -uses(Stancl\Tenancy\Tests\TestCase::class); - test('database can be created after tenant creation', function () { config(['tenancy.database.template_tenant_connection' => 'mysql']); diff --git a/tests/DatabaseUsersTest.php b/tests/DatabaseUsersTest.php index b2c1cea8..93ac7ec3 100644 --- a/tests/DatabaseUsersTest.php +++ b/tests/DatabaseUsersTest.php @@ -18,8 +18,6 @@ use Stancl\Tenancy\TenantDatabaseManagers\MySQLDatabaseManager; use Stancl\Tenancy\TenantDatabaseManagers\PermissionControlledMySQLDatabaseManager; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { config([ 'tenancy.database.managers.mysql' => PermissionControlledMySQLDatabaseManager::class, diff --git a/tests/DomainTest.php b/tests/DomainTest.php index e041dffd..b87d4f4d 100644 --- a/tests/DomainTest.php +++ b/tests/DomainTest.php @@ -11,8 +11,6 @@ use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Resolvers\DomainTenantResolver; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { Route::group([ 'middleware' => InitializeTenancyByDomain::class, diff --git a/tests/EventListenerTest.php b/tests/EventListenerTest.php index 02dcc38b..66dcedc8 100644 --- a/tests/EventListenerTest.php +++ b/tests/EventListenerTest.php @@ -20,8 +20,6 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\QueueableListener; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - test('listeners can be synchronous', function () { Queue::fake(); Event::listen(TenantCreated::class, FooListener::class); diff --git a/tests/GlobalCacheTest.php b/tests/GlobalCacheTest.php index db7d4417..add5fd2b 100644 --- a/tests/GlobalCacheTest.php +++ b/tests/GlobalCacheTest.php @@ -11,8 +11,6 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { config(['tenancy.bootstrappers' => [ CacheTenancyBootstrapper::class, diff --git a/tests/MaintenanceModeTest.php b/tests/MaintenanceModeTest.php index 41b8bb4b..bd459504 100644 --- a/tests/MaintenanceModeTest.php +++ b/tests/MaintenanceModeTest.php @@ -9,8 +9,6 @@ use Stancl\Tenancy\Middleware\CheckTenantForMaintenanceMode; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - test('tenant can be in maintenance mode', function () { Route::get('/foo', function () { return 'bar'; diff --git a/tests/PathIdentificationTest.php b/tests/PathIdentificationTest.php index 8ad93918..4cd793d7 100644 --- a/tests/PathIdentificationTest.php +++ b/tests/PathIdentificationTest.php @@ -9,8 +9,6 @@ use Stancl\Tenancy\Middleware\InitializeTenancyByPath; use Stancl\Tenancy\Resolvers\PathTenantResolver; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { PathTenantResolver::$tenantParameterName = 'tenant'; diff --git a/tests/Pest.php b/tests/Pest.php index 2e0dcbfb..9325cf53 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,42 +1,3 @@ in('Etc', 'Features'); - -/* -|-------------------------------------------------------------------------- -| Test Case -|-------------------------------------------------------------------------- -| -| The closure you provide to your test functions is always bound to a specific PHPUnit test -| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may -| need to change it using the "uses()" function to bind a different classes or traits. -| -*/ - -/** @link https://pestphp.com/docs/underlying-test-case */ - -/* -|-------------------------------------------------------------------------- -| Expectations -|-------------------------------------------------------------------------- -| -| When you're writing tests, you often need to check that values meet certain conditions. The -| "expect()" function gives you access to a set of "expectations" methods that you can use -| to assert different things. Of course, you may extend the Expectation API at any time. -| -*/ - -/** @link https://pestphp.com/docs/expectations#custom-expectations */ - -/* -|-------------------------------------------------------------------------- -| Functions -|-------------------------------------------------------------------------- -| -| While Pest is very powerful out-of-the-box, you may have some testing code specific to your -| project that you don't want to repeat in every file. Here you can also expose helpers as -| global functions to help you to reduce the number of lines of code in your test files. -| -*/ - -/** @link https://pestphp.com/docs/helpers */ +uses(Stancl\Tenancy\Tests\TestCase::class)->in(__DIR__); diff --git a/tests/QueueTest.php b/tests/QueueTest.php index eb1963d5..88e9ab10 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -27,8 +27,6 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { config([ 'tenancy.bootstrappers' => [ diff --git a/tests/RequestDataIdentificationTest.php b/tests/RequestDataIdentificationTest.php index 46b880b4..81bdda53 100644 --- a/tests/RequestDataIdentificationTest.php +++ b/tests/RequestDataIdentificationTest.php @@ -6,8 +6,6 @@ use Illuminate\Support\Facades\Route; use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { config([ 'tenancy.central_domains' => [ diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index c78f6838..82789a74 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -28,8 +28,6 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Listeners\UpdateSyncedResource; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { config(['tenancy.bootstrappers' => [ DatabaseTenancyBootstrapper::class, diff --git a/tests/ScopeSessionsTest.php b/tests/ScopeSessionsTest.php index 9e8eedb0..b1b6a05e 100644 --- a/tests/ScopeSessionsTest.php +++ b/tests/ScopeSessionsTest.php @@ -11,8 +11,6 @@ use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain; use Stancl\Tenancy\Middleware\ScopeSessions; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { Route::group([ 'middleware' => [StartSession::class, InitializeTenancyBySubdomain::class, ScopeSessions::class], diff --git a/tests/SingleDatabaseTenancyTest.php b/tests/SingleDatabaseTenancyTest.php index 2010df24..553c801f 100644 --- a/tests/SingleDatabaseTenancyTest.php +++ b/tests/SingleDatabaseTenancyTest.php @@ -12,8 +12,6 @@ use Stancl\Tenancy\Database\Concerns\BelongsToTenant; use Stancl\Tenancy\Database\Concerns\HasScopedValidationRules; use Stancl\Tenancy\Tests\Etc\Tenant as TestTenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { BelongsToTenant::$tenantIdColumn = 'tenant_id'; diff --git a/tests/SubdomainTest.php b/tests/SubdomainTest.php index 10f3833c..bab67b52 100644 --- a/tests/SubdomainTest.php +++ b/tests/SubdomainTest.php @@ -8,8 +8,6 @@ use Stancl\Tenancy\Exceptions\NotASubdomainException; use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain; use Stancl\Tenancy\Database\Models; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { // Global state cleanup after some tests InitializeTenancyBySubdomain::$onFail = null; diff --git a/tests/TenantAssetTest.php b/tests/TenantAssetTest.php index bb140ea5..c101e610 100644 --- a/tests/TenantAssetTest.php +++ b/tests/TenantAssetTest.php @@ -13,8 +13,6 @@ use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { config(['tenancy.bootstrappers' => [ FilesystemTenancyBootstrapper::class, diff --git a/tests/TenantAwareCommandTest.php b/tests/TenantAwareCommandTest.php index 06d31616..1332ccfd 100644 --- a/tests/TenantAwareCommandTest.php +++ b/tests/TenantAwareCommandTest.php @@ -6,8 +6,6 @@ use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - test('commands run globally are tenant aware and return valid exit code', function () { $tenant1 = Tenant::create(); $tenant2 = Tenant::create(); diff --git a/tests/TenantDatabaseManagerTest.php b/tests/TenantDatabaseManagerTest.php index b2997661..b7687eca 100644 --- a/tests/TenantDatabaseManagerTest.php +++ b/tests/TenantDatabaseManagerTest.php @@ -24,8 +24,6 @@ use Stancl\Tenancy\TenantDatabaseManagers\PostgreSQLSchemaManager; use Stancl\Tenancy\TenantDatabaseManagers\SQLiteDatabaseManager; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - test('databases can be created and deleted', function ($driver, $databaseManager) { Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) { return $event->tenant; diff --git a/tests/TenantModelTest.php b/tests/TenantModelTest.php index e26696b3..cbfa0ec8 100644 --- a/tests/TenantModelTest.php +++ b/tests/TenantModelTest.php @@ -19,8 +19,6 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\UUIDGenerator; -uses(Stancl\Tenancy\Tests\TestCase::class); - test('created event is dispatched', function () { Event::fake([TenantCreated::class]); diff --git a/tests/TenantUserImpersonationTest.php b/tests/TenantUserImpersonationTest.php index 6f7d7de6..be792a7f 100644 --- a/tests/TenantUserImpersonationTest.php +++ b/tests/TenantUserImpersonationTest.php @@ -24,8 +24,6 @@ use Stancl\Tenancy\Middleware\InitializeTenancyByPath; use Stancl\Tenancy\Tests\Etc\Tenant; use Illuminate\Foundation\Auth\User as Authenticable; -uses(Stancl\Tenancy\Tests\TestCase::class); - beforeEach(function () { $this->artisan('migrate', [ '--path' => __DIR__ . '/../assets/impersonation-migrations', diff --git a/tests/UniversalRouteTest.php b/tests/UniversalRouteTest.php index cb0600de..04d053cf 100644 --- a/tests/UniversalRouteTest.php +++ b/tests/UniversalRouteTest.php @@ -7,8 +7,6 @@ use Stancl\Tenancy\Features\UniversalRoutes; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Tests\Etc\Tenant; -uses(Stancl\Tenancy\Tests\TestCase::class); - afterEach(function () { InitializeTenancyByDomain::$onFail = null; }); @@ -67,7 +65,7 @@ test('making one route universal doesnt make all routes universal', function () $this->get('http://acme.localhost/foo') ->assertSuccessful() ->assertSee('Tenancy is initialized.'); - + tenancy()->end(); $this->get('http://localhost/bar')