diff --git a/src/Illuminate/Auth/RequestGuard.php b/src/Illuminate/Auth/RequestGuard.php index d756268d4f9c..2adc2cc35302 100644 --- a/src/Illuminate/Auth/RequestGuard.php +++ b/src/Illuminate/Auth/RequestGuard.php @@ -80,8 +80,6 @@ public function validate(array $credentials = []) */ public function setRequest(Request $request) { - $this->user = null; - $this->request = $request; return $this; diff --git a/tests/Integration/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php b/tests/Integration/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php new file mode 100644 index 000000000000..9bcb15897a4b --- /dev/null +++ b/tests/Integration/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php @@ -0,0 +1,100 @@ +set('auth.providers.users.model', AuthenticationTestUser::class); + + $app['config']->set('database.default', 'testbench'); + $app['config']->set('database.connections.testbench', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ]); + } + + public function setUp() + { + parent::setUp(); + + Schema::create('users', function ($table) { + $table->increments('id'); + $table->string('email'); + $table->string('username'); + $table->string('password'); + $table->string('remember_token')->default(null)->nullable(); + $table->tinyInteger('is_active')->default(0); + }); + + AuthenticationTestUser::create([ + 'username' => 'taylorotwell', + 'email' => 'taylorotwell@laravel.com', + 'password' => bcrypt('password'), + 'is_active' => true, + ]); + } + + public function test_acting_as_is_properly_handled_for_session_auth() + { + Route::get('me', function (Request $request) { + return 'Hello '.$request->user()->username; + })->middleware(['auth']); + + $user = AuthenticationTestUser::where('username', '=', 'taylorotwell')->first(); + + $this->actingAs($user) + ->get('/me') + ->assertSuccessful() + ->assertSeeText('Hello taylorotwell'); + } + + public function test_acting_as_is_properly_handled_for_auth_via_request() + { + Route::get('me', function (Request $request) { + return 'Hello '.$request->user()->username; + })->middleware(['auth:api']); + + Auth::viaRequest('api', function ($request) { + return $request->user(); + }); + + $user = AuthenticationTestUser::where('username', '=', 'taylorotwell')->first(); + + $this->actingAs($user, 'api') + ->get('/me') + ->assertSuccessful() + ->assertSeeText('Hello taylorotwell'); + } +} + +class AuthenticationTestUser extends Authenticatable +{ + public $table = 'users'; + public $timestamps = false; + + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $guarded = ['id']; + + /** + * The attributes that should be hidden for arrays. + * + * @var array + */ + protected $hidden = [ + 'password', 'remember_token', + ]; +} diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 5b054395b362..870a1b770c33 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -984,11 +984,10 @@ public function testExcept() $this->assertEquals(['first' => 'Taylor'], $data->except(['last', 'email', 'missing'])->all()); $this->assertEquals(['first' => 'Taylor'], $data->except('last', 'email', 'missing')->all()); - $this->assertEquals(['first' => 'Taylor'], $data->except(collect(['last', 'email', 'missing']))->all()); + $this->assertEquals(['first' => 'Taylor'], $data->except(collect(['last', 'email', 'missing']))->all()); $this->assertEquals(['first' => 'Taylor', 'email' => 'taylorotwell@gmail.com'], $data->except(['last'])->all()); $this->assertEquals(['first' => 'Taylor', 'email' => 'taylorotwell@gmail.com'], $data->except('last')->all()); - $this->assertEquals(['first' => 'Taylor', 'email' => 'taylorotwell@gmail.com'], $data->except(collect(['last']))->all()); } public function testPluckWithArrayAndObjectValues()