Skip to content

Commit

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

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

use App\Containers\AppSection\Authorization\Models\Permission;
use App\Containers\AppSection\Authorization\Tests\TestCase;

/**
* Class PermissionFactoryTest.
*
* @group authorization
* @group unit
*/
class PermissionFactoryTest extends TestCase
{
public function testCreatePermission(): void
{
$permission = Permission::factory()->create();

$this->assertInstanceOf(Permission::class, $permission);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

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

use App\Containers\AppSection\Authorization\Models\Role;
use App\Containers\AppSection\Authorization\Tests\TestCase;

/**
* Class RoleFactoryTest.
*
* @group authorization
* @group unit
*/
class RoleFactoryTest extends TestCase
{
public function testCreateRole(): void
{
$role = Role::factory()->create();

$this->assertInstanceOf(Role::class, $role);
}

public function testCreateAdminRole(): void
{
// 'admin' role is seeded into db automatically, so we have to remove it first before we can test creating it
// using factory
Role::findByName(config('appSection-authorization.admin_role'))->delete();

$role = Role::factory()->admin()->create();

$this->assertEquals(config('appSection-authorization.admin_role'), $role->name);
}
}
7 changes: 7 additions & 0 deletions app/Containers/AppSection/User/Tests/Unit/UserFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
*/
class UserFactoryTest extends TestCase
{
public function testCreateUser(): void
{
$user = User::factory()->create();

$this->assertInstanceOf(User::class, $user);
}

public function testCreateAdminUser(): void
{
$user = User::factory()->admin()->create();
Expand Down

0 comments on commit de9f0d1

Please sign in to comment.