diff --git a/tests/AutomaticModeTest.php b/tests/AutomaticModeTest.php index c34a5dbd..0e9a2a3c 100644 --- a/tests/AutomaticModeTest.php +++ b/tests/AutomaticModeTest.php @@ -28,7 +28,7 @@ test('context is switched when tenancy is initialized', function () { tenancy()->initialize($tenant); - $this->assertSame('acme', app('tenancy_initialized_for_tenant')); + expect(app('tenancy_initialized_for_tenant'))->toBe('acme'); }); test('context is reverted when tenancy is ended', function () { @@ -36,7 +36,7 @@ test('context is reverted when tenancy is ended', function () { tenancy()->end(); - $this->assertSame(true, app('tenancy_ended')); + expect(app('tenancy_ended'))->toBe(true); }); test('context is switched when tenancy is reinitialized', function () { @@ -50,7 +50,7 @@ test('context is switched when tenancy is reinitialized', function () { tenancy()->initialize($tenant); - $this->assertSame('acme', app('tenancy_initialized_for_tenant')); + expect(app('tenancy_initialized_for_tenant'))->toBe('acme'); $tenant2 = Tenant::create([ 'id' => 'foobar', @@ -58,17 +58,17 @@ test('context is switched when tenancy is reinitialized', function () { tenancy()->initialize($tenant2); - $this->assertSame('foobar', app('tenancy_initialized_for_tenant')); + expect(app('tenancy_initialized_for_tenant'))->toBe('foobar'); }); test('central helper runs callbacks in the central state', function () { tenancy()->initialize($tenant = Tenant::create()); tenancy()->central(function () { - $this->assertSame(null, tenant()); + expect(tenant())->toBe(null); }); - $this->assertSame($tenant, tenant()); + expect(tenant())->toBe($tenant); }); test('central helper returns the value from the callback', function () { @@ -86,19 +86,19 @@ test('central helper reverts back to tenant context', function () { // }); - $this->assertSame($tenant, tenant()); + expect(tenant())->toBe($tenant); }); test('central helper doesnt change tenancy state when called in central context', function () { - $this->assertFalse(tenancy()->initialized); - $this->assertNull(tenant()); + expect(tenancy()->initialized)->toBeFalse(); + expect(tenant())->toBeNull(); tenancy()->central(function () { // }); - $this->assertFalse(tenancy()->initialized); - $this->assertNull(tenant()); + expect(tenancy()->initialized)->toBeFalse(); + expect(tenant())->toBeNull(); }); // Helpers diff --git a/tests/BootstrapperTest.php b/tests/BootstrapperTest.php index 8a257438..90a98056 100644 --- a/tests/BootstrapperTest.php +++ b/tests/BootstrapperTest.php @@ -50,21 +50,21 @@ test('database data is separated', function () { // Create Foo user DB::table('users')->insert(['name' => 'Foo', 'email' => 'foo@bar.com', 'password' => 'secret']); - $this->assertCount(1, DB::table('users')->get()); + expect(DB::table('users')->get())->toHaveCount(1); tenancy()->initialize($tenant2); // Assert Foo user is not in this DB - $this->assertCount(0, DB::table('users')->get()); + expect(DB::table('users')->get())->toHaveCount(0); // Create Bar user DB::table('users')->insert(['name' => 'Bar', 'email' => 'bar@bar.com', 'password' => 'secret']); - $this->assertCount(1, DB::table('users')->get()); + expect(DB::table('users')->get())->toHaveCount(1); tenancy()->initialize($tenant1); // Assert Bar user is not in this DB - $this->assertCount(1, DB::table('users')->get()); - $this->assertSame('Foo', DB::table('users')->first()->name); + expect(DB::table('users')->get())->toHaveCount(1); + expect(DB::table('users')->first()->name)->toBe('Foo'); }); test('cache data is separated', function () { @@ -79,33 +79,33 @@ test('cache data is separated', function () { $tenant2 = Tenant::create(); cache()->set('foo', 'central'); - $this->assertSame('central', Cache::get('foo')); + expect(Cache::get('foo'))->toBe('central'); tenancy()->initialize($tenant1); // Assert central cache doesn't leak to tenant context - $this->assertFalse(Cache::has('foo')); + expect(Cache::has('foo'))->toBeFalse(); cache()->set('foo', 'bar'); - $this->assertSame('bar', Cache::get('foo')); + expect(Cache::get('foo'))->toBe('bar'); tenancy()->initialize($tenant2); // Assert one tenant's data doesn't leak to another tenant - $this->assertFalse(Cache::has('foo')); + expect(Cache::has('foo'))->toBeFalse(); cache()->set('foo', 'xyz'); - $this->assertSame('xyz', Cache::get('foo')); + expect(Cache::get('foo'))->toBe('xyz'); tenancy()->initialize($tenant1); // Asset data didn't leak to original tenant - $this->assertSame('bar', Cache::get('foo')); + expect(Cache::get('foo'))->toBe('bar'); tenancy()->end(); // Asset central is still the same - $this->assertSame('central', Cache::get('foo')); + expect(Cache::get('foo'))->toBe('central'); }); test('redis data is separated', function () { @@ -118,23 +118,23 @@ test('redis data is separated', function () { tenancy()->initialize($tenant1); Redis::set('foo', 'bar'); - $this->assertSame('bar', Redis::get('foo')); + expect(Redis::get('foo'))->toBe('bar'); tenancy()->initialize($tenant2); - $this->assertSame(null, Redis::get('foo')); + expect(Redis::get('foo'))->toBe(null); Redis::set('foo', 'xyz'); Redis::set('abc', 'def'); - $this->assertSame('xyz', Redis::get('foo')); - $this->assertSame('def', Redis::get('abc')); + expect(Redis::get('foo'))->toBe('xyz'); + expect(Redis::get('abc'))->toBe('def'); tenancy()->initialize($tenant1); - $this->assertSame('bar', Redis::get('foo')); - $this->assertSame(null, Redis::get('abc')); + expect(Redis::get('foo'))->toBe('bar'); + expect(Redis::get('abc'))->toBe(null); $tenant3 = Tenant::create(); tenancy()->initialize($tenant3); - $this->assertSame(null, Redis::get('foo')); - $this->assertSame(null, Redis::get('abc')); + expect(Redis::get('foo'))->toBe(null); + expect(Redis::get('abc'))->toBe(null); }); test('filesystem data is separated', function () { @@ -154,34 +154,34 @@ test('filesystem data is separated', function () { tenancy()->initialize($tenant1); Storage::disk('public')->put('foo', 'bar'); - $this->assertSame('bar', Storage::disk('public')->get('foo')); + expect(Storage::disk('public')->get('foo'))->toBe('bar'); tenancy()->initialize($tenant2); - $this->assertFalse(Storage::disk('public')->exists('foo')); + expect(Storage::disk('public')->exists('foo'))->toBeFalse(); Storage::disk('public')->put('foo', 'xyz'); Storage::disk('public')->put('abc', 'def'); - $this->assertSame('xyz', Storage::disk('public')->get('foo')); - $this->assertSame('def', Storage::disk('public')->get('abc')); + expect(Storage::disk('public')->get('foo'))->toBe('xyz'); + expect(Storage::disk('public')->get('abc'))->toBe('def'); tenancy()->initialize($tenant1); - $this->assertSame('bar', Storage::disk('public')->get('foo')); - $this->assertFalse(Storage::disk('public')->exists('abc')); + expect(Storage::disk('public')->get('foo'))->toBe('bar'); + expect(Storage::disk('public')->exists('abc'))->toBeFalse(); $tenant3 = Tenant::create(); tenancy()->initialize($tenant3); - $this->assertFalse(Storage::disk('public')->exists('foo')); - $this->assertFalse(Storage::disk('public')->exists('abc')); + expect(Storage::disk('public')->exists('foo'))->toBeFalse(); + expect(Storage::disk('public')->exists('abc'))->toBeFalse(); $expected_storage_path = $old_storage_path . '/tenant' . tenant('id'); // /tenant = suffix base // Check that disk prefixes respect the root_override logic - $this->assertSame($expected_storage_path . '/app/', getDiskPrefix('local')); - $this->assertSame($expected_storage_path . '/app/public/', getDiskPrefix('public')); + expect(getDiskPrefix('local'))->toBe($expected_storage_path . '/app/'); + expect(getDiskPrefix('public'))->toBe($expected_storage_path . '/app/public/'); $this->assertSame('tenant' . tenant('id') . '/', getDiskPrefix('s3'), '/'); // Check suffixing logic $new_storage_path = storage_path(); - $this->assertEquals($expected_storage_path, $new_storage_path); + expect($new_storage_path)->toEqual($expected_storage_path); }); // Helpers diff --git a/tests/CacheManagerTest.php b/tests/CacheManagerTest.php index 563fa6c9..19bfa566 100644 --- a/tests/CacheManagerTest.php +++ b/tests/CacheManagerTest.php @@ -28,14 +28,14 @@ test('tags are merged when array is passed', function () { tenancy()->initialize(Tenant::create()); $expected = [config('tenancy.cache.tag_base') . tenant('id'), 'foo', 'bar']; - $this->assertEquals($expected, cache()->tags(['foo', 'bar'])->getTags()->getNames()); + expect(cache()->tags(['foo', 'bar'])->getTags()->getNames())->toEqual($expected); }); test('tags are merged when string is passed', function () { tenancy()->initialize(Tenant::create()); $expected = [config('tenancy.cache.tag_base') . tenant('id'), 'foo']; - $this->assertEquals($expected, cache()->tags('foo')->getTags()->getNames()); + expect(cache()->tags('foo')->getTags()->getNames())->toEqual($expected); }); test('exception is thrown when zero arguments are passed to tags method', function () { @@ -57,7 +57,7 @@ test('tags separate cache well enough', function () { tenancy()->initialize($tenant1); cache()->put('foo', 'bar', 1); - $this->assertSame('bar', cache()->get('foo')); + expect(cache()->get('foo'))->toBe('bar'); $tenant2 = Tenant::create(); tenancy()->initialize($tenant2); @@ -65,7 +65,7 @@ test('tags separate cache well enough', function () { $this->assertNotSame('bar', cache()->get('foo')); cache()->put('foo', 'xyz', 1); - $this->assertSame('xyz', cache()->get('foo')); + expect(cache()->get('foo'))->toBe('xyz'); }); test('invoking the cache helper works', function () { @@ -73,7 +73,7 @@ test('invoking the cache helper works', function () { tenancy()->initialize($tenant1); cache(['foo' => 'bar'], 1); - $this->assertSame('bar', cache('foo')); + expect(cache('foo'))->toBe('bar'); $tenant2 = Tenant::create(); tenancy()->initialize($tenant2); @@ -81,7 +81,7 @@ test('invoking the cache helper works', function () { $this->assertNotSame('bar', cache('foo')); cache(['foo' => 'xyz'], 1); - $this->assertSame('xyz', cache('foo')); + expect(cache('foo'))->toBe('xyz'); }); test('cache is persisted', function () { @@ -89,12 +89,12 @@ test('cache is persisted', function () { tenancy()->initialize($tenant1); cache(['foo' => 'bar'], 10); - $this->assertSame('bar', cache('foo')); + expect(cache('foo'))->toBe('bar'); tenancy()->end(); tenancy()->initialize($tenant1); - $this->assertSame('bar', cache('foo')); + expect(cache('foo'))->toBe('bar'); }); test('cache is persisted when reidentification is used', function () { @@ -103,11 +103,11 @@ test('cache is persisted when reidentification is used', function () { tenancy()->initialize($tenant1); cache(['foo' => 'bar'], 10); - $this->assertSame('bar', cache('foo')); + expect(cache('foo'))->toBe('bar'); tenancy()->initialize($tenant2); tenancy()->end(); tenancy()->initialize($tenant1); - $this->assertSame('bar', cache('foo')); + expect(cache('foo'))->toBe('bar'); }); diff --git a/tests/CachedTenantResolverTest.php b/tests/CachedTenantResolverTest.php index 8ac93657..f8d1dbe1 100644 --- a/tests/CachedTenantResolverTest.php +++ b/tests/CachedTenantResolverTest.php @@ -18,8 +18,8 @@ test('tenants can be resolved using the cached resolver', function () { 'domain' => 'acme', ]); - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); }); test('the underlying resolver is not touched when using the cached resolver', function () { @@ -32,17 +32,17 @@ test('the underlying resolver is not touched when using the cached resolver', fu DomainTenantResolver::$shouldCache = false; - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); DB::flushQueryLog(); - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); $this->assertNotEmpty(DB::getQueryLog()); // not empty DomainTenantResolver::$shouldCache = true; - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); DB::flushQueryLog(); - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); - $this->assertEmpty(DB::getQueryLog()); // empty + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); + expect(DB::getQueryLog())->toBeEmpty(); // empty }); test('cache is invalidated when the tenant is updated', function () { @@ -55,17 +55,17 @@ test('cache is invalidated when the tenant is updated', function () { DomainTenantResolver::$shouldCache = true; - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); DB::flushQueryLog(); - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); - $this->assertEmpty(DB::getQueryLog()); // empty + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); + expect(DB::getQueryLog())->toBeEmpty(); // empty $tenant->update([ 'foo' => 'bar', ]); DB::flushQueryLog(); - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); $this->assertNotEmpty(DB::getQueryLog()); // not empty }); @@ -79,20 +79,20 @@ test('cache is invalidated when a tenants domain is changed', function () { DomainTenantResolver::$shouldCache = true; - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); DB::flushQueryLog(); - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); - $this->assertEmpty(DB::getQueryLog()); // empty + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); + expect(DB::getQueryLog())->toBeEmpty(); // empty $tenant->createDomain([ 'domain' => 'bar', ]); DB::flushQueryLog(); - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme'))); + expect($tenant->is(app(DomainTenantResolver::class)->resolve('acme')))->toBeTrue(); $this->assertNotEmpty(DB::getQueryLog()); // not empty DB::flushQueryLog(); - $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('bar'))); + expect($tenant->is(app(DomainTenantResolver::class)->resolve('bar')))->toBeTrue(); $this->assertNotEmpty(DB::getQueryLog()); // not empty }); diff --git a/tests/CombinedDomainAndSubdomainIdentificationTest.php b/tests/CombinedDomainAndSubdomainIdentificationTest.php index 9fea8649..75b4430b 100644 --- a/tests/CombinedDomainAndSubdomainIdentificationTest.php +++ b/tests/CombinedDomainAndSubdomainIdentificationTest.php @@ -32,14 +32,14 @@ test('tenant can be identified by subdomain', function () { 'domain' => 'foo', ]); - $this->assertFalse(tenancy()->initialized); + expect(tenancy()->initialized)->toBeFalse(); $this ->get('http://foo.localhost/foo/abc/xyz') ->assertSee('abc + xyz'); - $this->assertTrue(tenancy()->initialized); - $this->assertSame('acme', tenant('id')); + expect(tenancy()->initialized)->toBeTrue(); + expect(tenant('id'))->toBe('acme'); }); test('tenant can be identified by domain', function () { @@ -53,12 +53,12 @@ test('tenant can be identified by domain', function () { 'domain' => 'foobar.localhost', ]); - $this->assertFalse(tenancy()->initialized); + expect(tenancy()->initialized)->toBeFalse(); $this ->get('http://foobar.localhost/foo/abc/xyz') ->assertSee('abc + xyz'); - $this->assertTrue(tenancy()->initialized); - $this->assertSame('acme', tenant('id')); + expect(tenancy()->initialized)->toBeTrue(); + expect(tenant('id'))->toBe('acme'); }); diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index cf722e52..5f23d427 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -40,27 +40,27 @@ afterEach(function () { }); test('migrate command doesnt change the db connection', function () { - $this->assertFalse(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeFalse(); $old_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName(); Artisan::call('tenants:migrate'); $new_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName(); - $this->assertFalse(Schema::hasTable('users')); - $this->assertEquals($old_connection_name, $new_connection_name); + expect(Schema::hasTable('users'))->toBeFalse(); + expect($new_connection_name)->toEqual($old_connection_name); $this->assertNotEquals('tenant', $new_connection_name); }); test('migrate command works without options', function () { $tenant = Tenant::create(); - $this->assertFalse(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeFalse(); Artisan::call('tenants:migrate'); - $this->assertFalse(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeFalse(); tenancy()->initialize($tenant); - $this->assertTrue(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeTrue(); }); test('migrate command works with tenants option', function () { @@ -69,30 +69,30 @@ test('migrate command works with tenants option', function () { '--tenants' => [$tenant['id']], ]); - $this->assertFalse(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeFalse(); tenancy()->initialize(Tenant::create()); - $this->assertFalse(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeFalse(); tenancy()->initialize($tenant); - $this->assertTrue(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeTrue(); }); test('migrate command loads schema state', function () { $tenant = Tenant::create(); - $this->assertFalse(Schema::hasTable('schema_users')); - $this->assertFalse(Schema::hasTable('users')); + expect(Schema::hasTable('schema_users'))->toBeFalse(); + expect(Schema::hasTable('users'))->toBeFalse(); Artisan::call('tenants:migrate --schema-path="tests/Etc/tenant-schema.dump"'); - $this->assertFalse(Schema::hasTable('schema_users')); - $this->assertFalse(Schema::hasTable('users')); + expect(Schema::hasTable('schema_users'))->toBeFalse(); + expect(Schema::hasTable('users'))->toBeFalse(); tenancy()->initialize($tenant); // Check for both tables to see if missing migrations also get executed - $this->assertTrue(Schema::hasTable('schema_users')); - $this->assertTrue(Schema::hasTable('users')); + expect(Schema::hasTable('schema_users'))->toBeTrue(); + expect(Schema::hasTable('users'))->toBeTrue(); }); test('dump command works', function () { @@ -102,19 +102,19 @@ test('dump command works', function () { tenancy()->initialize($tenant); Artisan::call('tenants:dump --path="tests/Etc/tenant-schema-test.dump"'); - $this->assertFileExists('tests/Etc/tenant-schema-test.dump'); + expect('tests/Etc/tenant-schema-test.dump')->toBeFile(); }); test('rollback command works', function () { $tenant = Tenant::create(); Artisan::call('tenants:migrate'); - $this->assertFalse(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeFalse(); tenancy()->initialize($tenant); - $this->assertTrue(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeTrue(); Artisan::call('tenants:rollback'); - $this->assertFalse(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeFalse(); }); test('seed command works', function () { @@ -125,16 +125,16 @@ test('database connection is switched to default', function () { $originalDBName = DB::connection()->getDatabaseName(); Artisan::call('tenants:migrate'); - $this->assertSame($originalDBName, DB::connection()->getDatabaseName()); + expect(DB::connection()->getDatabaseName())->toBe($originalDBName); Artisan::call('tenants:seed', ['--class' => ExampleSeeder::class]); - $this->assertSame($originalDBName, DB::connection()->getDatabaseName()); + expect(DB::connection()->getDatabaseName())->toBe($originalDBName); Artisan::call('tenants:rollback'); - $this->assertSame($originalDBName, DB::connection()->getDatabaseName()); + expect(DB::connection()->getDatabaseName())->toBe($originalDBName); $this->run_commands_works(); - $this->assertSame($originalDBName, DB::connection()->getDatabaseName()); + expect(DB::connection()->getDatabaseName())->toBe($originalDBName); }); test('database connection is switched to default when tenancy has been initialized', function () { @@ -163,32 +163,32 @@ test('install command works', function () { } $this->artisan('tenancy:install'); - $this->assertFileExists(base_path('routes/tenant.php')); - $this->assertFileExists(base_path('config/tenancy.php')); - $this->assertFileExists(app_path('Providers/TenancyServiceProvider.php')); - $this->assertFileExists(database_path('migrations/2019_09_15_000010_create_tenants_table.php')); - $this->assertFileExists(database_path('migrations/2019_09_15_000020_create_domains_table.php')); - $this->assertDirectoryExists(database_path('migrations/tenant')); + expect(base_path('routes/tenant.php'))->toBeFile(); + expect(base_path('config/tenancy.php'))->toBeFile(); + expect(app_path('Providers/TenancyServiceProvider.php'))->toBeFile(); + expect(database_path('migrations/2019_09_15_000010_create_tenants_table.php'))->toBeFile(); + expect(database_path('migrations/2019_09_15_000020_create_domains_table.php'))->toBeFile(); + expect(database_path('migrations/tenant'))->toBeDirectory(); }); test('migrate fresh command works', function () { $tenant = Tenant::create(); - $this->assertFalse(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeFalse(); Artisan::call('tenants:migrate-fresh'); - $this->assertFalse(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeFalse(); tenancy()->initialize($tenant); - $this->assertTrue(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeTrue(); - $this->assertFalse(DB::table('users')->exists()); + expect(DB::table('users')->exists())->toBeFalse(); DB::table('users')->insert(['name' => 'xxx', 'password' => bcrypt('password'), 'email' => 'foo@bar.xxx']); - $this->assertTrue(DB::table('users')->exists()); + expect(DB::table('users')->exists())->toBeTrue(); // test that db is wiped Artisan::call('tenants:migrate-fresh'); - $this->assertFalse(DB::table('users')->exists()); + expect(DB::table('users')->exists())->toBeFalse(); }); test('run command with array of tenants works', function () { diff --git a/tests/DatabasePreparationTest.php b/tests/DatabasePreparationTest.php index ada0899f..a810ee16 100644 --- a/tests/DatabasePreparationTest.php +++ b/tests/DatabasePreparationTest.php @@ -29,7 +29,7 @@ test('database can be created after tenant creation', function () { $manager = app(MySQLDatabaseManager::class); $manager->setConnection('mysql'); - $this->assertTrue($manager->databaseExists($tenant->database()->getName())); + expect($manager->databaseExists($tenant->database()->getName()))->toBeTrue(); }); test('database can be migrated after tenant creation', function () { @@ -43,7 +43,7 @@ test('database can be migrated after tenant creation', function () { $tenant = Tenant::create(); $tenant->run(function () { - $this->assertTrue(Schema::hasTable('users')); + expect(Schema::hasTable('users'))->toBeTrue(); }); }); @@ -63,7 +63,7 @@ test('database can be seeded after tenant creation', function () { $tenant = Tenant::create(); $tenant->run(function () { - $this->assertSame('Seeded User', User::first()->name); + expect(User::first()->name)->toBe('Seeded User'); }); }); @@ -84,7 +84,7 @@ test('custom job can be added to the pipeline', function () { $tenant = Tenant::create(); $tenant->run(function () { - $this->assertSame('Foo', User::all()[1]->name); + expect(User::all()[1]->name)->toBe('Foo'); }); }); diff --git a/tests/DatabaseUsersTest.php b/tests/DatabaseUsersTest.php index 7c400af9..b2c1cea8 100644 --- a/tests/DatabaseUsersTest.php +++ b/tests/DatabaseUsersTest.php @@ -40,11 +40,11 @@ test('users are created when permission controlled mysql manager is used', funct /** @var ManagesDatabaseUsers $manager */ $manager = $tenant->database()->manager(); - $this->assertFalse($manager->userExists($tenant->database()->getUsername())); + expect($manager->userExists($tenant->database()->getUsername()))->toBeFalse(); $tenant->save(); - $this->assertTrue($manager->userExists($tenant->database()->getUsername())); + expect($manager->userExists($tenant->database()->getUsername()))->toBeTrue(); }); test('a tenants database cannot be created when the user already exists', function () { @@ -55,8 +55,8 @@ test('a tenants database cannot be created when the user already exists', functi /** @var ManagesDatabaseUsers $manager */ $manager = $tenant->database()->manager(); - $this->assertTrue($manager->userExists($tenant->database()->getUsername())); - $this->assertTrue($manager->databaseExists($tenant->database()->getName())); + expect($manager->userExists($tenant->database()->getUsername()))->toBeTrue(); + expect($manager->databaseExists($tenant->database()->getName()))->toBeTrue(); $this->expectException(TenantDatabaseUserAlreadyExistsException::class); Event::fake([DatabaseCreated::class]); @@ -69,7 +69,7 @@ test('a tenants database cannot be created when the user already exists', functi $manager2 = $tenant2->database()->manager(); // database was not created because of DB transaction - $this->assertFalse($manager2->databaseExists($tenant2->database()->getName())); + expect($manager2->databaseExists($tenant2->database()->getName()))->toBeFalse(); Event::assertNotDispatched(DatabaseCreated::class); }); @@ -83,7 +83,7 @@ test('correct grants are given to users', function () { ]); $query = DB::connection('mysql')->select("SHOW GRANTS FOR `{$tenant->database()->getUsername()}`@`%`")[1]; - $this->assertStringStartsWith('GRANT CREATE, ALTER, ALTER ROUTINE ON', $query->{"Grants for {$user}@%"}); // @mysql because that's the hostname within the docker network + expect($query->{"Grants for {$user}@%"})->toStartWith('GRANT CREATE, ALTER, ALTER ROUTINE ON'); // @mysql because that's the hostname within the docker network }); test('having existing databases without users and switching to permission controlled mysql manager doesnt break existing dbs', function () { @@ -102,7 +102,7 @@ test('having existing databases without users and switching to permission contro 'id' => 'foo' . Str::random(10), ]); - $this->assertTrue($tenant->database()->manager() instanceof MySQLDatabaseManager); + expect($tenant->database()->manager() instanceof MySQLDatabaseManager)->toBeTrue(); tenancy()->initialize($tenant); // check if everything works tenancy()->end(); @@ -111,6 +111,6 @@ test('having existing databases without users and switching to permission contro tenancy()->initialize($tenant); // check if everything works - $this->assertTrue($tenant->database()->manager() instanceof PermissionControlledMySQLDatabaseManager); - $this->assertSame('root', config('database.connections.tenant.username')); + expect($tenant->database()->manager() instanceof PermissionControlledMySQLDatabaseManager)->toBeTrue(); + expect(config('database.connections.tenant.username'))->toBe('root'); }); diff --git a/tests/DomainTest.php b/tests/DomainTest.php index cc201b0a..d8f293a7 100644 --- a/tests/DomainTest.php +++ b/tests/DomainTest.php @@ -36,8 +36,8 @@ test('tenant can be identified using hostname', function () { $resolvedTenant = app(DomainTenantResolver::class)->resolve('foo.localhost'); - $this->assertSame($id, $resolvedTenant->id); - $this->assertSame(['foo.localhost'], $resolvedTenant->domains->pluck('domain')->toArray()); + expect($resolvedTenant->id)->toBe($id); + expect($resolvedTenant->domains->pluck('domain')->toArray())->toBe(['foo.localhost']); }); test('a domain can belong to only one tenant', function () { @@ -70,14 +70,14 @@ test('tenant can be identified by domain', function () { 'domain' => 'foo.localhost', ]); - $this->assertFalse(tenancy()->initialized); + expect(tenancy()->initialized)->toBeFalse(); $this ->get('http://foo.localhost/foo/abc/xyz') ->assertSee('abc + xyz'); - $this->assertTrue(tenancy()->initialized); - $this->assertSame('acme', tenant('id')); + expect(tenancy()->initialized)->toBeTrue(); + expect(tenant('id'))->toBe('acme'); }); test('onfail logic can be customized', function () { @@ -97,5 +97,5 @@ test('domains are always lowercase', function () { 'domain' => 'CAPITALS', ]); - $this->assertSame('capitals', Domain::first()->domain); + expect(Domain::first()->domain)->toBe('capitals'); }); diff --git a/tests/EventListenerTest.php b/tests/EventListenerTest.php index db293330..27e46833 100644 --- a/tests/EventListenerTest.php +++ b/tests/EventListenerTest.php @@ -31,7 +31,7 @@ test('listeners can be synchronous', function () { Queue::assertNothingPushed(); - $this->assertSame('bar', app('foo')); + expect(app('foo'))->toBe('bar'); }); test('listeners can be queued by setting a static property', function () { @@ -46,7 +46,7 @@ test('listeners can be queued by setting a static property', function () { return $job->class === FooListener::class; }); - $this->assertFalse(app()->bound('foo')); + expect(app()->bound('foo'))->toBeFalse(); }); test('ing events can be used to cancel tenant model actions', function () { @@ -54,8 +54,8 @@ test('ing events can be used to cancel tenant model actions', function () { return false; }); - $this->assertSame(false, Tenant::create()->exists); - $this->assertSame(0, Tenant::count()); + expect(Tenant::create()->exists)->toBe(false); + expect(Tenant::count())->toBe(0); }); test('ing events can be used to cancel domain model actions', function () { @@ -73,7 +73,7 @@ test('ing events can be used to cancel domain model actions', function () { 'domain' => 'foo', ]); - $this->assertSame('acme', $domain->refresh()->domain); + expect($domain->refresh()->domain)->toBe('acme'); }); test('ing events can be used to cancel db creation', function () { @@ -112,7 +112,7 @@ test('ing events can be used to cancel tenancy bootstrapping', function () { tenancy()->initialize(Tenant::create()); - $this->assertSame([DatabaseTenancyBootstrapper::class], array_map('get_class', tenancy()->getBootstrappers())); + expect(array_map('get_class', tenancy()->getBootstrappers()))->toBe([DatabaseTenancyBootstrapper::class]); }); test('individual job pipelines can terminate while leaving others running', function () { @@ -179,7 +179,7 @@ test('database is not migrated if creation is disabled', function () { 'tenancy_db_name' => 'already_created', ]); - $this->assertFalse($this->hasFailed()); + expect($this->hasFailed())->toBeFalse(); }); // Helpers diff --git a/tests/Features/RedirectTest.php b/tests/Features/RedirectTest.php index 9c5f6191..94861f36 100644 --- a/tests/Features/RedirectTest.php +++ b/tests/Features/RedirectTest.php @@ -34,6 +34,6 @@ test('tenant route helper generates correct url', function () { return 'Foo'; })->name('foo'); - $this->assertSame('http://foo.localhost/abcdef/as/df', tenant_route('foo.localhost', 'foo', ['a' => 'as', 'b' => 'df'])); - $this->assertSame('http://foo.localhost/abcdef', tenant_route('foo.localhost', 'foo', [])); + expect(tenant_route('foo.localhost', 'foo', ['a' => 'as', 'b' => 'df']))->toBe('http://foo.localhost/abcdef/as/df'); + expect(tenant_route('foo.localhost', 'foo', []))->toBe('http://foo.localhost/abcdef'); }); diff --git a/tests/Features/TenantConfigTest.php b/tests/Features/TenantConfigTest.php index 105a48fb..bb4dd4a9 100644 --- a/tests/Features/TenantConfigTest.php +++ b/tests/Features/TenantConfigTest.php @@ -18,7 +18,7 @@ afterEach(function () { }); test('config is merged and removed', function () { - $this->assertSame(null, config('services.paypal')); + expect(config('services.paypal'))->toBe(null); config([ 'tenancy.features' => [TenantConfig::class], 'tenancy.bootstrappers' => [], @@ -37,7 +37,7 @@ test('config is merged and removed', function () { ]); tenancy()->initialize($tenant); - $this->assertSame(['public' => 'foo', 'private' => 'bar'], config('services.paypal')); + expect(config('services.paypal'))->toBe(['public' => 'foo', 'private' => 'bar']); tenancy()->end(); $this->assertSame([ @@ -47,7 +47,7 @@ test('config is merged and removed', function () { }); test('the value can be set to multiple config keys', function () { - $this->assertSame(null, config('services.paypal')); + expect(config('services.paypal'))->toBe(null); config([ 'tenancy.features' => [TenantConfig::class], 'tenancy.bootstrappers' => [], diff --git a/tests/GlobalCacheTest.php b/tests/GlobalCacheTest.php index d02c9449..db7d4417 100644 --- a/tests/GlobalCacheTest.php +++ b/tests/GlobalCacheTest.php @@ -23,31 +23,31 @@ beforeEach(function () { }); test('global cache manager stores data in global cache', function () { - $this->assertSame(null, cache('foo')); + expect(cache('foo'))->toBe(null); GlobalCache::put(['foo' => 'bar'], 1); - $this->assertSame('bar', GlobalCache::get('foo')); + expect(GlobalCache::get('foo'))->toBe('bar'); $tenant1 = Tenant::create(); tenancy()->initialize($tenant1); - $this->assertSame('bar', GlobalCache::get('foo')); + expect(GlobalCache::get('foo'))->toBe('bar'); GlobalCache::put(['abc' => 'xyz'], 1); cache(['def' => 'ghi'], 10); - $this->assertSame('ghi', cache('def')); + expect(cache('def'))->toBe('ghi'); tenancy()->end(); - $this->assertSame('xyz', GlobalCache::get('abc')); - $this->assertSame('bar', GlobalCache::get('foo')); - $this->assertSame(null, cache('def')); + expect(GlobalCache::get('abc'))->toBe('xyz'); + expect(GlobalCache::get('foo'))->toBe('bar'); + expect(cache('def'))->toBe(null); $tenant2 = Tenant::create(); tenancy()->initialize($tenant2); - $this->assertSame('xyz', GlobalCache::get('abc')); - $this->assertSame('bar', GlobalCache::get('foo')); - $this->assertSame(null, cache('def')); + expect(GlobalCache::get('abc'))->toBe('xyz'); + expect(GlobalCache::get('foo'))->toBe('bar'); + expect(cache('def'))->toBe(null); cache(['def' => 'xxx'], 1); - $this->assertSame('xxx', cache('def')); + expect(cache('def'))->toBe('xxx'); tenancy()->initialize($tenant1); - $this->assertSame('ghi', cache('def')); + expect(cache('def'))->toBe('ghi'); }); diff --git a/tests/PathIdentificationTest.php b/tests/PathIdentificationTest.php index 65532bad..8ad93918 100644 --- a/tests/PathIdentificationTest.php +++ b/tests/PathIdentificationTest.php @@ -34,12 +34,12 @@ test('tenant can be identified by path', function () { 'id' => 'acme', ]); - $this->assertFalse(tenancy()->initialized); + expect(tenancy()->initialized)->toBeFalse(); $this->get('/acme/foo/abc/xyz'); - $this->assertTrue(tenancy()->initialized); - $this->assertSame('acme', tenant('id')); + expect(tenancy()->initialized)->toBeTrue(); + expect(tenant('id'))->toBe('acme'); }); test('route actions dont get the tenant id', function () { @@ -47,14 +47,14 @@ test('route actions dont get the tenant id', function () { 'id' => 'acme', ]); - $this->assertFalse(tenancy()->initialized); + expect(tenancy()->initialized)->toBeFalse(); $this ->get('/acme/foo/abc/xyz') ->assertContent('abc + xyz'); - $this->assertTrue(tenancy()->initialized); - $this->assertSame('acme', tenant('id')); + expect(tenancy()->initialized)->toBeTrue(); + expect(tenant('id'))->toBe('acme'); }); test('exception is thrown when tenant cannot be identified by path', function () { @@ -64,7 +64,7 @@ test('exception is thrown when tenant cannot be identified by path', function () ->withoutExceptionHandling() ->get('/acme/foo/abc/xyz'); - $this->assertFalse(tenancy()->initialized); + expect(tenancy()->initialized)->toBeFalse(); }); test('onfail logic can be customized', function () { diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 1bb73e9c..a1e38bce 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -104,7 +104,7 @@ test('tenancy is initialized inside queues', function (bool $shouldEndTenancy) { dispatch(new TestJob($this->valuestore, $user)); - $this->assertFalse($this->valuestore->has('tenant_id')); + expect($this->valuestore->has('tenant_id'))->toBeFalse(); if ($shouldEndTenancy) { tenancy()->end(); @@ -112,12 +112,12 @@ test('tenancy is initialized inside queues', function (bool $shouldEndTenancy) { $this->artisan('queue:work --once'); - $this->assertSame(0, DB::connection('central')->table('failed_jobs')->count()); + expect(DB::connection('central')->table('failed_jobs')->count())->toBe(0); - $this->assertSame('The current tenant id is: ' . $tenant->id, $this->valuestore->get('tenant_id')); + expect($this->valuestore->get('tenant_id'))->toBe('The current tenant id is: ' . $tenant->id); $tenant->run(function () use ($user) { - $this->assertSame('Bar', $user->fresh()->name); + expect($user->fresh()->name)->toBe('Bar'); }); }); @@ -147,7 +147,7 @@ test('tenancy is initialized when retrying jobs', function (bool $shouldEndTenan dispatch(new TestJob($this->valuestore, $user)); - $this->assertFalse($this->valuestore->has('tenant_id')); + expect($this->valuestore->has('tenant_id'))->toBeFalse(); if ($shouldEndTenancy) { tenancy()->end(); @@ -155,18 +155,18 @@ test('tenancy is initialized when retrying jobs', function (bool $shouldEndTenan $this->artisan('queue:work --once'); - $this->assertSame(1, DB::connection('central')->table('failed_jobs')->count()); - $this->assertNull($this->valuestore->get('tenant_id')); // job failed + expect(DB::connection('central')->table('failed_jobs')->count())->toBe(1); + expect($this->valuestore->get('tenant_id'))->toBeNull(); // job failed $this->artisan('queue:retry all'); $this->artisan('queue:work --once'); - $this->assertSame(0, DB::connection('central')->table('failed_jobs')->count()); + expect(DB::connection('central')->table('failed_jobs')->count())->toBe(0); - $this->assertSame('The current tenant id is: ' . $tenant->id, $this->valuestore->get('tenant_id')); // job succeeded + expect($this->valuestore->get('tenant_id'))->toBe('The current tenant id is: ' . $tenant->id); // job succeeded $tenant->run(function () use ($user) { - $this->assertSame('Bar', $user->fresh()->name); + expect($user->fresh()->name)->toBe('Bar'); }); }); @@ -185,10 +185,10 @@ test('the tenant used by the job doesnt change when the current tenant changes', tenancy()->initialize($tenant2); - $this->assertFalse($this->valuestore->has('tenant_id')); + expect($this->valuestore->has('tenant_id'))->toBeFalse(); $this->artisan('queue:work --once'); - $this->assertSame('The current tenant id is: acme', $this->valuestore->get('tenant_id')); + expect($this->valuestore->get('tenant_id'))->toBe('The current tenant id is: acme'); }); // Helpers diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index 6064f83d..3335eb25 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -130,7 +130,7 @@ test('only the synced columns are updated in the central db', function () { test('creating the resource in tenant database creates it in central database and creates the mapping', function () { // Assert no user in central DB - $this->assertCount(0, ResourceUser::all()); + expect(ResourceUser::all())->toHaveCount(0); $tenant = ResourceTenant::create(); migrateTenants(); @@ -149,23 +149,23 @@ test('creating the resource in tenant database creates it in central database an tenancy()->end(); // Asset user was created - $this->assertSame('acme', CentralUser::first()->global_id); - $this->assertSame('commenter', CentralUser::first()->role); + expect(CentralUser::first()->global_id)->toBe('acme'); + expect(CentralUser::first()->role)->toBe('commenter'); // Assert mapping was created - $this->assertCount(1, CentralUser::first()->tenants); + expect(CentralUser::first()->tenants)->toHaveCount(1); // Assert role change doesn't cascade CentralUser::first()->update(['role' => 'central superadmin']); tenancy()->initialize($tenant); - $this->assertSame('commenter', ResourceUser::first()->role); + expect(ResourceUser::first()->role)->toBe('commenter'); }); test('trying to update synced resources from central context using tenant models results in an exception', function () { $this->creating_the_resource_in_tenant_database_creates_it_in_central_database_and_creates_the_mapping(); tenancy()->end(); - $this->assertFalse(tenancy()->initialized); + expect(tenancy()->initialized)->toBeFalse(); $this->expectException(ModelNotSyncMasterException::class); ResourceUser::first()->update(['role' => 'foobar']); @@ -186,13 +186,13 @@ test('attaching a tenant to the central resource triggers a pull from the tenant migrateTenants(); $tenant->run(function () { - $this->assertCount(0, ResourceUser::all()); + expect(ResourceUser::all())->toHaveCount(0); }); $centralUser->tenants()->attach('t1'); $tenant->run(function () { - $this->assertCount(1, ResourceUser::all()); + expect(ResourceUser::all())->toHaveCount(1); }); }); @@ -211,7 +211,7 @@ test('attaching users to tenants d o e s n o t d o a n y t h i n g', function () migrateTenants(); $tenant->run(function () { - $this->assertCount(0, ResourceUser::all()); + expect(ResourceUser::all())->toHaveCount(0); }); // The child model is inaccessible in the Pivot Model, so we can't fire any events. @@ -219,7 +219,7 @@ test('attaching users to tenants d o e s n o t d o a n y t h i n g', function () $tenant->run(function () { // Still zero - $this->assertCount(0, ResourceUser::all()); + expect(ResourceUser::all())->toHaveCount(0); }); }); @@ -251,17 +251,17 @@ test('resources are synced only to workspaces that have the resource', function $t1->run(function () { // assert user exists - $this->assertCount(1, ResourceUser::all()); + expect(ResourceUser::all())->toHaveCount(1); }); $t2->run(function () { // assert user exists - $this->assertCount(1, ResourceUser::all()); + expect(ResourceUser::all())->toHaveCount(1); }); $t3->run(function () { // assert user does NOT exist - $this->assertCount(0, ResourceUser::all()); + expect(ResourceUser::all())->toHaveCount(0); }); }); @@ -298,15 +298,15 @@ test('when a resource exists in other tenant dbs but is c r e a t e d in a tenan }); $centralUser = CentralUser::first(); - $this->assertSame('John Foo', $centralUser->name); // name changed - $this->assertSame('john@foo', $centralUser->email); // email changed - $this->assertSame('commenter', $centralUser->role); // role didn't change + expect($centralUser->name)->toBe('John Foo'); // name changed + expect($centralUser->email)->toBe('john@foo'); // email changed + expect($centralUser->role)->toBe('commenter'); // role didn't change $t1->run(function () { $user = ResourceUser::first(); - $this->assertSame('John Foo', $user->name); // name changed - $this->assertSame('john@foo', $user->email); // email changed - $this->assertSame('commenter', $user->role); // role didn't change, i.e. is the same as from the original copy from central + expect($user->name)->toBe('John Foo'); // name changed + expect($user->email)->toBe('john@foo'); // email changed + expect($user->role)->toBe('commenter'); // role didn't change, i.e. is the same as from the original copy from central }); }); @@ -342,23 +342,23 @@ test('the synced columns are updated in other tenant dbs where the resource exis 'role' => 'employee', // unsynced ]); - $this->assertSame('employee', ResourceUser::first()->role); + expect(ResourceUser::first()->role)->toBe('employee'); }); // Check that change was cascaded to other tenants $t1->run($check = function () { $user = ResourceUser::first(); - $this->assertSame('John 3', $user->name); // synced - $this->assertSame('commenter', $user->role); // unsynced + expect($user->name)->toBe('John 3'); // synced + expect($user->role)->toBe('commenter'); // unsynced }); $t2->run($check); // Check that change bubbled up to central DB - $this->assertSame(1, CentralUser::count()); + expect(CentralUser::count())->toBe(1); $centralUser = CentralUser::first(); - $this->assertSame('John 3', $centralUser->name); // synced - $this->assertSame('commenter', $centralUser->role); // unsynced + expect($centralUser->name)->toBe('John 3'); // synced + expect($centralUser->role)->toBe('commenter'); // unsynced }); test('global id is generated using id generator when its not supplied', function () { @@ -389,7 +389,7 @@ test('when the resource doesnt exist in the tenant db non synced columns will ca $centralUser->tenants()->attach('t1'); $t1->run(function () { - $this->assertSame('employee', ResourceUser::first()->role); + expect(ResourceUser::first()->role)->toBe('employee'); }); }); @@ -409,7 +409,7 @@ test('when the resource doesnt exist in the central db non synced columns will b ]); }); - $this->assertSame('employee', CentralUser::first()->role); + expect(CentralUser::first()->role)->toBe('employee'); }); test('the listener can be queued', function () { @@ -491,7 +491,7 @@ test('an event is fired for all touched resources', function () { 'role' => 'employee', // unsynced ]); - $this->assertSame('employee', ResourceUser::first()->role); + expect(ResourceUser::first()->role)->toBe('employee'); }); Event::assertDispatched(SyncedResourceChangedInForeignDatabase::class, function (SyncedResourceChangedInForeignDatabase $event) { diff --git a/tests/SingleDatabaseTenancyTest.php b/tests/SingleDatabaseTenancyTest.php index 70860507..3d4e7420 100644 --- a/tests/SingleDatabaseTenancyTest.php +++ b/tests/SingleDatabaseTenancyTest.php @@ -46,13 +46,13 @@ test('primary models are scoped to the current tenant', function () { $post = Post::create(['text' => 'Foo']); - $this->assertSame('acme', $post->tenant_id); - $this->assertSame('acme', $post->tenant->id); + expect($post->tenant_id)->toBe('acme'); + expect($post->tenant->id)->toBe('acme'); $post = Post::first(); - $this->assertSame('acme', $post->tenant_id); - $this->assertSame('acme', $post->tenant->id); + expect($post->tenant_id)->toBe('acme'); + expect($post->tenant->id)->toBe('acme'); // ====================================== // foobar context @@ -62,13 +62,13 @@ test('primary models are scoped to the current tenant', function () { $post = Post::create(['text' => 'Bar']); - $this->assertSame('foobar', $post->tenant_id); - $this->assertSame('foobar', $post->tenant->id); + expect($post->tenant_id)->toBe('foobar'); + expect($post->tenant->id)->toBe('foobar'); $post = Post::first(); - $this->assertSame('foobar', $post->tenant_id); - $this->assertSame('foobar', $post->tenant->id); + expect($post->tenant_id)->toBe('foobar'); + expect($post->tenant->id)->toBe('foobar'); // ====================================== // acme context again @@ -76,11 +76,11 @@ test('primary models are scoped to the current tenant', function () { tenancy()->initialize($acme); $post = Post::first(); - $this->assertSame('acme', $post->tenant_id); - $this->assertSame('acme', $post->tenant->id); + expect($post->tenant_id)->toBe('acme'); + expect($post->tenant->id)->toBe('acme'); // Assert foobar models are inaccessible in acme context - $this->assertSame(1, Post::count()); + expect(Post::count())->toBe(1); }); test('primary models are not scoped in the central context', function () { @@ -88,7 +88,7 @@ test('primary models are not scoped in the central context', function () { tenancy()->end(); - $this->assertSame(2, Post::count()); + expect(Post::count())->toBe(2); }); test('secondary models are scoped to the current tenant when accessed via primary model', function () { @@ -112,17 +112,17 @@ test('secondary models are scoped to the current tenant when accessed via primar // ================ // acme context again tenancy()->initialize($acme); - $this->assertSame(1, Post::count()); - $this->assertSame(1, Post::first()->comments->count()); + expect(Post::count())->toBe(1); + expect(Post::first()->comments->count())->toBe(1); }); test('secondary models are n o t scoped to the current tenant when accessed directly', function () { $this->secondary_models_are_scoped_to_the_current_tenant_when_accessed_via_primary_model(); // We're in acme context - $this->assertSame('acme', tenant('id')); + expect(tenant('id'))->toBe('acme'); - $this->assertSame(2, Comment::count()); + expect(Comment::count())->toBe(2); }); test('secondary models a r e scoped to the current tenant when accessed directly a n d p a r e n t r e l a t i o n s h i p t r a i t i s u s e d', function () { @@ -134,8 +134,8 @@ test('secondary models a r e scoped to the current tenant when accessed directly $post = Post::create(['text' => 'Foo']); $post->scoped_comments()->create(['text' => 'Comment Text']); - $this->assertSame(1, Post::count()); - $this->assertSame(1, ScopedComment::count()); + expect(Post::count())->toBe(1); + expect(ScopedComment::count())->toBe(1); }); $foobar = Tenant::create([ @@ -143,18 +143,18 @@ test('secondary models a r e scoped to the current tenant when accessed directly ]); $foobar->run(function () { - $this->assertSame(0, Post::count()); - $this->assertSame(0, ScopedComment::count()); + expect(Post::count())->toBe(0); + expect(ScopedComment::count())->toBe(0); $post = Post::create(['text' => 'Bar']); $post->scoped_comments()->create(['text' => 'Comment Text 2']); - $this->assertSame(1, Post::count()); - $this->assertSame(1, ScopedComment::count()); + expect(Post::count())->toBe(1); + expect(ScopedComment::count())->toBe(1); }); // Global context - $this->assertSame(2, ScopedComment::count()); + expect(ScopedComment::count())->toBe(2); }); test('secondary models are n o t scoped in the central context', function () { @@ -162,7 +162,7 @@ test('secondary models are n o t scoped in the central context', function () { tenancy()->end(); - $this->assertSame(2, Comment::count()); + expect(Comment::count())->toBe(2); }); test('global models are not scoped at all', function () { @@ -179,13 +179,13 @@ test('global models are not scoped at all', function () { ]); $acme->run(function () { - $this->assertSame(2, GlobalResource::count()); + expect(GlobalResource::count())->toBe(2); GlobalResource::create(['text' => 'Third']); GlobalResource::create(['text' => 'Fourth']); }); - $this->assertSame(4, GlobalResource::count()); + expect(GlobalResource::count())->toBe(4); }); test('tenant id and relationship is auto added when creating primary resources in tenant context', function () { @@ -195,10 +195,10 @@ test('tenant id and relationship is auto added when creating primary resources i $post = Post::create(['text' => 'Foo']); - $this->assertSame('acme', $post->tenant_id); - $this->assertTrue($post->relationLoaded('tenant')); - $this->assertSame($acme, $post->tenant); - $this->assertSame(tenant(), $post->tenant); + expect($post->tenant_id)->toBe('acme'); + expect($post->relationLoaded('tenant'))->toBeTrue(); + expect($post->tenant)->toBe($acme); + expect($post->tenant)->toBe(tenant()); }); test('tenant id is not auto added when creating primary resources in central context', function () { @@ -227,7 +227,7 @@ test('tenant id column name can be customized', function () { $post = Post::create(['text' => 'Foo']); - $this->assertSame('acme', $post->team_id); + expect($post->team_id)->toBe('acme'); // ====================================== // foobar context @@ -237,11 +237,11 @@ test('tenant id column name can be customized', function () { $post = Post::create(['text' => 'Bar']); - $this->assertSame('foobar', $post->team_id); + expect($post->team_id)->toBe('foobar'); $post = Post::first(); - $this->assertSame('foobar', $post->team_id); + expect($post->team_id)->toBe('foobar'); // ====================================== // acme context again @@ -249,10 +249,10 @@ test('tenant id column name can be customized', function () { tenancy()->initialize($acme); $post = Post::first(); - $this->assertSame('acme', $post->team_id); + expect($post->team_id)->toBe('acme'); // Assert foobar models are inaccessible in acme context - $this->assertSame(1, Post::count()); + expect(Post::count())->toBe(1); }); test('the model returned by the tenant helper has unique and exists validation rules', function () { @@ -287,8 +287,8 @@ test('the model returned by the tenant helper has unique and exists validation r ])->fails(); // Assert that tenant()->unique() and tenant()->exists() are scoped - $this->assertTrue($uniqueFails); - $this->assertFalse($existsFails); + expect($uniqueFails)->toBeTrue(); + expect($existsFails)->toBeFalse(); }); // Helpers diff --git a/tests/SubdomainTest.php b/tests/SubdomainTest.php index dfb6bf0f..a0ee68a8 100644 --- a/tests/SubdomainTest.php +++ b/tests/SubdomainTest.php @@ -34,14 +34,14 @@ test('tenant can be identified by subdomain', function () { 'domain' => 'foo', ]); - $this->assertFalse(tenancy()->initialized); + expect(tenancy()->initialized)->toBeFalse(); $this ->get('http://foo.localhost/foo/abc/xyz') ->assertSee('abc + xyz'); - $this->assertTrue(tenancy()->initialized); - $this->assertSame('acme', tenant('id')); + expect(tenancy()->initialized)->toBeTrue(); + expect(tenant('id'))->toBe('acme'); }); test('onfail logic can be customized', function () { diff --git a/tests/TenantAssetTest.php b/tests/TenantAssetTest.php index 3b132aec..662bf799 100644 --- a/tests/TenantAssetTest.php +++ b/tests/TenantAssetTest.php @@ -40,7 +40,7 @@ test('asset can be accessed using the url returned by the tenant asset helper', // response()->file() returns BinaryFileResponse whose content is // inaccessible via getContent, so ->assertSee() can't be used - $this->assertFileExists($path); + expect($path)->toBeFile(); $response = $this->get(tenant_asset($filename), [ 'X-Tenant' => $tenant->id, ]); @@ -51,7 +51,7 @@ test('asset can be accessed using the url returned by the tenant asset helper', $content = fread($f, filesize($path)); fclose($f); - $this->assertSame('bar', $content); + expect($content)->toBe('bar'); }); test('asset helper returns a link to tenant asset controller when asset url is null', function () { @@ -60,7 +60,7 @@ test('asset helper returns a link to tenant asset controller when asset url is n $tenant = Tenant::create(); tenancy()->initialize($tenant); - $this->assertSame(route('stancl.tenancy.asset', ['path' => 'foo']), asset('foo')); + expect(asset('foo'))->toBe(route('stancl.tenancy.asset', ['path' => 'foo'])); }); test('asset helper returns a link to an external url when asset url is not null', function () { @@ -69,17 +69,17 @@ test('asset helper returns a link to an external url when asset url is not null' $tenant = Tenant::create(); tenancy()->initialize($tenant); - $this->assertSame("https://an-s3-bucket/tenant{$tenant->id}/foo", asset('foo')); + expect(asset('foo'))->toBe("https://an-s3-bucket/tenant{$tenant->id}/foo"); }); test('global asset helper returns the same url regardless of tenancy initialization', function () { $original = global_asset('foobar'); - $this->assertSame(asset('foobar'), global_asset('foobar')); + expect(global_asset('foobar'))->toBe(asset('foobar')); $tenant = Tenant::create(); tenancy()->initialize($tenant); - $this->assertSame($original, global_asset('foobar')); + expect(global_asset('foobar'))->toBe($original); }); test('asset helper tenancy can be disabled', function () { @@ -93,7 +93,7 @@ test('asset helper tenancy can be disabled', function () { $tenant = Tenant::create(); tenancy()->initialize($tenant); - $this->assertSame($original, asset('foo')); + expect(asset('foo'))->toBe($original); }); // Helpers diff --git a/tests/TenantDatabaseManagerTest.php b/tests/TenantDatabaseManagerTest.php index 29c7add8..b2997661 100644 --- a/tests/TenantDatabaseManagerTest.php +++ b/tests/TenantDatabaseManagerTest.php @@ -40,20 +40,20 @@ test('databases can be created and deleted', function ($driver, $databaseManager $manager = app($databaseManager); $manager->setConnection($driver); - $this->assertFalse($manager->databaseExists($name)); + expect($manager->databaseExists($name))->toBeFalse(); $tenant = Tenant::create([ 'tenancy_db_name' => $name, 'tenancy_db_connection' => $driver, ]); - $this->assertTrue($manager->databaseExists($name)); + expect($manager->databaseExists($name))->toBeTrue(); $manager->deleteDatabase($tenant); - $this->assertFalse($manager->databaseExists($name)); + expect($manager->databaseExists($name))->toBeFalse(); })->with('database_manager_provider'); test('dbs can be created when another driver is used for the central db', function () { - $this->assertSame('central', config('database.default')); + expect(config('database.default'))->toBe('central'); Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) { return $event->tenant; @@ -64,26 +64,26 @@ test('dbs can be created when another driver is used for the central db', functi $mysqlmanager = app(MySQLDatabaseManager::class); $mysqlmanager->setConnection('mysql'); - $this->assertFalse($mysqlmanager->databaseExists($database)); + expect($mysqlmanager->databaseExists($database))->toBeFalse(); Tenant::create([ 'tenancy_db_name' => $database, 'tenancy_db_connection' => 'mysql', ]); - $this->assertTrue($mysqlmanager->databaseExists($database)); + expect($mysqlmanager->databaseExists($database))->toBeTrue(); $postgresManager = app(PostgreSQLDatabaseManager::class); $postgresManager->setConnection('pgsql'); $database = 'db' . $this->randomString(); - $this->assertFalse($postgresManager->databaseExists($database)); + expect($postgresManager->databaseExists($database))->toBeFalse(); Tenant::create([ 'tenancy_db_name' => $database, 'tenancy_db_connection' => 'pgsql', ]); - $this->assertTrue($postgresManager->databaseExists($database)); + expect($postgresManager->databaseExists($database))->toBeTrue(); }); test('the tenant connection is fully removed', function () { @@ -102,20 +102,20 @@ test('the tenant connection is fully removed', function () { $tenant = Tenant::create(); - $this->assertSame(['central'], array_keys(app('db')->getConnections())); + expect(array_keys(app('db')->getConnections()))->toBe(['central']); $this->assertArrayNotHasKey('tenant', config('database.connections')); tenancy()->initialize($tenant); createUsersTable(); - $this->assertSame(['central', 'tenant'], array_keys(app('db')->getConnections())); + expect(array_keys(app('db')->getConnections()))->toBe(['central', 'tenant']); $this->assertArrayHasKey('tenant', config('database.connections')); tenancy()->end(); - $this->assertSame(['central'], array_keys(app('db')->getConnections())); - $this->assertNull(config('database.connections.tenant')); + expect(array_keys(app('db')->getConnections()))->toBe(['central']); + expect(config('database.connections.tenant'))->toBeNull(); }); test('db name is prefixed with db path when sqlite is used', function () { @@ -132,7 +132,7 @@ test('db name is prefixed with db path when sqlite is used', function () { ]); app(DatabaseManager::class)->createTenantConnection($tenant); - $this->assertSame(config('database.connections.tenant.database'), database_path('foodb')); + expect(database_path('foodb'))->toBe(config('database.connections.tenant.database')); }); test('schema manager uses schema to separate tenant dbs', function () { @@ -160,8 +160,8 @@ test('schema manager uses schema to separate tenant dbs', function () { config('database.connections.' . config('database.default') . '.search_path') : config('database.connections.' . config('database.default') . '.schema'); - $this->assertSame($tenant->database()->getName(), $schemaConfig); - $this->assertSame($originalDatabaseName, config(['database.connections.pgsql.database'])); + expect($schemaConfig)->toBe($tenant->database()->getName()); + expect(config(['database.connections.pgsql.database']))->toBe($originalDatabaseName); }); test('a tenants database cannot be created when the database already exists', function () { @@ -175,7 +175,7 @@ test('a tenants database cannot be created when the database already exists', fu ]); $manager = $tenant->database()->manager(); - $this->assertTrue($manager->databaseExists($tenant->database()->getName())); + expect($manager->databaseExists($tenant->database()->getName()))->toBeTrue(); $this->expectException(TenantDatabaseAlreadyExistsException::class); $tenant2 = Tenant::create([ @@ -220,10 +220,10 @@ test('tenant database can be created on a foreign server', function () { $manager = $tenant->database()->manager(); $manager->setConnection('mysql'); - $this->assertFalse($manager->databaseExists($name)); + expect($manager->databaseExists($name))->toBeFalse(); $manager->setConnection('mysql2'); - $this->assertTrue($manager->databaseExists($name)); + expect($manager->databaseExists($name))->toBeTrue(); }); test('path used by sqlite manager can be customized', function () { diff --git a/tests/TenantModelTest.php b/tests/TenantModelTest.php index 8dc2a9ac..3f261109 100644 --- a/tests/TenantModelTest.php +++ b/tests/TenantModelTest.php @@ -36,11 +36,11 @@ test('current tenant can be resolved from service container using typehint', fun tenancy()->initialize($tenant); - $this->assertSame($tenant->id, app(Contracts\Tenant::class)->id); + expect(app(Contracts\Tenant::class)->id)->toBe($tenant->id); tenancy()->end(); - $this->assertSame(null, app(Contracts\Tenant::class)); + expect(app(Contracts\Tenant::class))->toBe(null); }); test('id is generated when no id is supplied', function () { @@ -66,8 +66,8 @@ test('autoincrement ids are supported', function () { $tenant1 = Tenant::create(); $tenant2 = Tenant::create(); - $this->assertSame(1, $tenant1->id); - $this->assertSame(2, $tenant2->id); + expect($tenant1->id)->toBe(1); + expect($tenant2->id)->toBe(2); }); test('custom tenant model can be used', function () { @@ -75,7 +75,7 @@ test('custom tenant model can be used', function () { tenancy()->initialize($tenant); - $this->assertTrue(tenant() instanceof MyTenant); + expect(tenant() instanceof MyTenant)->toBeTrue(); }); test('custom tenant model that doesnt extend vendor tenant model can be used', function () { @@ -85,7 +85,7 @@ test('custom tenant model that doesnt extend vendor tenant model can be used', f tenancy()->initialize($tenant); - $this->assertTrue(tenant() instanceof AnotherTenant); + expect(tenant() instanceof AnotherTenant)->toBeTrue(); }); test('tenant can be created even when we are in another tenants context', function () { @@ -112,15 +112,15 @@ test('tenant can be created even when we are in another tenants context', functi tenancy()->end(); - $this->assertSame(2, Tenant::count()); + expect(Tenant::count())->toBe(2); }); test('the model uses tenant collection', function () { Tenant::create(); Tenant::create(); - $this->assertSame(2, Tenant::count()); - $this->assertTrue(Tenant::all() instanceof TenantCollection); + expect(Tenant::count())->toBe(2); + expect(Tenant::all() instanceof TenantCollection)->toBeTrue(); }); test('a command can be run on a collection of tenants', function () { @@ -139,8 +139,8 @@ test('a command can be run on a collection of tenants', function () { ]); }); - $this->assertSame('xyz', Tenant::find('t1')->foo); - $this->assertSame('xyz', Tenant::find('t2')->foo); + expect(Tenant::find('t1')->foo)->toBe('xyz'); + expect(Tenant::find('t2')->foo)->toBe('xyz'); }); // Helpers diff --git a/tests/TenantUserImpersonationTest.php b/tests/TenantUserImpersonationTest.php index e94861d9..e0e54fea 100644 --- a/tests/TenantUserImpersonationTest.php +++ b/tests/TenantUserImpersonationTest.php @@ -171,7 +171,7 @@ test('tokens are deleted after use', function () { ->assertSuccessful() ->assertSee('You are logged in as Joe'); - $this->assertNull(ImpersonationToken::find($token->token)); + expect(ImpersonationToken::find($token->token))->toBeNull(); }); test('impersonation works with multiple models and guards', function () { @@ -220,8 +220,8 @@ test('impersonation works with multiple models and guards', function () { ->assertSee('You are logged in as Joe'); Tenant::first()->run(function () { - $this->assertSame('Joe', auth()->guard('another')->user()->name); - $this->assertSame(null, auth()->guard('web')->user()); + expect(auth()->guard('another')->user()->name)->toBe('Joe'); + expect(auth()->guard('web')->user())->toBe(null); }); });