diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index 6db7c4ca..44b4b4ce 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -579,7 +579,7 @@ class ResourceTenant extends Tenant { public function users() { - return $this->belongsToMany(CentralUser::class, 'tenant_users', 'tenant_id', 'global_user_id') + return $this->belongsToMany(CentralUser::class, 'tenant_users', 'tenant_id', 'global_user_id', 'id', 'global_id') ->using(TenantPivot::class); } } @@ -594,7 +594,7 @@ class CentralUser extends Model implements SyncMaster public function tenants(): BelongsToMany { - return $this->belongsToMany(ResourceTenant::class, 'tenant_users', 'global_user_id', 'tenant_id') + return $this->belongsToMany(ResourceTenant::class, 'tenant_users', 'global_user_id', 'tenant_id', 'global_id') ->using(TenantPivot::class); } diff --git a/tests/SingleDatabaseTenancyTest.php b/tests/SingleDatabaseTenancyTest.php index 33a86fd3..b64478cc 100644 --- a/tests/SingleDatabaseTenancyTest.php +++ b/tests/SingleDatabaseTenancyTest.php @@ -9,7 +9,6 @@ use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Validator; -use Illuminate\Validation\Rules\Unique; use Stancl\Tenancy\Database\Concerns\BelongsToPrimaryModel; use Stancl\Tenancy\Database\Concerns\BelongsToTenant; use Stancl\Tenancy\Database\Concerns\HasScopedValidationRules; @@ -36,7 +35,7 @@ class SingleDatabaseTenancyTest extends TestCase $table->increments('id'); $table->string('text'); - $table->string('post_id'); + $table->unsignedInteger('post_id'); $table->foreign('post_id')->references('id')->on('posts')->onUpdate('cascade')->onDelete('cascade'); }); @@ -236,6 +235,7 @@ class SingleDatabaseTenancyTest extends TestCase { BelongsToTenant::$tenantIdColumn = 'team_id'; + Schema::drop('comments'); Schema::drop('posts'); Schema::create('posts', function (Blueprint $table) { $table->increments('id'); diff --git a/tests/TenantModelTest.php b/tests/TenantModelTest.php index 44c262eb..d42db5c5 100644 --- a/tests/TenantModelTest.php +++ b/tests/TenantModelTest.php @@ -62,7 +62,7 @@ class TenantModelTest extends TestCase $this->assertSame(null, $tenant->data); // Low level test to assert database structure - $this->assertSame(json_encode(['foo' => 'bar']), DB::table('tenants')->where('id', $tenant->id)->first()->data); + $this->assertSame(['foo' => 'bar'], json_decode(DB::table('tenants')->where('id', $tenant->id)->first()->data, true)); $this->assertSame(null, DB::table('tenants')->where('id', $tenant->id)->first()->foo ?? null); // Model has the correct structure when retrieved @@ -105,6 +105,7 @@ class TenantModelTest extends TestCase /** @test */ public function autoincrement_ids_are_supported() { + Schema::drop('domains'); Schema::table('tenants', function (Blueprint $table) { $table->bigIncrements('id')->change(); }); diff --git a/tests/TestCase.php b/tests/TestCase.php index bb33da43..bbc42489 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests; use Illuminate\Support\Facades\Redis; +use PDO; use Stancl\Tenancy\Tests\Etc\Tenant; abstract class TestCase extends \Orchestra\Testbench\TestCase @@ -56,9 +57,23 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase 'database.redis.default.host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'), 'database.redis.options.prefix' => 'foo', 'database.connections.central' => [ - 'driver' => 'sqlite', - 'database' => database_path('central.sqlite'), - // 'database' => ':memory:', + 'driver' => 'mysql', + 'url' => env('DATABASE_URL'), + 'host' => 'mysql', + 'port' => env('DB_PORT', '3306'), + 'database' => 'main', + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'prefix_indexes' => true, + 'strict' => true, + 'engine' => null, + 'options' => extension_loaded('pdo_mysql') ? array_filter([ + PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), + ]) : [], ], 'database.connections.sqlite.database' => ':memory:', 'database.connections.mysql.host' => env('TENANCY_TEST_MYSQL_HOST', '127.0.0.1'),