Last active
September 28, 2019 08:53
-
-
Save tonyfrenzy/92ff0f9ddea4c91d4027f3528fa8c646 to your computer and use it in GitHub Desktop.
belongsToMany() Relationship Test I (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 UserTest extends TestCase | |
{ | |
use RefreshDatabase, WithFaker; | |
/** @test */ | |
public function a_user_belongs_to_many_roles() | |
{ | |
$user = factory(User::class)->create(); | |
$role = factory(Role::class)->create(); | |
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->roles); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment