Skip to content

Commit

Permalink
Merge pull request #34252 from open-source-contributions/improve_auth…
Browse files Browse the repository at this point in the history
…_test_assert

Improve assertions for classes on Auth folder
  • Loading branch information
driesvints authored Sep 10, 2020
2 parents f7493ab + e8977ad commit 6af0565
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions tests/Auth/AuthAccessGateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function testCurrentUserThatIsOnGateAlwaysInjectedIntoClosureCallbacks()
$gate = $this->getBasicGate();

$gate->define('foo', function ($user) {
$this->assertEquals(1, $user->id);
$this->assertSame(1, $user->id);

return true;
});
Expand Down Expand Up @@ -519,7 +519,7 @@ public function testForUserMethodAttachesANewUserToANewGateInstance()

// Assert that the callback receives the new user with ID of 2 instead of ID of 1...
$gate->define('foo', function ($user) {
$this->assertEquals(2, $user->id);
$this->assertSame(2, $user->id);

return true;
});
Expand All @@ -541,16 +541,16 @@ public function testForUserMethodAttachesANewUserToANewGateInstanceWithGuessCall
};
$gate->guessPolicyNamesUsing($guesserCallback);
$gate->getPolicyFor('fooClass');
$this->assertEquals(1, $counter);
$this->assertSame(1, $counter);

// now the guesser callback should be present on the new gate as well
$newGate = $gate->forUser((object) ['id' => 1]);

$newGate->getPolicyFor('fooClass');
$this->assertEquals(2, $counter);
$this->assertSame(2, $counter);

$newGate->getPolicyFor('fooClass');
$this->assertEquals(3, $counter);
$this->assertSame(3, $counter);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Auth/AuthDatabaseUserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testRetrieveByIDReturnsUserWhenUserIsFound()
$user = $provider->retrieveById(1);

$this->assertInstanceOf(GenericUser::class, $user);
$this->assertEquals(1, $user->getAuthIdentifier());
$this->assertSame(1, $user->getAuthIdentifier());
$this->assertSame('Dayle', $user->name);
}

Expand Down Expand Up @@ -98,7 +98,7 @@ public function testRetrieveByCredentialsReturnsUserWhenUserIsFound()
$user = $provider->retrieveByCredentials(['username' => 'dayle', 'password' => 'foo', 'group' => ['one', 'two']]);

$this->assertInstanceOf(GenericUser::class, $user);
$this->assertEquals(1, $user->getAuthIdentifier());
$this->assertSame(1, $user->getAuthIdentifier());
$this->assertSame('taylor', $user->name);
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Auth/AuthPasswordBrokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testIfUserIsNotFoundErrorRedirectIsReturned()
$broker = $this->getMockBuilder(PasswordBroker::class)->setMethods(['getUser', 'makeErrorRedirect'])->setConstructorArgs(array_values($mocks))->getMock();
$broker->expects($this->once())->method('getUser')->willReturn(null);

$this->assertEquals(PasswordBrokerContract::INVALID_USER, $broker->sendResetLink(['credentials']));
$this->assertSame(PasswordBrokerContract::INVALID_USER, $broker->sendResetLink(['credentials']));
}

public function testIfTokenIsRecentlyCreated()
Expand All @@ -37,7 +37,7 @@ public function testIfTokenIsRecentlyCreated()
$mocks['tokens']->shouldReceive('recentlyCreatedToken')->once()->with($user)->andReturn(true);
$user->shouldReceive('sendPasswordResetNotification')->with('token');

$this->assertEquals(PasswordBrokerContract::RESET_THROTTLED, $broker->sendResetLink(['foo']));
$this->assertSame(PasswordBrokerContract::RESET_THROTTLED, $broker->sendResetLink(['foo']));
}

public function testGetUserThrowsExceptionIfUserDoesntImplementCanResetPassword()
Expand Down Expand Up @@ -68,15 +68,15 @@ public function testBrokerCreatesTokenAndRedirectsWithoutError()
$mocks['tokens']->shouldReceive('create')->once()->with($user)->andReturn('token');
$user->shouldReceive('sendPasswordResetNotification')->with('token');

$this->assertEquals(PasswordBrokerContract::RESET_LINK_SENT, $broker->sendResetLink(['foo']));
$this->assertSame(PasswordBrokerContract::RESET_LINK_SENT, $broker->sendResetLink(['foo']));
}

