diff --git a/composer.json b/composer.json index a2daae5..f8d3397 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,14 @@ "minimum-stability": "dev", "require": { "php": "^8.0", - "illuminate/support": "~6.0|~7.0|~8.0", - "illuminate/cache": "~6.0|~7.0|~8.0" + "illuminate/support": "~8.0|~9.0|~10.0|~11.0", + "illuminate/cache": "~8.0|~9.0|~10.0|~11.0" }, "require-dev": { - "orchestra/database": "^4.0", - "orchestra/testbench": "^4.0", - "phpunit/phpunit": "~8.0" + "orchestra/database": "^6.0", + "orchestra/testbench": "^6.0", + "phpunit/phpunit": "~8.5|^9.5.10", + "laravel/legacy-factories": "^1.0" }, "autoload": { "psr-4": { diff --git a/database/migrations/create_role_user_table.php b/database/migrations/create_role_user_table.php index cbf8817..1a19e66 100644 --- a/database/migrations/create_role_user_table.php +++ b/database/migrations/create_role_user_table.php @@ -14,11 +14,9 @@ class CreateRoleUserTable extends Migration public function up() { Schema::create('role_user', function (Blueprint $table) { - $table->increments('id'); - $table->integer('role_id')->unsigned()->index(); - $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade'); - $table->integer('user_id')->unsigned()->index(); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->id(); + $table->foreignId('role_id')->constrained('roles')->onDelete('cascade'); + $table->foreignId('user_id')->constrained('users')->onDelete('cascade'); $table->timestamps(); }); } @@ -31,9 +29,9 @@ public function up() public function down() { Schema::table('role_user', function (Blueprint $table) { - $table->dropForeign('role_user_role_id_foreign'); - $table->dropForeign('role_user_user_id_foreign'); + $table->dropForeign(['role_id']); + $table->dropForeign(['user_id']); }); Schema::dropIfExists('role_user'); } -} +} \ No newline at end of file diff --git a/database/migrations/create_roles_table.php b/database/migrations/create_roles_table.php index 72cf541..418607f 100644 --- a/database/migrations/create_roles_table.php +++ b/database/migrations/create_roles_table.php @@ -14,7 +14,7 @@ class CreateRolesTable extends Migration public function up() { Schema::create('roles', function (Blueprint $table) { - $table->increments('id'); + $table->id(); $table->string('name'); $table->string('slug')->unique(); $table->string('description')->nullable(); @@ -32,4 +32,4 @@ public function down() { Schema::dropIfExists('roles'); } -} +} \ No newline at end of file diff --git a/database/migrations/create_user_table.php b/database/migrations/create_user_table.php new file mode 100644 index 0000000..6cdf0f0 --- /dev/null +++ b/database/migrations/create_user_table.php @@ -0,0 +1,36 @@ +id(); + $table->string('name'); + $table->string('email')->unique(); + $table->timestamp('email_verified_at')->nullable(); + $table->string('password'); + $table->rememberToken(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('users'); + } +} \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index 4f94a22..81e4627 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,18 +4,20 @@ use HttpOz\Roles\Tests\Stubs\User; use Orchestra\Testbench\TestCase as Orchestra; +use Illuminate\Foundation\Testing\RefreshDatabase; class TestCase extends Orchestra { + use RefreshDatabase; + /** * Setup the test environment. */ public function setUp(): void { parent::setUp(); - $this->loadLaravelMigrations(['--database' => 'testbench']); + $this->artisan('migrate:fresh'); // This will drop all tables and re-run all migrations $this->setUpDatabase($this->app); - $this->withFactories(__DIR__ . '/../database/factories'); } @@ -36,9 +38,16 @@ public function getEnvironmentSetUp($app) { $app['config']->set('database.default', 'testbench'); $app['config']->set('database.connections.testbench', [ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'pgsql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '5432'), + 'database' => env('DB_DATABASE', 'test_db'), + 'username' => env('DB_USERNAME', 'trustanchor'), + 'password' => env('DB_PASSWORD', 'Yai3hahMaepi9uyo3Joh'), + 'charset' => 'utf8', 'prefix' => '', + 'schema' => 'public', + 'sslmode' => 'prefer', ]); $app['config']->set('auth.providers.users.model', User::class); @@ -68,9 +77,16 @@ public function getEnvironmentSetUp($app) */ protected function setUpDatabase($app) { + // Include default Laravel migrations to ensure users table exists + $this->artisan('migrate', ['--database' => 'testbench']); + + // Include custom migrations + include_once __DIR__ . '/../database/migrations/create_user_table.php'; include_once __DIR__ . '/../database/migrations/create_roles_table.php'; include_once __DIR__ . '/../database/migrations/create_role_user_table.php'; + + (new \CreateUsersTable())->up(); (new \CreateRolesTable())->up(); (new \CreateRoleUserTable())->up(); } -} +} \ No newline at end of file