Last active
September 28, 2019 08:53
-
-
Save tonyfrenzy/5ddc9bdf96d2355c3e306a781228fb26 to your computer and use it in GitHub Desktop.
belongsToMany() Relationship Test 2 (User-Role) - Testing Model Relationships in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests\Unit; | |
use App\Role; | |
use App\User; | |
use Illuminate\Foundation\Testing\RefreshDatabase; | |
use Illuminate\Foundation\Testing\WithFaker; | |
use Illuminate\Support\Facades\Schema; | |
use Tests\TestCase; | |
class RolesTest extends TestCase | |
{ | |
use RefreshDatabase, WithFaker; | |
/** @test */ | |
public function roles_database_has_expected_columns() | |
{ | |
$this->assertTrue( | |
Schema::hasColumns('roles', [ | |
'id', 'title', 'description' | |
]), 1); | |
} | |
/** @test */ | |
public function a_role_belongs_to_many_users() | |
{ | |
$user = factory(User::class)->create(); | |
$role = factory(Role::class)->create(); | |
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $role->users); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment