mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 10:54:04 +00:00
Change @test annotations to #[Test] attributes
This commit is contained in:
parent
f9f28c9d26
commit
5fa5c3b7dd
29 changed files with 179 additions and 165 deletions
|
|
@ -20,7 +20,7 @@
|
|||
},
|
||||
"require-dev": {
|
||||
"laravel/framework": "^10.0|^11.0|^12.0",
|
||||
"orchestra/testbench": "^8.0|^9.0|10.3",
|
||||
"orchestra/testbench": "^8.0|^9.0|^10.0",
|
||||
"league/flysystem-aws-s3-v3": "^3.12.2",
|
||||
"doctrine/dbal": "^3.6.0",
|
||||
"spatie/valuestore": "^1.3.2"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\Events\TenancyEnded;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
|
|
@ -22,7 +23,7 @@ class AutomaticModeTest extends TestCase
|
|||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function context_is_switched_when_tenancy_is_initialized()
|
||||
{
|
||||
config(['tenancy.bootstrappers' => [
|
||||
|
|
@ -38,7 +39,7 @@ class AutomaticModeTest extends TestCase
|
|||
$this->assertSame('acme', app('tenancy_initialized_for_tenant'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function context_is_reverted_when_tenancy_is_ended()
|
||||
{
|
||||
$this->context_is_switched_when_tenancy_is_initialized();
|
||||
|
|
@ -48,7 +49,7 @@ class AutomaticModeTest extends TestCase
|
|||
$this->assertSame(true, app('tenancy_ended'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function context_is_switched_when_tenancy_is_reinitialized()
|
||||
{
|
||||
config(['tenancy.bootstrappers' => [
|
||||
|
|
@ -72,7 +73,7 @@ class AutomaticModeTest extends TestCase
|
|||
$this->assertSame('foobar', app('tenancy_initialized_for_tenant'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function central_helper_runs_callbacks_in_the_central_state()
|
||||
{
|
||||
tenancy()->initialize($tenant = Tenant::create());
|
||||
|
|
@ -84,7 +85,7 @@ class AutomaticModeTest extends TestCase
|
|||
$this->assertSame($tenant, tenant());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function central_helper_returns_the_value_from_the_callback()
|
||||
{
|
||||
tenancy()->initialize(Tenant::create());
|
||||
|
|
@ -94,7 +95,7 @@ class AutomaticModeTest extends TestCase
|
|||
}));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function central_helper_reverts_back_to_tenant_context()
|
||||
{
|
||||
tenancy()->initialize($tenant = Tenant::create());
|
||||
|
|
@ -106,7 +107,7 @@ class AutomaticModeTest extends TestCase
|
|||
$this->assertSame($tenant, tenant());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function central_helper_doesnt_change_tenancy_state_when_called_in_central_context()
|
||||
{
|
||||
$this->assertFalse(tenancy()->initialized);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use Illuminate\Support\Facades\Cache;
|
|||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Events\TenancyEnded;
|
||||
use Stancl\Tenancy\Jobs\CreateDatabase;
|
||||
use Stancl\Tenancy\Events\TenantCreated;
|
||||
|
|
@ -45,7 +46,7 @@ class BootstrapperTest extends TestCase
|
|||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function database_data_is_separated()
|
||||
{
|
||||
config(['tenancy.bootstrappers' => [
|
||||
|
|
@ -78,7 +79,7 @@ class BootstrapperTest extends TestCase
|
|||
$this->assertSame('Foo', DB::table('users')->first()->name);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function cache_data_is_separated()
|
||||
{
|
||||
config([
|
||||
|
|
@ -121,7 +122,7 @@ class BootstrapperTest extends TestCase
|
|||
$this->assertSame('central', Cache::get('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function redis_data_is_separated()
|
||||
{
|
||||
config(['tenancy.bootstrappers' => [
|
||||
|
|
@ -152,7 +153,7 @@ class BootstrapperTest extends TestCase
|
|||
$this->assertSame(null, Redis::get('abc'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function filesystem_data_is_separated()
|
||||
{
|
||||
config(['tenancy.bootstrappers' => [
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||
|
|
@ -23,7 +24,7 @@ class CacheManagerTest extends TestCase
|
|||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function default_tag_is_automatically_applied()
|
||||
{
|
||||
tenancy()->initialize(Tenant::create());
|
||||
|
|
@ -31,7 +32,7 @@ class CacheManagerTest extends TestCase
|
|||
$this->assertArrayIsSubset([config('tenancy.cache.tag_base') . tenant('id')], cache()->tags('foo')->getTags()->getNames());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tags_are_merged_when_array_is_passed()
|
||||
{
|
||||
tenancy()->initialize(Tenant::create());
|
||||
|
|
@ -40,7 +41,7 @@ class CacheManagerTest extends TestCase
|
|||
$this->assertEquals($expected, cache()->tags(['foo', 'bar'])->getTags()->getNames());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tags_are_merged_when_string_is_passed()
|
||||
{
|
||||
tenancy()->initialize(Tenant::create());
|
||||
|
|
@ -49,7 +50,7 @@ class CacheManagerTest extends TestCase
|
|||
$this->assertEquals($expected, cache()->tags('foo')->getTags()->getNames());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function exception_is_thrown_when_zero_arguments_are_passed_to_tags_method()
|
||||
{
|
||||
tenancy()->initialize(Tenant::create());
|
||||
|
|
@ -58,7 +59,7 @@ class CacheManagerTest extends TestCase
|
|||
cache()->tags();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function exception_is_thrown_when_more_than_one_argument_is_passed_to_tags_method()
|
||||
{
|
||||
tenancy()->initialize(Tenant::create());
|
||||
|
|
@ -67,7 +68,7 @@ class CacheManagerTest extends TestCase
|
|||
cache()->tags(1, 2);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tags_separate_cache_well_enough()
|
||||
{
|
||||
$tenant1 = Tenant::create();
|
||||
|
|
@ -85,7 +86,7 @@ class CacheManagerTest extends TestCase
|
|||
$this->assertSame('xyz', cache()->get('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function invoking_the_cache_helper_works()
|
||||
{
|
||||
$tenant1 = Tenant::create();
|
||||
|
|
@ -103,7 +104,7 @@ class CacheManagerTest extends TestCase
|
|||
$this->assertSame('xyz', cache('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function cache_is_persisted()
|
||||
{
|
||||
$tenant1 = Tenant::create();
|
||||
|
|
@ -118,7 +119,7 @@ class CacheManagerTest extends TestCase
|
|||
$this->assertSame('bar', cache('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function cache_is_persisted_when_reidentification_is_used()
|
||||
{
|
||||
$tenant1 = Tenant::create();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException;
|
||||
use Stancl\Tenancy\Resolvers\DomainTenantResolver;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
|
|
@ -18,7 +19,7 @@ class CachedTenantResolverTest extends TestCase
|
|||
parent::tearDown();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenants_can_be_resolved_using_the_cached_resolver()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -30,7 +31,7 @@ class CachedTenantResolverTest extends TestCase
|
|||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function the_underlying_resolver_is_not_touched_when_using_the_cached_resolver()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -55,7 +56,7 @@ class CachedTenantResolverTest extends TestCase
|
|||
$this->assertEmpty(DB::getQueryLog()); // empty
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function cache_is_invalidated_when_the_tenant_is_updated()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -81,7 +82,7 @@ class CachedTenantResolverTest extends TestCase
|
|||
$this->assertNotEmpty(DB::getQueryLog()); // not empty
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function cache_is_invalidated_when_the_tenant_is_deleted()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -108,7 +109,7 @@ class CachedTenantResolverTest extends TestCase
|
|||
$this->assertNotEmpty(DB::getQueryLog()); // not empty - cache cleared so the DB was queried
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function cache_is_invalidated_when_a_tenants_domain_is_changed()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -138,7 +139,7 @@ class CachedTenantResolverTest extends TestCase
|
|||
$this->assertNotEmpty(DB::getQueryLog()); // not empty
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function cache_is_invalidated_when_a_tenants_domain_is_deleted()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Database\Concerns\HasDomains;
|
||||
use Stancl\Tenancy\Database\Models;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyByDomainOrSubdomain;
|
||||
|
|
@ -26,7 +27,7 @@ class CombinedDomainAndSubdomainIdentificationTest extends TestCase
|
|||
config(['tenancy.tenant_model' => CombinedTenant::class]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_can_be_identified_by_subdomain()
|
||||
{
|
||||
config(['tenancy.central_domains' => ['localhost']]);
|
||||
|
|
@ -49,7 +50,7 @@ class CombinedDomainAndSubdomainIdentificationTest extends TestCase
|
|||
$this->assertSame('acme', tenant('id'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_can_be_identified_by_domain()
|
||||
{
|
||||
config(['tenancy.central_domains' => []]);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Artisan;
|
|||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Events\TenancyEnded;
|
||||
|
|
@ -47,7 +48,7 @@ class CommandsTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function migrate_command_doesnt_change_the_db_connection()
|
||||
{
|
||||
$this->assertFalse(Schema::hasTable('users'));
|
||||
|
|
@ -61,7 +62,7 @@ class CommandsTest extends TestCase
|
|||
$this->assertNotEquals('tenant', $new_connection_name);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function migrate_command_works_without_options()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -75,7 +76,7 @@ class CommandsTest extends TestCase
|
|||
$this->assertTrue(Schema::hasTable('users'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function migrate_command_works_with_tenants_option()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -91,7 +92,7 @@ class CommandsTest extends TestCase
|
|||
$this->assertTrue(Schema::hasTable('users'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function rollback_command_works()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -105,13 +106,13 @@ class CommandsTest extends TestCase
|
|||
$this->assertFalse(Schema::hasTable('users'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function seed_command_works()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function database_connection_is_switched_to_default()
|
||||
{
|
||||
$originalDBName = DB::connection()->getDatabaseName();
|
||||
|
|
@ -129,7 +130,7 @@ class CommandsTest extends TestCase
|
|||
$this->assertSame($originalDBName, DB::connection()->getDatabaseName());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function database_connection_is_switched_to_default_when_tenancy_has_been_initialized()
|
||||
{
|
||||
tenancy()->initialize(Tenant::create());
|
||||
|
|
@ -137,7 +138,7 @@ class CommandsTest extends TestCase
|
|||
$this->database_connection_is_switched_to_default();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function run_commands_works()
|
||||
{
|
||||
$id = Tenant::create()->getTenantKey();
|
||||
|
|
@ -150,7 +151,7 @@ class CommandsTest extends TestCase
|
|||
->expectsOutput('xyz');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function install_command_works()
|
||||
{
|
||||
if (! is_dir($dir = app_path('Http'))) {
|
||||
|
|
@ -169,7 +170,7 @@ class CommandsTest extends TestCase
|
|||
$this->assertDirectoryExists(database_path('migrations/tenant'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function migrate_fresh_command_works()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -191,7 +192,7 @@ class CommandsTest extends TestCase
|
|||
$this->assertFalse(DB::table('users')->exists());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function run_command_with_array_of_tenants_works()
|
||||
{
|
||||
$tenantId1 = Tenant::create()->getTenantKey();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use Illuminate\Foundation\Auth\User as Authenticable;
|
|||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Stancl\Tenancy\Events\TenantCreated;
|
||||
use Stancl\Tenancy\Jobs\CreateDatabase;
|
||||
|
|
@ -19,7 +20,7 @@ use Stancl\Tenancy\Tests\Etc\Tenant;
|
|||
|
||||
class DatabasePreparationTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function database_can_be_created_after_tenant_creation()
|
||||
{
|
||||
config(['tenancy.database.template_tenant_connection' => 'mysql']);
|
||||
|
|
@ -36,7 +37,7 @@ class DatabasePreparationTest extends TestCase
|
|||
$this->assertTrue($manager->databaseExists($tenant->database()->getName()));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function database_can_be_migrated_after_tenant_creation()
|
||||
{
|
||||
Event::listen(TenantCreated::class, JobPipeline::make([
|
||||
|
|
@ -53,7 +54,7 @@ class DatabasePreparationTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function database_can_be_seeded_after_tenant_creation()
|
||||
{
|
||||
config(['tenancy.seeder_parameters' => [
|
||||
|
|
@ -75,7 +76,7 @@ class DatabasePreparationTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function custom_job_can_be_added_to_the_pipeline()
|
||||
{
|
||||
config(['tenancy.seeder_parameters' => [
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ namespace Stancl\Tenancy\Tests;
|
|||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Str;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Contracts\ManagesDatabaseUsers;
|
||||
|
|
@ -37,7 +38,7 @@ class DatabaseUsersTest extends TestCase
|
|||
})->toListener());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function users_are_created_when_permission_controlled_mysql_manager_is_used()
|
||||
{
|
||||
$tenant = new Tenant([
|
||||
|
|
@ -54,7 +55,7 @@ class DatabaseUsersTest extends TestCase
|
|||
$this->assertTrue($manager->userExists($tenant->database()->getUsername()));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function a_tenants_database_cannot_be_created_when_the_user_already_exists()
|
||||
{
|
||||
$username = 'foo' . Str::random(8);
|
||||
|
|
@ -82,7 +83,7 @@ class DatabaseUsersTest extends TestCase
|
|||
Event::assertNotDispatched(DatabaseCreated::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function correct_grants_are_given_to_users()
|
||||
{
|
||||
PermissionControlledMySQLDatabaseManager::$grants = [
|
||||
|
|
@ -97,7 +98,7 @@ class DatabaseUsersTest extends TestCase
|
|||
$this->assertStringStartsWith('GRANT CREATE, ALTER, ALTER ROUTINE ON', $query->{"Grants for {$user}@%"}); // @mysql because that's the hostname within the docker network
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function having_existing_databases_without_users_and_switching_to_permission_controlled_mysql_manager_doesnt_break_existing_dbs()
|
||||
{
|
||||
config([
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Database\Concerns\HasDomains;
|
||||
use Stancl\Tenancy\Database\Models;
|
||||
use Stancl\Tenancy\Database\Models\Domain;
|
||||
|
|
@ -30,7 +31,7 @@ class DomainTest extends TestCase
|
|||
config(['tenancy.tenant_model' => DomainTenant::class]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_can_be_identified_using_hostname()
|
||||
{
|
||||
$tenant = DomainTenant::create();
|
||||
|
|
@ -47,7 +48,7 @@ class DomainTest extends TestCase
|
|||
$this->assertSame(['foo.localhost'], $resolvedTenant->domains->pluck('domain')->toArray());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function a_domain_can_belong_to_only_one_tenant()
|
||||
{
|
||||
$tenant = DomainTenant::create();
|
||||
|
|
@ -64,7 +65,7 @@ class DomainTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function an_exception_is_thrown_if_tenant_cannot_be_identified()
|
||||
{
|
||||
$this->expectException(TenantCouldNotBeIdentifiedOnDomainException::class);
|
||||
|
|
@ -72,7 +73,7 @@ class DomainTest extends TestCase
|
|||
app(DomainTenantResolver::class)->resolve('foo.localhost');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_can_be_identified_by_domain()
|
||||
{
|
||||
$tenant = DomainTenant::create([
|
||||
|
|
@ -93,7 +94,7 @@ class DomainTest extends TestCase
|
|||
$this->assertSame('acme', tenant('id'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function onfail_logic_can_be_customized()
|
||||
{
|
||||
InitializeTenancyByDomain::$onFail = function () {
|
||||
|
|
@ -105,7 +106,7 @@ class DomainTest extends TestCase
|
|||
->assertSee('foo');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function domains_are_always_lowercase()
|
||||
{
|
||||
$tenant = DomainTenant::create();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ namespace Stancl\Tenancy\Tests;
|
|||
use Illuminate\Events\CallQueuedListener;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper;
|
||||
|
|
@ -20,12 +21,11 @@ use Stancl\Tenancy\Jobs\CreateDatabase;
|
|||
use Stancl\Tenancy\Jobs\MigrateDatabase;
|
||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||
use Stancl\Tenancy\Listeners\QueueableListener;
|
||||
use Stancl\Tenancy\Tenancy;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
|
||||
class EventListenerTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function listeners_can_be_synchronous()
|
||||
{
|
||||
Queue::fake();
|
||||
|
|
@ -38,7 +38,7 @@ class EventListenerTest extends TestCase
|
|||
$this->assertSame('bar', app('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function listeners_can_be_queued_by_setting_a_static_property()
|
||||
{
|
||||
Queue::fake();
|
||||
|
|
@ -55,7 +55,7 @@ class EventListenerTest extends TestCase
|
|||
$this->assertFalse(app()->bound('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function ing_events_can_be_used_to_cancel_tenant_model_actions()
|
||||
{
|
||||
Event::listen(CreatingTenant::class, function () {
|
||||
|
|
@ -66,7 +66,7 @@ class EventListenerTest extends TestCase
|
|||
$this->assertSame(0, Tenant::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function ing_events_can_be_used_to_cancel_domain_model_actions()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -86,7 +86,7 @@ class EventListenerTest extends TestCase
|
|||
$this->assertSame('acme', $domain->refresh()->domain);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function ing_events_can_be_used_to_cancel_db_creation()
|
||||
{
|
||||
Event::listen(CreatingDatabase::class, function (CreatingDatabase $event) {
|
||||
|
|
@ -101,7 +101,7 @@ class EventListenerTest extends TestCase
|
|||
));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function ing_events_can_be_used_to_cancel_tenancy_bootstrapping()
|
||||
{
|
||||
config(['tenancy.bootstrappers' => [
|
||||
|
|
@ -129,7 +129,7 @@ class EventListenerTest extends TestCase
|
|||
$this->assertSame([DatabaseTenancyBootstrapper::class], array_map('get_class', tenancy()->getBootstrappers()));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function individual_job_pipelines_can_terminate_while_leaving_others_running()
|
||||
{
|
||||
$executed = [];
|
||||
|
|
@ -176,7 +176,7 @@ class EventListenerTest extends TestCase
|
|||
], $executed);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function database_is_not_migrated_if_creation_is_disabled()
|
||||
{
|
||||
Event::listen(
|
||||
|
|
|
|||
|
|
@ -5,13 +5,14 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests\Features;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Features\CrossDomainRedirect;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Stancl\Tenancy\Tests\TestCase;
|
||||
|
||||
class RedirectTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_redirect_macro_replaces_only_the_hostname()
|
||||
{
|
||||
config([
|
||||
|
|
@ -33,7 +34,7 @@ class RedirectTest extends TestCase
|
|||
->assertRedirect('http://abcd/foobar');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_route_helper_generates_correct_url()
|
||||
{
|
||||
Route::get('/abcdef/{a?}/{b?}', function () {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests\Features;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Events\TenancyEnded;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
use Stancl\Tenancy\Features\TenantConfig;
|
||||
|
|
@ -22,7 +23,7 @@ class TenantConfigTest extends TestCase
|
|||
parent::tearDown();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function nested_tenant_values_are_merged()
|
||||
{
|
||||
$this->assertSame(null, config('whitelabel.theme'));
|
||||
|
|
@ -46,7 +47,7 @@ class TenantConfigTest extends TestCase
|
|||
tenancy()->end();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function config_is_merged_and_removed()
|
||||
{
|
||||
$this->assertSame(null, config('services.paypal'));
|
||||
|
|
@ -77,7 +78,7 @@ class TenantConfigTest extends TestCase
|
|||
], config('services.paypal'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function the_value_can_be_set_to_multiple_config_keys()
|
||||
{
|
||||
$this->assertSame(null, config('services.paypal'));
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Features\ViteBundler;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Stancl\Tenancy\Tests\TestCase;
|
||||
|
|
@ -9,7 +10,7 @@ use Stancl\Tenancy\Vite as StanclVite;
|
|||
|
||||
class ViteBundlerTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function the_vite_helper_uses_our_custom_class()
|
||||
{
|
||||
$vite = app(\Illuminate\Foundation\Vite::class);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Events\TenancyEnded;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
|
|
@ -27,7 +28,7 @@ class GlobalCacheTest extends TestCase
|
|||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function global_cache_manager_stores_data_in_global_cache()
|
||||
{
|
||||
$this->assertSame(null, cache('foo'));
|
||||
|
|
|
|||
|
|
@ -5,17 +5,16 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Database\Concerns\MaintenanceMode;
|
||||
use Stancl\Tenancy\Middleware\CheckTenantForMaintenanceMode;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
|
||||
|
||||
class MaintenanceModeTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_can_be_in_maintenance_mode()
|
||||
{
|
||||
Route::get('/foo', function () {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Exceptions\RouteIsMissingTenantParameterException;
|
||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByPathException;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyByPath;
|
||||
|
|
@ -37,7 +38,7 @@ class PathIdentificationTest extends TestCase
|
|||
PathTenantResolver::$tenantParameterName = 'tenant';
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_can_be_identified_by_path()
|
||||
{
|
||||
Tenant::create([
|
||||
|
|
@ -52,7 +53,7 @@ class PathIdentificationTest extends TestCase
|
|||
$this->assertSame('acme', tenant('id'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function route_actions_dont_get_the_tenant_id()
|
||||
{
|
||||
Tenant::create([
|
||||
|
|
@ -69,7 +70,7 @@ class PathIdentificationTest extends TestCase
|
|||
$this->assertSame('acme', tenant('id'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function exception_is_thrown_when_tenant_cannot_be_identified_by_path()
|
||||
{
|
||||
$this->expectException(TenantCouldNotBeIdentifiedByPathException::class);
|
||||
|
|
@ -81,7 +82,7 @@ class PathIdentificationTest extends TestCase
|
|||
$this->assertFalse(tenancy()->initialized);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function onfail_logic_can_be_customized()
|
||||
{
|
||||
InitializeTenancyByPath::$onFail = function () {
|
||||
|
|
@ -93,7 +94,7 @@ class PathIdentificationTest extends TestCase
|
|||
->assertContent('foo');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function an_exception_is_thrown_when_the_routes_first_parameter_is_not_tenant()
|
||||
{
|
||||
Route::group([
|
||||
|
|
@ -116,7 +117,7 @@ class PathIdentificationTest extends TestCase
|
|||
->get('/bar/foo/bar');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_parameter_name_can_be_customized()
|
||||
{
|
||||
PathTenantResolver::$tenantParameterName = 'team';
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ use Illuminate\Queue\Events\JobProcessed;
|
|||
use Illuminate\Queue\Events\JobProcessing;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\TestWith;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||
|
|
@ -108,7 +110,7 @@ class QueueTest extends TestCase
|
|||
})->toListener());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_id_is_passed_to_tenant_queues()
|
||||
{
|
||||
config(['queue.default' => 'sync']);
|
||||
|
|
@ -126,7 +128,7 @@ class QueueTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_id_is_not_passed_to_central_queues()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -147,12 +149,7 @@ class QueueTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @testWith [true]
|
||||
* [false]
|
||||
*/
|
||||
#[Test] #[TestWith([true, false])]
|
||||
public function tenancy_is_initialized_inside_queues(bool $shouldEndTenancy)
|
||||
{
|
||||
$this->withTenantDatabases();
|
||||
|
|
@ -187,12 +184,7 @@ class QueueTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @testWith [true]
|
||||
* [false]
|
||||
*/
|
||||
#[Test] #[TestWith([true, false])]
|
||||
public function tenancy_is_initialized_when_retrying_jobs(bool $shouldEndTenancy)
|
||||
{
|
||||
$this->withFailedJobs();
|
||||
|
|
@ -234,7 +226,7 @@ class QueueTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function the_tenant_used_by_the_job_doesnt_change_when_the_current_tenant_changes()
|
||||
{
|
||||
$tenant1 = Tenant::create([
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ class RequestDataIdentificationTest extends TestCase
|
|||
parent::tearDown();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function header_identification_works()
|
||||
{
|
||||
InitializeTenancyByRequestData::$header = 'X-Tenant';
|
||||
|
|
@ -48,7 +49,7 @@ class RequestDataIdentificationTest extends TestCase
|
|||
->assertSee($tenant->id);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function query_parameter_identification_works()
|
||||
{
|
||||
InitializeTenancyByRequestData::$header = null;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use Illuminate\Events\CallQueuedListener;
|
|||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Str;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Contracts\Syncable;
|
||||
|
|
@ -71,7 +72,7 @@ class ResourceSyncingTest extends TestCase
|
|||
])->assertExitCode(0);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function an_event_is_triggered_when_a_synced_resource_is_changed()
|
||||
{
|
||||
Event::fake([SyncedResourceSaved::class]);
|
||||
|
|
@ -89,7 +90,7 @@ class ResourceSyncingTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function only_the_synced_columns_are_updated_in_the_central_db()
|
||||
{
|
||||
// Create user in central DB
|
||||
|
|
@ -145,7 +146,7 @@ class ResourceSyncingTest extends TestCase
|
|||
], ResourceUser::first()->getAttributes());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function creating_the_resource_in_tenant_database_creates_it_in_central_database_and_creates_the_mapping()
|
||||
{
|
||||
// Assert no user in central DB
|
||||
|
|
@ -180,7 +181,7 @@ class ResourceSyncingTest extends TestCase
|
|||
$this->assertSame('commenter', ResourceUser::first()->role);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function trying_to_update_synced_resources_from_central_context_using_tenant_models_results_in_an_exception()
|
||||
{
|
||||
$this->creating_the_resource_in_tenant_database_creates_it_in_central_database_and_creates_the_mapping();
|
||||
|
|
@ -192,7 +193,7 @@ class ResourceSyncingTest extends TestCase
|
|||
ResourceUser::first()->update(['role' => 'foobar']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function attaching_a_tenant_to_the_central_resource_triggers_a_pull_from_the_tenant_db()
|
||||
{
|
||||
$centralUser = CentralUser::create([
|
||||
|
|
@ -219,7 +220,7 @@ class ResourceSyncingTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function attaching_users_to_tenants_DOES_NOT_DO_ANYTHING()
|
||||
{
|
||||
$centralUser = CentralUser::create([
|
||||
|
|
@ -248,7 +249,7 @@ class ResourceSyncingTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function resources_are_synced_only_to_workspaces_that_have_the_resource()
|
||||
{
|
||||
$centralUser = CentralUser::create([
|
||||
|
|
@ -292,7 +293,7 @@ class ResourceSyncingTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function when_a_resource_exists_in_other_tenant_dbs_but_is_CREATED_in_a_tenant_db_the_synced_columns_are_updated_in_the_other_dbs()
|
||||
{
|
||||
// create shared resource
|
||||
|
|
@ -339,7 +340,7 @@ class ResourceSyncingTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function the_synced_columns_are_updated_in_other_tenant_dbs_where_the_resource_exists()
|
||||
{
|
||||
// create shared resource
|
||||
|
|
@ -392,7 +393,7 @@ class ResourceSyncingTest extends TestCase
|
|||
$this->assertSame('commenter', $centralUser->role); // unsynced
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function global_id_is_generated_using_id_generator_when_its_not_supplied()
|
||||
{
|
||||
$user = CentralUser::create([
|
||||
|
|
@ -405,7 +406,7 @@ class ResourceSyncingTest extends TestCase
|
|||
$this->assertNotNull($user->global_id);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function when_the_resource_doesnt_exist_in_the_tenant_db_non_synced_columns_will_cascade_too()
|
||||
{
|
||||
$centralUser = CentralUser::create([
|
||||
|
|
@ -428,7 +429,7 @@ class ResourceSyncingTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function when_the_resource_doesnt_exist_in_the_central_db_non_synced_columns_will_bubble_up_too()
|
||||
{
|
||||
$t1 = ResourceTenant::create([
|
||||
|
|
@ -449,7 +450,7 @@ class ResourceSyncingTest extends TestCase
|
|||
$this->assertSame('employee', CentralUser::first()->role);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function the_listener_can_be_queued()
|
||||
{
|
||||
Queue::fake();
|
||||
|
|
@ -477,7 +478,7 @@ class ResourceSyncingTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function an_event_is_fired_for_all_touched_resources()
|
||||
{
|
||||
Event::fake([SyncedResourceChangedInForeignDatabase::class]);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ namespace Stancl\Tenancy\Tests;
|
|||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Events\TenantCreated;
|
||||
use Stancl\Tenancy\Exceptions\TenancyNotInitializedException;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain;
|
||||
|
|
@ -37,7 +38,7 @@ class ScopeSessionsTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_id_is_auto_added_to_session_if_its_missing()
|
||||
{
|
||||
$tenant = Tenant::create([
|
||||
|
|
@ -48,7 +49,7 @@ class ScopeSessionsTest extends TestCase
|
|||
->assertSessionHas(ScopeSessions::$tenantIdKey, 'acme');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function changing_tenant_id_in_session_will_abort_the_request()
|
||||
{
|
||||
$tenant = Tenant::create([
|
||||
|
|
@ -64,7 +65,7 @@ class ScopeSessionsTest extends TestCase
|
|||
->assertStatus(403);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function an_exception_is_thrown_when_the_middleware_is_executed_before_tenancy_is_initialized()
|
||||
{
|
||||
Route::get('/bar', function () {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use Illuminate\Database\QueryException;
|
|||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Database\Concerns\BelongsToPrimaryModel;
|
||||
use Stancl\Tenancy\Database\Concerns\BelongsToTenant;
|
||||
use Stancl\Tenancy\Database\Concerns\HasScopedValidationRules;
|
||||
|
|
@ -43,7 +44,7 @@ class SingleDatabaseTenancyTest extends TestCase
|
|||
config(['tenancy.tenant_model' => Tenant::class]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function primary_models_are_scoped_to_the_current_tenant()
|
||||
{
|
||||
// acme context
|
||||
|
|
@ -90,7 +91,7 @@ class SingleDatabaseTenancyTest extends TestCase
|
|||
$this->assertSame(1, Post::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function primary_models_are_not_scoped_in_the_central_context()
|
||||
{
|
||||
$this->primary_models_are_scoped_to_the_current_tenant();
|
||||
|
|
@ -100,7 +101,7 @@ class SingleDatabaseTenancyTest extends TestCase
|
|||
$this->assertSame(2, Post::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function secondary_models_are_scoped_to_the_current_tenant_when_accessed_via_primary_model()
|
||||
{
|
||||
// acme context
|
||||
|
|
@ -127,7 +128,7 @@ class SingleDatabaseTenancyTest extends TestCase
|
|||
$this->assertSame(1, Post::first()->comments->count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function secondary_models_are_NOT_scoped_to_the_current_tenant_when_accessed_directly()
|
||||
{
|
||||
$this->secondary_models_are_scoped_to_the_current_tenant_when_accessed_via_primary_model();
|
||||
|
|
@ -138,7 +139,7 @@ class SingleDatabaseTenancyTest extends TestCase
|
|||
$this->assertSame(2, Comment::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function secondary_models_ARE_scoped_to_the_current_tenant_when_accessed_directly_AND_PARENT_RELATIONSHIP_TRAIT_IS_USED()
|
||||
{
|
||||
$acme = Tenant::create([
|
||||
|
|
@ -172,7 +173,7 @@ class SingleDatabaseTenancyTest extends TestCase
|
|||
$this->assertSame(2, ScopedComment::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function secondary_models_are_NOT_scoped_in_the_central_context()
|
||||
{
|
||||
$this->secondary_models_are_scoped_to_the_current_tenant_when_accessed_via_primary_model();
|
||||
|
|
@ -182,7 +183,7 @@ class SingleDatabaseTenancyTest extends TestCase
|
|||
$this->assertSame(2, Comment::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function global_models_are_not_scoped_at_all()
|
||||
{
|
||||
Schema::create('global_resources', function (Blueprint $table) {
|
||||
|
|
@ -207,7 +208,7 @@ class SingleDatabaseTenancyTest extends TestCase
|
|||
$this->assertSame(4, GlobalResource::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_id_and_relationship_is_auto_added_when_creating_primary_resources_in_tenant_context()
|
||||
{
|
||||
tenancy()->initialize($acme = Tenant::create([
|
||||
|
|
@ -222,7 +223,7 @@ class SingleDatabaseTenancyTest extends TestCase
|
|||
$this->assertSame(tenant(), $post->tenant);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_id_is_not_auto_added_when_creating_primary_resources_in_central_context()
|
||||
{
|
||||
$this->expectException(QueryException::class);
|
||||
|
|
@ -230,7 +231,7 @@ class SingleDatabaseTenancyTest extends TestCase
|
|||
Post::create(['text' => 'Foo']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_id_column_name_can_be_customized()
|
||||
{
|
||||
BelongsToTenant::$tenantIdColumn = 'team_id';
|
||||
|
|
@ -280,7 +281,7 @@ class SingleDatabaseTenancyTest extends TestCase
|
|||
$this->assertSame(1, Post::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function the_model_returned_by_the_tenant_helper_has_unique_and_exists_validation_rules()
|
||||
{
|
||||
Schema::table('posts', function (Blueprint $table) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Database\Concerns\HasDomains;
|
||||
use Stancl\Tenancy\Database\Models;
|
||||
use Stancl\Tenancy\Exceptions\NotASubdomainException;
|
||||
|
|
@ -30,7 +31,7 @@ class SubdomainTest extends TestCase
|
|||
config(['tenancy.tenant_model' => SubdomainTenant::class]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_can_be_identified_by_subdomain()
|
||||
{
|
||||
$tenant = SubdomainTenant::create([
|
||||
|
|
@ -51,7 +52,7 @@ class SubdomainTest extends TestCase
|
|||
$this->assertSame('acme', tenant('id'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function onfail_logic_can_be_customized()
|
||||
{
|
||||
InitializeTenancyBySubdomain::$onFail = function () {
|
||||
|
|
@ -63,7 +64,7 @@ class SubdomainTest extends TestCase
|
|||
->assertSee('foo');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function localhost_is_not_a_valid_subdomain()
|
||||
{
|
||||
$this->expectException(NotASubdomainException::class);
|
||||
|
|
@ -73,7 +74,7 @@ class SubdomainTest extends TestCase
|
|||
->get('http://localhost/foo/abc/xyz');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function ip_address_is_not_a_valid_subdomain()
|
||||
{
|
||||
$this->expectException(NotASubdomainException::class);
|
||||
|
|
@ -83,7 +84,7 @@ class SubdomainTest extends TestCase
|
|||
->get('http://127.0.0.1/foo/abc/xyz');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function oninvalidsubdomain_logic_can_be_customized()
|
||||
{
|
||||
// in this case, we need to return a response instance
|
||||
|
|
@ -102,7 +103,7 @@ class SubdomainTest extends TestCase
|
|||
->assertSee('foo custom invalid subdomain handler');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function we_cant_use_a_subdomain_that_doesnt_belong_to_our_central_domains()
|
||||
{
|
||||
config(['tenancy.central_domains' => [
|
||||
|
|
@ -125,7 +126,7 @@ class SubdomainTest extends TestCase
|
|||
->get('http://foo.localhost/foo/abc/xyz');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function central_domain_is_not_a_subdomain()
|
||||
{
|
||||
config(['tenancy.central_domains' => [
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ namespace Stancl\Tenancy\Tests;
|
|||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Controllers\TenantAssetsController;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
|
|
@ -49,7 +50,7 @@ class TenantAssetTest extends TestCase
|
|||
TenantAssetsController::$tenancyMiddleware = InitializeTenancyByDomain::class;
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function asset_can_be_accessed_using_the_url_returned_by_the_tenant_asset_helper()
|
||||
{
|
||||
TenantAssetsController::$tenancyMiddleware = InitializeTenancyByRequestData::class;
|
||||
|
|
@ -77,7 +78,7 @@ class TenantAssetTest extends TestCase
|
|||
$this->assertSame('bar', $content);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function asset_helper_returns_a_link_to_TenantAssetController_when_asset_url_is_null()
|
||||
{
|
||||
config(['app.asset_url' => null]);
|
||||
|
|
@ -88,7 +89,7 @@ class TenantAssetTest extends TestCase
|
|||
$this->assertSame(route('stancl.tenancy.asset', ['path' => 'foo']), asset('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function asset_helper_returns_a_link_to_an_external_url_when_asset_url_is_not_null()
|
||||
{
|
||||
config(['app.asset_url' => 'https://an-s3-bucket']);
|
||||
|
|
@ -99,7 +100,7 @@ class TenantAssetTest extends TestCase
|
|||
$this->assertSame("https://an-s3-bucket/tenant{$tenant->id}/foo", asset('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function global_asset_helper_returns_the_same_url_regardless_of_tenancy_initialization()
|
||||
{
|
||||
$original = global_asset('foobar');
|
||||
|
|
@ -111,7 +112,7 @@ class TenantAssetTest extends TestCase
|
|||
$this->assertSame($original, global_asset('foobar'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function asset_helper_tenancy_can_be_disabled()
|
||||
{
|
||||
$original = asset('foo');
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ namespace Stancl\Tenancy\Tests;
|
|||
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
|
||||
class TenantAwareCommandTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function commands_run_globally_are_tenant_aware_and_return_valid_exit_code()
|
||||
{
|
||||
$tenant1 = Tenant::create();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ use Illuminate\Support\Facades\Event;
|
|||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Database\DatabaseManager;
|
||||
|
|
@ -28,10 +30,7 @@ use Stancl\Tenancy\Tests\Etc\Tenant;
|
|||
|
||||
class TenantDatabaseManagerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider database_manager_provider
|
||||
*/
|
||||
#[Test] #[DataProvider('database_manager_provider')]
|
||||
public function databases_can_be_created_and_deleted($driver, $databaseManager)
|
||||
{
|
||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
||||
|
|
@ -59,7 +58,7 @@ class TenantDatabaseManagerTest extends TestCase
|
|||
$this->assertFalse($manager->databaseExists($name));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function dbs_can_be_created_when_another_driver_is_used_for_the_central_db()
|
||||
{
|
||||
$this->assertSame('central', config('database.default'));
|
||||
|
|
@ -106,7 +105,7 @@ class TenantDatabaseManagerTest extends TestCase
|
|||
];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function the_tenant_connection_is_fully_removed()
|
||||
{
|
||||
config([
|
||||
|
|
@ -152,7 +151,7 @@ class TenantDatabaseManagerTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function db_name_is_prefixed_with_db_path_when_sqlite_is_used()
|
||||
{
|
||||
if (file_exists(database_path('foodb'))) {
|
||||
|
|
@ -171,7 +170,7 @@ class TenantDatabaseManagerTest extends TestCase
|
|||
$this->assertSame(config('database.connections.tenant.database'), database_path('foodb'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function schema_manager_uses_schema_to_separate_tenant_dbs()
|
||||
{
|
||||
config([
|
||||
|
|
@ -200,7 +199,7 @@ class TenantDatabaseManagerTest extends TestCase
|
|||
$this->assertSame($originalDatabaseName, config(['database.connections.pgsql.database']));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function a_tenants_database_cannot_be_created_when_the_database_already_exists()
|
||||
{
|
||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
||||
|
|
@ -221,7 +220,7 @@ class TenantDatabaseManagerTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_database_can_be_created_on_a_foreign_server()
|
||||
{
|
||||
config([
|
||||
|
|
@ -266,7 +265,7 @@ class TenantDatabaseManagerTest extends TestCase
|
|||
$this->assertTrue($manager->databaseExists($name));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function path_used_by_sqlite_manager_can_be_customized()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use Illuminate\Database\Schema\Blueprint;
|
|||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Contracts;
|
||||
|
|
@ -23,7 +24,7 @@ use Stancl\Tenancy\UUIDGenerator;
|
|||
|
||||
class TenantModelTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function created_event_is_dispatched()
|
||||
{
|
||||
Event::fake([TenantCreated::class]);
|
||||
|
|
@ -35,7 +36,7 @@ class TenantModelTest extends TestCase
|
|||
Event::assertDispatched(TenantCreated::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function current_tenant_can_be_resolved_from_service_container_using_typehint()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
|
|
@ -49,7 +50,7 @@ class TenantModelTest extends TestCase
|
|||
$this->assertSame(null, app(Contracts\Tenant::class));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function id_is_generated_when_no_id_is_supplied()
|
||||
{
|
||||
config(['tenancy.id_generator' => UUIDGenerator::class]);
|
||||
|
|
@ -63,7 +64,7 @@ class TenantModelTest extends TestCase
|
|||
$this->assertNotNull($tenant->id);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function autoincrement_ids_are_supported()
|
||||
{
|
||||
Schema::drop('domains');
|
||||
|
|
@ -80,7 +81,7 @@ class TenantModelTest extends TestCase
|
|||
$this->assertSame(2, $tenant2->id);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function custom_tenant_model_can_be_used()
|
||||
{
|
||||
$tenant = MyTenant::create();
|
||||
|
|
@ -90,7 +91,7 @@ class TenantModelTest extends TestCase
|
|||
$this->assertTrue(tenant() instanceof MyTenant);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function custom_tenant_model_that_doesnt_extend_vendor_Tenant_model_can_be_used()
|
||||
{
|
||||
$tenant = AnotherTenant::create([
|
||||
|
|
@ -102,7 +103,7 @@ class TenantModelTest extends TestCase
|
|||
$this->assertTrue(tenant() instanceof AnotherTenant);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_can_be_created_even_when_we_are_in_another_tenants_context()
|
||||
{
|
||||
config(['tenancy.bootstrappers' => [
|
||||
|
|
@ -131,7 +132,7 @@ class TenantModelTest extends TestCase
|
|||
$this->assertSame(2, Tenant::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function the_model_uses_TenantCollection()
|
||||
{
|
||||
Tenant::create();
|
||||
|
|
@ -141,7 +142,7 @@ class TenantModelTest extends TestCase
|
|||
$this->assertTrue(Tenant::all() instanceof TenantCollection);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function a_command_can_be_run_on_a_collection_of_tenants()
|
||||
{
|
||||
Tenant::create([
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use Illuminate\Support\Facades\Auth;
|
|||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Str;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||
use Stancl\Tenancy\Database\Models\ImpersonationToken;
|
||||
|
|
@ -89,7 +90,7 @@ class TenantUserImpersonationTest extends TestCase
|
|||
};
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_user_can_be_impersonated_on_a_tenant_domain()
|
||||
{
|
||||
Route::middleware(InitializeTenancyByDomain::class)->group($this->getRoutes());
|
||||
|
|
@ -122,7 +123,7 @@ class TenantUserImpersonationTest extends TestCase
|
|||
->assertSee('You are logged in as Joe');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tenant_user_can_be_impersonated_on_a_tenant_path()
|
||||
{
|
||||
$this->makeLoginRoute();
|
||||
|
|
@ -157,7 +158,7 @@ class TenantUserImpersonationTest extends TestCase
|
|||
->assertSee('You are logged in as Joe');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tokens_have_a_limited_ttl()
|
||||
{
|
||||
Route::middleware(InitializeTenancyByDomain::class)->group($this->getRoutes());
|
||||
|
|
@ -186,7 +187,7 @@ class TenantUserImpersonationTest extends TestCase
|
|||
->assertStatus(403);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tokens_are_deleted_after_use()
|
||||
{
|
||||
Route::middleware(InitializeTenancyByDomain::class)->group($this->getRoutes());
|
||||
|
|
@ -217,7 +218,7 @@ class TenantUserImpersonationTest extends TestCase
|
|||
$this->assertNull(ImpersonationToken::find($token->token));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function impersonation_works_with_multiple_models_and_guards()
|
||||
{
|
||||
config([
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Stancl\Tenancy\Features\UniversalRoutes;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
|
|
@ -18,7 +19,7 @@ class UniversalRouteTest extends TestCase
|
|||
parent::tearDown();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function a_route_can_work_in_both_central_and_tenant_context()
|
||||
{
|
||||
Route::middlewareGroup('universal', []);
|
||||
|
|
@ -46,7 +47,7 @@ class UniversalRouteTest extends TestCase
|
|||
->assertSee('Tenancy is initialized.');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function making_one_route_universal_doesnt_make_all_routes_universal()
|
||||
{
|
||||
Route::get('/bar', function () {
|
||||
|
|
@ -64,7 +65,7 @@ class UniversalRouteTest extends TestCase
|
|||
->assertSee('acme');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function universal_route_works_when_middleware_is_inserted_via_controller_middleware()
|
||||
{
|
||||
Route::middlewareGroup('universal', []);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue