{"action":"created","issue":{"url":"https://api.github.com/repos/Kbwebs/MultiAuth/issues/17","labels_url":"https://api.github.com/repos/Kbwebs/MultiAuth/issues/17/labels{/name}","comments_url":"https://api.github.com/repos/Kbwebs/MultiAuth/issues/17/comments","events_url":"https://api.github.com/repos/Kbwebs/MultiAuth/issues/17/events","html_url":"https://github.com/Kbwebs/MultiAuth/issues/17","id":115837193,"number":17,"title":"MultiAuth inside Integrated Testing","user":{"login":"foxlance","id":914792,"avatar_url":"https://avatars.githubusercontent.com/u/914792?v=3","gravatar_id":"","url":"https://api.github.com/users/foxlance","html_url":"https://github.com/foxlance","followers_url":"https://api.github.com/users/foxlance/followers","following_url":"https://api.github.com/users/foxlance/following{/other_user}","gists_url":"https://api.github.com/users/foxlance/gists{/gist_id}","starred_url":"https://api.github.com/users/foxlance/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/foxlance/subscriptions","organizations_url":"https://api.github.com/users/foxlance/orgs","repos_url":"https://api.github.com/users/foxlance/repos","events_url":"https://api.github.com/users/foxlance/events{/privacy}","received_events_url":"https://api.github.com/users/foxlance/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-09T09:23:13Z","updated_at":"2015-11-10T08:44:49Z","closed_at":null,"body":"Hi KB,\r\n\r\nTrying out TDD with Laravel using your package. I wrote the following test:\r\n\r\n```php\r\n/**\r\n * Login with proper credentials\r\n */\r\npublic function testProperLogin()\r\n{\r\n    $user = factory(App\\User::class)->create();\r\n\r\n    $this->actingAs($user)\r\n        ->visit('/testlink')\r\n        ->see('Howdy '.$user->first_name);\r\n}\r\n```\r\n\r\nTo match against:\r\n\r\n```php\r\nRoute::get('testlink', function(){\r\n    return 'Howdy '.Auth::user()->get()->first_name;\r\n});\r\n```\r\n\r\nHowever, Im greeted with a \"trying to get property of non-object\". I'm assuming its because actingAs() doesn't recognize the way you handle Auth::user(). I'd love to stick with your package without sacrificing Auth within my test.\r\n\r\nAny ideas, or am I doing something wrong?"},"comment":{"url":"https://api.github.com/repos/Kbwebs/MultiAuth/issues/comments/155359456","html_url":"https://github.com/Kbwebs/MultiAuth/issues/17#issuecomment-155359456","issue_url":"https://api.github.com/repos/Kbwebs/MultiAuth/issues/17","id":155359456,"user":{"login":"aceraven777","id":2563083,"avatar_url":"https://avatars.githubusercontent.com/u/2563083?v=3","gravatar_id":"","url":"https://api.github.com/users/aceraven777","html_url":"https://github.com/aceraven777","followers_url":"https://api.github.com/users/aceraven777/followers","following_url":"https://api.github.com/users/aceraven777/following{/other_user}","gists_url":"https://api.github.com/users/aceraven777/gists{/gist_id}","starred_url":"https://api.github.com/users/aceraven777/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aceraven777/subscriptions","organizations_url":"https://api.github.com/users/aceraven777/orgs","repos_url":"https://api.github.com/users/aceraven777/repos","events_url":"https://api.github.com/users/aceraven777/events{/privacy}","received_events_url":"https://api.github.com/users/aceraven777/received_events","type":"User","site_admin":false},"created_at":"2015-11-10T08:44:49Z","updated_at":"2015-11-10T08:44:49Z","body":"Hi @foxlance ,\r\n\r\nBecause kbwebs/multiauth entirely replaces the laravel's auth, I was able to fix this by overriding the `actingAs()` and `be()` method in TestCase class.\r\n\r\nSo in my /tests/TestCase.php class:\r\n\r\n```\r\n<?php\r\n\r\nuse Illuminate\\Contracts\\Auth\\Authenticatable as UserContract;\r\n\r\nclass TestCase extends Illuminate\\Foundation\\Testing\\TestCase\r\n{\r\n    /**\r\n     * The base URL to use while testing the application.\r\n     *\r\n     * @var string\r\n     */\r\n    protected $baseUrl = 'http://localhost';\r\n\r\n    /**\r\n     * Creates the application.\r\n     *\r\n     * @return \\Illuminate\\Foundation\\Application\r\n     */\r\n    public function createApplication()\r\n    {\r\n        $app = require __DIR__.'/../bootstrap/app.php';\r\n\r\n        $app->make(Illuminate\\Contracts\\Console\\Kernel::class)->bootstrap();\r\n\r\n        return $app;\r\n    }\r\n\r\n    /**\r\n     * Set the currently logged in user for the application.\r\n     *\r\n     * @param  \\Illuminate\\Contracts\\Auth\\Authenticatable  $user\r\n     * @param  string       $type\r\n     * @param  string|null  $driver\r\n     * @return $this\r\n     */\r\n    public function actingAs(UserContract $user, $type = '', $driver = null)\r\n    {\r\n        $this->be($user, $type, $driver);\r\n\r\n        return $this;\r\n    }\r\n\r\n    /**\r\n     * Set the currently logged in user for the application.\r\n     *\r\n     * @param  \\Illuminate\\Contracts\\Auth\\Authenticatable  $user\r\n     * @param  string       $type\r\n     * @param  string|null  $driver\r\n     * @return void\r\n     */\r\n    public function be(UserContract $user, $type = '', $driver = null)\r\n    {\r\n        $this->app['auth']->$type()->driver($driver)->setUser($user);\r\n    }\r\n}\r\n```\r\n\r\nSo in order to use this, if you want to login in auth 'user':\r\n\r\n```\r\n$this->actingAs($user, 'user')\r\n    ->visit('/testlink')\r\n    ->see('Howdy '.$user->first_name);\r\n```\r\n\r\nTo login as admin:\r\n\r\n```\r\n$this->actingAs($user, 'admin')\r\n    ->visit('/testlink')\r\n    ->see('Howdy '.$user->first_name);\r\n```\r\n\r\nHope this helps :)"}}