Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 6 additions & 8 deletions database/migrations/create_role_user_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand All @@ -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');
}
}
}
4 changes: 2 additions & 2 deletions database/migrations/create_roles_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -32,4 +32,4 @@ public function down()
{
Schema::dropIfExists('roles');
}
}
}
36 changes: 36 additions & 0 deletions database/migrations/create_user_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->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');
}
}
26 changes: 21 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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);

Expand Down Expand Up @@ -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();
}
}
}