{"action":"created","issue":{"url":"https://api.github.com/repos/spatie/laravel-permission/issues/482","repository_url":"https://api.github.com/repos/spatie/laravel-permission","labels_url":"https://api.github.com/repos/spatie/laravel-permission/issues/482/labels{/name}","comments_url":"https://api.github.com/repos/spatie/laravel-permission/issues/482/comments","events_url":"https://api.github.com/repos/spatie/laravel-permission/issues/482/events","html_url":"https://github.com/spatie/laravel-permission/issues/482","id":261812657,"number":482,"title":"Why roles are not assigned in Unit test","user":{"login":"saqueib","id":6937224,"avatar_url":"https://avatars0.githubusercontent.com/u/6937224?v=4","gravatar_id":"","url":"https://api.github.com/users/saqueib","html_url":"https://github.com/saqueib","followers_url":"https://api.github.com/users/saqueib/followers","following_url":"https://api.github.com/users/saqueib/following{/other_user}","gists_url":"https://api.github.com/users/saqueib/gists{/gist_id}","starred_url":"https://api.github.com/users/saqueib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saqueib/subscriptions","organizations_url":"https://api.github.com/users/saqueib/orgs","repos_url":"https://api.github.com/users/saqueib/repos","events_url":"https://api.github.com/users/saqueib/events{/privacy}","received_events_url":"https://api.github.com/users/saqueib/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-09-30T02:58:53Z","updated_at":"2017-09-30T03:17:08Z","closed_at":null,"author_association":"NONE","body":"I am trying to Unit test role assignment on user but Its always returning false, no roles are getting assigned\r\n\r\n```php\r\nnamespace Tests\\Unit;\r\n\r\nuse App\\User;\r\nuse Tests\\TestCase;\r\nuse Spatie\\Permission\\Models\\Role;\r\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\r\n\r\nclass RoleTest extends TestCase\r\n{\r\n    use RefreshDatabase;\r\n\r\n    /**\r\n    * user can have roles assigned\r\n    *\r\n    * @test\r\n    */\r\n    function user_can_have_roles_assigned()\r\n    {\r\n        $roleAdmin = Role::create(['name' => 'Admin']);\r\n        $roleUser = Role::create(['name' => 'User']);\r\n\r\n        $user = factory(User::class)->create();\r\n\r\n        $this->assertFalse($user->hasRole('Admin'));\r\n        $user->assignRole($roleAdmin);\r\n        $this->assertTrue($user->hasRole('Admin'));\r\n\r\n        $this->assertFalse($user->hasRole('User'));\r\n        $user->assignRole($roleUser);\r\n        $this->assertTrue($user->hasRole('User'));\r\n\r\n        $this->assertTrue($user->hasAllRoles('User', 'Admin'));\r\n    }\r\n}\r\n```\r\n\r\n> For testing I am using in memory sqlite db\r\n\r\nI am planning to use it with Laravel Spark with Laravel 5.5, is it possible? \r\nWhats wrong in this test i am getting `$user->hasRole('Admin')` fasle."},"comment":{"url":"https://api.github.com/repos/spatie/laravel-permission/issues/comments/333279144","html_url":"https://github.com/spatie/laravel-permission/issues/482#issuecomment-333279144","issue_url":"https://api.github.com/repos/spatie/laravel-permission/issues/482","id":333279144,"user":{"login":"saqueib","id":6937224,"avatar_url":"https://avatars0.githubusercontent.com/u/6937224?v=4","gravatar_id":"","url":"https://api.github.com/users/saqueib","html_url":"https://github.com/saqueib","followers_url":"https://api.github.com/users/saqueib/followers","following_url":"https://api.github.com/users/saqueib/following{/other_user}","gists_url":"https://api.github.com/users/saqueib/gists{/gist_id}","starred_url":"https://api.github.com/users/saqueib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saqueib/subscriptions","organizations_url":"https://api.github.com/users/saqueib/orgs","repos_url":"https://api.github.com/users/saqueib/repos","events_url":"https://api.github.com/users/saqueib/events{/privacy}","received_events_url":"https://api.github.com/users/saqueib/received_events","type":"User","site_admin":false},"created_at":"2017-09-30T03:17:08Z","updated_at":"2017-09-30T03:17:08Z","author_association":"NONE","body":"Thanks for pointing this out, I will keep it in mind for permission testing, \r\nBut I am only testing for user roles. I have added above `setUp` code but it still doesn't work."}}
{"actor":{"display_login":"saqueib"}}