public function testRedirectIsReturnedByResetWhenUserCredentialsInvalid()
{
$broker = $this->getBroker($mocks = $this->getMocks());
$mocks['users']->shouldReceive('retrieveByCredentials')->once()->with(['creds'])->andReturn(null);

$this->assertEquals(PasswordBrokerContract::INVALID_USER, $broker->reset(['creds'], function () {
$this->assertSame(PasswordBrokerContract::INVALID_USER, $broker->reset(['creds'], function () {
//
}));
}
Expand All @@ -88,7 +88,7 @@ public function testRedirectReturnedByRemindWhenRecordDoesntExistInTable()
$mocks['users']->shouldReceive('retrieveByCredentials')->once()->with(Arr::except($creds, ['token']))->andReturn($user = m::mock(CanResetPassword::class));
$mocks['tokens']->shouldReceive('exists')->with($user, 'token')->andReturn(false);

$this->assertEquals(PasswordBrokerContract::INVALID_TOKEN, $broker->reset($creds, function () {
$this->assertSame(PasswordBrokerContract::INVALID_TOKEN, $broker->reset($creds, function () {
//
}));
}
Expand All @@ -105,7 +105,7 @@ public function testResetRemovesRecordOnReminderTableAndCallsCallback()
return 'foo';
};

$this->assertEquals(PasswordBrokerContract::PASSWORD_RESET, $broker->reset(['password' => 'password', 'token' => 'token'], $callback));
$this->assertSame(PasswordBrokerContract::PASSWORD_RESET, $broker->reset(['password' => 'password', 'token' => 'token'], $callback));
$this->assertEquals(['user' => $user, 'password' => 'password'], $_SERVER['__password.reset.test']);
}

Expand Down
22 changes: 11 additions & 11 deletions tests/Auth/AuthTokenGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public function testUserCanBeRetrievedByQueryStringVariable()

$user = $guard->user();

$this->assertEquals(1, $user->id);
$this->assertSame(1, $user->id);
$this->assertTrue($guard->check());
$this->assertFalse($guard->guest());
$this->assertEquals(1, $guard->id());
$this->assertSame(1, $guard->id());
}

public function testTokenCanBeHashed()
Expand All @@ -45,10 +45,10 @@ public function testTokenCanBeHashed()

$user = $guard->user();

$this->assertEquals(1, $user->id);
$this->assertSame(1, $user->id);
$this->assertTrue($guard->check());
$this->assertFalse($guard->guest());
$this->assertEquals(1, $guard->id());
$this->assertSame(1, $guard->id());
}

public function testUserCanBeRetrievedByAuthHeaders()
Expand All @@ -61,7 +61,7 @@ public function testUserCanBeRetrievedByAuthHeaders()

$user = $guard->user();

$this->assertEquals(1, $user->id);
$this->assertSame(1, $user->id);
}

public function testUserCanBeRetrievedByBearerToken()
Expand All @@ -74,7 +74,7 @@ public function testUserCanBeRetrievedByBearerToken()

$user = $guard->user();

$this->assertEquals(1, $user->id);
$this->assertSame(1, $user->id);
}

public function testValidateCanDetermineIfCredentialsAreValid()
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testItAllowsToPassCustomRequestInSetterAndUseItForValidation()

$user = $guard->user();

$this->assertEquals(1, $user->id);
$this->assertSame(1, $user->id);
}

public function testUserCanBeRetrievedByBearerTokenWithCustomKey()
Expand All @@ -137,7 +137,7 @@ public function testUserCanBeRetrievedByBearerTokenWithCustomKey()

$user = $guard->user();

$this->assertEquals(1, $user->id);
$this->assertSame(1, $user->id);
}

public function testUserCanBeRetrievedByQueryStringVariableWithCustomKey()
Expand All @@ -152,10 +152,10 @@ public function testUserCanBeRetrievedByQueryStringVariableWithCustomKey()

$user = $guard->user();

$this->assertEquals(1, $user->id);
$this->assertSame(1, $user->id);
$this->assertTrue($guard->check());
$this->assertFalse($guard->guest());
$this->assertEquals(1, $guard->id());
$this->assertSame(1, $guard->id());
}

public function testUserCanBeRetrievedByAuthHeadersWithCustomField()
Expand All @@ -168,7 +168,7 @@ public function testUserCanBeRetrievedByAuthHeadersWithCustomField()

$user = $guard->user();

$this->assertEquals(1, $user->id);
$this->assertSame(1, $user->id);
}

public function testValidateCanDetermineIfCredentialsAreValidWithCustomKey()
Expand Down

0 comments on commit 6af0565

Please sign in to comment.