mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:24:04 +00:00
Switch to using MySQL for tests, resolve FK constraint issues
This commit is contained in:
parent
616c5983a4
commit
6735d0a589
4 changed files with 24 additions and 8 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue