Skip to content

Commit

Permalink
add migration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Oct 3, 2021
1 parent 162f711 commit 7b4c2ea
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace App\Containers\AppSection\Authorization\Tests\Unit;

use App\Containers\AppSection\Authorization\Tests\TestCase;
use Illuminate\Support\Facades\Schema;

/**
* Class PermissionMigrationTest.
*
* @group authorization
* @group unit
*/
class PermissionMigrationTest extends TestCase
{
private array $tableNames;
private array $columnNames;

protected function setUp(): void
{
parent::setUp();
$this->tableNames = config('permission.table_names');
$this->columnNames = config('permission.column_names');
}

public function test_permissions_table_has_expected_columns(): void
{
$columns = [
'id',
'name',
'guard_name',
'display_name',
'description',
];

foreach ($columns as $column) {
$this->assertTrue(Schema::hasColumn($this->tableNames['permissions'], $column));
}
}

public function test_roles_table_has_expected_columns(): void
{
$columns = [
'id',
'name',
'guard_name',
'display_name',
'description',
'created_at',
'updated_at',
];

foreach ($columns as $column) {
$this->assertTrue(Schema::hasColumn($this->tableNames['roles'], $column));
}
}

public function test_model_has_permissions_table_has_expected_columns(): void
{
$columns = [
'permission_id',
'model_type',
$this->columnNames['model_morph_key'],
];

foreach ($columns as $column) {
$this->assertTrue(Schema::hasColumn($this->tableNames['model_has_permissions'], $column));
}
}

public function test_model_has_roles_table_has_expected_columns(): void
{
$columns = [
'role_id',
'model_type',
$this->columnNames['model_morph_key'],
];

foreach ($columns as $column) {
$this->assertTrue(Schema::hasColumn($this->tableNames['model_has_roles'], $column));
}
}

public function test_role_has_permissions_table_has_expected_columns(): void
{
$columns = [
'permission_id',
'role_id',
];

foreach ($columns as $column) {
$this->assertTrue(Schema::hasColumn($this->tableNames['role_has_permissions'], $column));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Containers\AppSection\User\Tests\Unit;

use App\Containers\AppSection\User\Tests\TestCase;
use Illuminate\Support\Facades\Schema;

/**
* Class PasswordResetsMigrationTest.
*
* @group user
* @group unit
*/
class PasswordResetsMigrationTest extends TestCase
{
public function test_password_resets_table_has_expected_columns(): void
{
$columns = [
'email',
'token',
'created_at',
];

foreach ($columns as $column) {
$this->assertTrue(Schema::hasColumn('password_resets', $column));
}
}
}
34 changes: 34 additions & 0 deletions app/Containers/AppSection/User/Tests/Unit/UsersMigrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Containers\AppSection\User\Tests\Unit;

use App\Containers\AppSection\User\Tests\TestCase;
use Illuminate\Support\Facades\Schema;

/**
* Class UsersMigrationTest.
*
* @group user
* @group unit
*/
class UsersMigrationTest extends TestCase
{
public function test_users_table_has_expected_columns(): void
{
$columns = [
'id',
'name',
'email',
'password',
'email_verified_at',
'gender',
'remember_token',
'created_at',
'updated_at',
];

foreach ($columns as $column) {
$this->assertTrue(Schema::hasColumn('users', $column));
}
}
}

0 comments on commit 7b4c2ea

Please sign in to comment.