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

removed uses from individual files and add it in Pest

This commit is contained in:
Abrar Ahmad 2022-06-30 13:12:34 +05:00
parent e7d0bbf302
commit 8bd7c95fff
26 changed files with 2 additions and 91 deletions

View file

@ -10,8 +10,6 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
Event::listen(TenancyEnded::class, RevertToCentralContext::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class);

View file

@ -22,8 +22,6 @@ use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
Event::listen( Event::listen(
TenantCreated::class, TenantCreated::class,

View file

@ -8,8 +8,6 @@ use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
config(['tenancy.bootstrappers' => [ config(['tenancy.bootstrappers' => [
CacheTenancyBootstrapper::class, CacheTenancyBootstrapper::class,

View file

@ -6,8 +6,6 @@ use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Resolvers\DomainTenantResolver; use Stancl\Tenancy\Resolvers\DomainTenantResolver;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
afterEach(function () { afterEach(function () {
DomainTenantResolver::$shouldCache = false; DomainTenantResolver::$shouldCache = false;
}); });

View file

@ -7,8 +7,6 @@ use Stancl\Tenancy\Database\Concerns\HasDomains;
use Stancl\Tenancy\Middleware\InitializeTenancyByDomainOrSubdomain; use Stancl\Tenancy\Middleware\InitializeTenancyByDomainOrSubdomain;
use Stancl\Tenancy\Database\Models; use Stancl\Tenancy\Database\Models;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
Route::group([ Route::group([
'middleware' => InitializeTenancyByDomainOrSubdomain::class, 'middleware' => InitializeTenancyByDomainOrSubdomain::class,

View file

@ -17,8 +17,6 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Tests\Etc\ExampleSeeder; use Stancl\Tenancy\Tests\Etc\ExampleSeeder;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) { Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
return $event->tenant; return $event->tenant;

View file

@ -14,8 +14,6 @@ use Stancl\Tenancy\Tests\Etc\Tenant;
use Illuminate\Foundation\Auth\User as Authenticable; use Illuminate\Foundation\Auth\User as Authenticable;
use Stancl\Tenancy\Tests\Etc\TestSeeder; use Stancl\Tenancy\Tests\Etc\TestSeeder;
uses(Stancl\Tenancy\Tests\TestCase::class);
test('database can be created after tenant creation', function () { test('database can be created after tenant creation', function () {
config(['tenancy.database.template_tenant_connection' => 'mysql']); config(['tenancy.database.template_tenant_connection' => 'mysql']);

View file

@ -18,8 +18,6 @@ use Stancl\Tenancy\TenantDatabaseManagers\MySQLDatabaseManager;
use Stancl\Tenancy\TenantDatabaseManagers\PermissionControlledMySQLDatabaseManager; use Stancl\Tenancy\TenantDatabaseManagers\PermissionControlledMySQLDatabaseManager;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
config([ config([
'tenancy.database.managers.mysql' => PermissionControlledMySQLDatabaseManager::class, 'tenancy.database.managers.mysql' => PermissionControlledMySQLDatabaseManager::class,

View file

@ -11,8 +11,6 @@ use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException;
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
use Stancl\Tenancy\Resolvers\DomainTenantResolver; use Stancl\Tenancy\Resolvers\DomainTenantResolver;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
Route::group([ Route::group([
'middleware' => InitializeTenancyByDomain::class, 'middleware' => InitializeTenancyByDomain::class,

View file

@ -20,8 +20,6 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\QueueableListener; use Stancl\Tenancy\Listeners\QueueableListener;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
test('listeners can be synchronous', function () { test('listeners can be synchronous', function () {
Queue::fake(); Queue::fake();
Event::listen(TenantCreated::class, FooListener::class); Event::listen(TenantCreated::class, FooListener::class);

View file

@ -11,8 +11,6 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
config(['tenancy.bootstrappers' => [ config(['tenancy.bootstrappers' => [
CacheTenancyBootstrapper::class, CacheTenancyBootstrapper::class,

View file

@ -9,8 +9,6 @@ use Stancl\Tenancy\Middleware\CheckTenantForMaintenanceMode;
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
test('tenant can be in maintenance mode', function () { test('tenant can be in maintenance mode', function () {
Route::get('/foo', function () { Route::get('/foo', function () {
return 'bar'; return 'bar';

View file

@ -9,8 +9,6 @@ use Stancl\Tenancy\Middleware\InitializeTenancyByPath;
use Stancl\Tenancy\Resolvers\PathTenantResolver; use Stancl\Tenancy\Resolvers\PathTenantResolver;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
PathTenantResolver::$tenantParameterName = 'tenant'; PathTenantResolver::$tenantParameterName = 'tenant';

View file

@ -1,42 +1,3 @@
<?php <?php
uses(\Stancl\Tenancy\Tests\TestCase::class)->in('Etc', 'Features'); uses(Stancl\Tenancy\Tests\TestCase::class)->in(__DIR__);
/*
|--------------------------------------------------------------------------
| 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 */

View file

@ -27,8 +27,6 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
config([ config([
'tenancy.bootstrappers' => [ 'tenancy.bootstrappers' => [

View file

@ -6,8 +6,6 @@ use Illuminate\Support\Facades\Route;
use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData; use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
config([ config([
'tenancy.central_domains' => [ 'tenancy.central_domains' => [

View file

@ -28,8 +28,6 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Listeners\UpdateSyncedResource; use Stancl\Tenancy\Listeners\UpdateSyncedResource;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
config(['tenancy.bootstrappers' => [ config(['tenancy.bootstrappers' => [
DatabaseTenancyBootstrapper::class, DatabaseTenancyBootstrapper::class,

View file

@ -11,8 +11,6 @@ use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain;
use Stancl\Tenancy\Middleware\ScopeSessions; use Stancl\Tenancy\Middleware\ScopeSessions;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
Route::group([ Route::group([
'middleware' => [StartSession::class, InitializeTenancyBySubdomain::class, ScopeSessions::class], 'middleware' => [StartSession::class, InitializeTenancyBySubdomain::class, ScopeSessions::class],

View file

@ -12,8 +12,6 @@ use Stancl\Tenancy\Database\Concerns\BelongsToTenant;
use Stancl\Tenancy\Database\Concerns\HasScopedValidationRules; use Stancl\Tenancy\Database\Concerns\HasScopedValidationRules;
use Stancl\Tenancy\Tests\Etc\Tenant as TestTenant; use Stancl\Tenancy\Tests\Etc\Tenant as TestTenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
BelongsToTenant::$tenantIdColumn = 'tenant_id'; BelongsToTenant::$tenantIdColumn = 'tenant_id';

View file

@ -8,8 +8,6 @@ use Stancl\Tenancy\Exceptions\NotASubdomainException;
use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain; use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain;
use Stancl\Tenancy\Database\Models; use Stancl\Tenancy\Database\Models;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
// Global state cleanup after some tests // Global state cleanup after some tests
InitializeTenancyBySubdomain::$onFail = null; InitializeTenancyBySubdomain::$onFail = null;

View file

@ -13,8 +13,6 @@ use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData; use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
config(['tenancy.bootstrappers' => [ config(['tenancy.bootstrappers' => [
FilesystemTenancyBootstrapper::class, FilesystemTenancyBootstrapper::class,

View file

@ -6,8 +6,6 @@ use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Tests\Etc\Tenant; 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 () { test('commands run globally are tenant aware and return valid exit code', function () {
$tenant1 = Tenant::create(); $tenant1 = Tenant::create();
$tenant2 = Tenant::create(); $tenant2 = Tenant::create();

View file

@ -24,8 +24,6 @@ use Stancl\Tenancy\TenantDatabaseManagers\PostgreSQLSchemaManager;
use Stancl\Tenancy\TenantDatabaseManagers\SQLiteDatabaseManager; use Stancl\Tenancy\TenantDatabaseManagers\SQLiteDatabaseManager;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
test('databases can be created and deleted', function ($driver, $databaseManager) { test('databases can be created and deleted', function ($driver, $databaseManager) {
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) { Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
return $event->tenant; return $event->tenant;

View file

@ -19,8 +19,6 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
use Stancl\Tenancy\UUIDGenerator; use Stancl\Tenancy\UUIDGenerator;
uses(Stancl\Tenancy\Tests\TestCase::class);
test('created event is dispatched', function () { test('created event is dispatched', function () {
Event::fake([TenantCreated::class]); Event::fake([TenantCreated::class]);

View file

@ -24,8 +24,6 @@ use Stancl\Tenancy\Middleware\InitializeTenancyByPath;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
use Illuminate\Foundation\Auth\User as Authenticable; use Illuminate\Foundation\Auth\User as Authenticable;
uses(Stancl\Tenancy\Tests\TestCase::class);
beforeEach(function () { beforeEach(function () {
$this->artisan('migrate', [ $this->artisan('migrate', [
'--path' => __DIR__ . '/../assets/impersonation-migrations', '--path' => __DIR__ . '/../assets/impersonation-migrations',

View file

@ -7,8 +7,6 @@ use Stancl\Tenancy\Features\UniversalRoutes;
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
uses(Stancl\Tenancy\Tests\TestCase::class);
afterEach(function () { afterEach(function () {
InitializeTenancyByDomain::$onFail = null; InitializeTenancyByDomain::$onFail = null;
}); });
@ -67,7 +65,7 @@ test('making one route universal doesnt make all routes universal', function ()
$this->get('http://acme.localhost/foo') $this->get('http://acme.localhost/foo')
->assertSuccessful() ->assertSuccessful()
->assertSee('Tenancy is initialized.'); ->assertSee('Tenancy is initialized.');
tenancy()->end(); tenancy()->end();
$this->get('http://localhost/bar') $this->get('http://localhost/bar')