-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Deprecated the AdvancedUserInterface #23508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,6 @@ public function getCredentials() | |
} | ||
} | ||
|
||
/** @noinspection PhpUndefinedClassInspection */ | ||
class AbstractTokenTest extends TestCase | ||
{ | ||
public function testGetUsername() | ||
|
@@ -185,10 +184,8 @@ public function testSetUser($user) | |
public function getUsers() | ||
{ | ||
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock(); | ||
$advancedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock(); | ||
|
||
return array( | ||
array($advancedUser), | ||
array($user), | ||
array(new TestUser('foo')), | ||
array('foo'), | ||
|
@@ -212,53 +209,59 @@ public function testSetUserSetsAuthenticatedToFalseWhenUserChanges($firstUser, $ | |
} | ||
|
||
public function getUserChanges() | ||
{ | ||
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock(); | ||
|
||
return array( | ||
array('foo', 'bar'), | ||
array('foo', new TestUser('bar')), | ||
array('foo', $user), | ||
array($user, 'foo'), | ||
array($user, new TestUser('foo')), | ||
array(new TestUser('foo'), new TestUser('bar')), | ||
array(new TestUser('foo'), 'bar'), | ||
array(new TestUser('foo'), $user), | ||
); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
* | ||
* @dataProvider getUserChangesAdvancedUser | ||
*/ | ||
public function testSetUserSetsAuthenticatedToFalseWhenUserChangesdvancedUser($firstUser, $secondUser) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an 'A' missing here to complete the word 'Advanced' :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, you're completely right! If you wish, you could make a PR to fix this (you can just click the edit file). Gives you a nice contributor tag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do =) Thank you. |
||
{ | ||
$token = $this->getToken(); | ||
$token->setAuthenticated(true); | ||
$this->assertTrue($token->isAuthenticated()); | ||
|
||
$token->setUser($firstUser); | ||
$this->assertTrue($token->isAuthenticated()); | ||
|
||
$token->setUser($secondUser); | ||
$this->assertFalse($token->isAuthenticated()); | ||
} | ||
|
||
public function getUserChangesAdvancedUser() | ||
{ | ||
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock(); | ||
$advancedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock(); | ||
|
||
return array( | ||
array( | ||
'foo', 'bar', | ||
), | ||
array( | ||
'foo', new TestUser('bar'), | ||
), | ||
array( | ||
'foo', $user, | ||
), | ||
array( | ||
'foo', $advancedUser, | ||
), | ||
array( | ||
$user, 'foo', | ||
), | ||
array( | ||
$advancedUser, 'foo', | ||
), | ||
array( | ||
$user, new TestUser('foo'), | ||
), | ||
array( | ||
$advancedUser, new TestUser('foo'), | ||
), | ||
array( | ||
new TestUser('foo'), new TestUser('bar'), | ||
), | ||
array( | ||
new TestUser('foo'), 'bar', | ||
), | ||
array( | ||
new TestUser('foo'), $user, | ||
), | ||
array( | ||
new TestUser('foo'), $advancedUser, | ||
), | ||
array( | ||
$user, $advancedUser, | ||
), | ||
array( | ||
$advancedUser, $user, | ||
), | ||
array('foo', 'bar'), | ||
array('foo', new TestUser('bar')), | ||
array('foo', $user), | ||
array('foo', $advancedUser), | ||
array($user, 'foo'), | ||
array($advancedUser, 'foo'), | ||
array($user, new TestUser('foo')), | ||
array($advancedUser, new TestUser('foo')), | ||
array(new TestUser('foo'), new TestUser('bar')), | ||
array(new TestUser('foo'), 'bar'), | ||
array(new TestUser('foo'), $user), | ||
array(new TestUser('foo'), $advancedUser), | ||
array($user, $advancedUser), | ||
array($advancedUser, $user), | ||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\Component\Security\Core\Tests\User; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Security\Core\User\User; | ||
use Symfony\Component\Security\Core\User\UserChecker; | ||
|
||
class UserCheckerTest extends TestCase | ||
|
@@ -24,6 +25,16 @@ public function testCheckPostAuthNotAdvancedUserInterface() | |
} | ||
|
||
public function testCheckPostAuthPass() | ||
{ | ||
$checker = new UserChecker(); | ||
$this->assertNull($checker->checkPostAuth(new User('John', 'password'))); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing |
||
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPostAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality. | ||
*/ | ||
public function testCheckPostAuthPassAdvancedUser() | ||
{ | ||
$checker = new UserChecker(); | ||
|
||
|
@@ -39,21 +50,29 @@ public function testCheckPostAuthPass() | |
public function testCheckPostAuthCredentialsExpired() | ||
{ | ||
$checker = new UserChecker(); | ||
|
||
$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock(); | ||
$account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(false)); | ||
|
||
$checker->checkPostAuth($account); | ||
$checker->checkPostAuth(new User('John', 'password', array(), true, true, false, true)); | ||
} | ||
|
||
public function testCheckPreAuthNotAdvancedUserInterface() | ||
/** | ||
* @group legacy | ||
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPostAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality. | ||
* @expectedException \Symfony\Component\Security\Core\Exception\CredentialsExpiredException | ||
*/ | ||
public function testCheckPostAuthCredentialsExpiredAdvancedUser() | ||
{ | ||
$checker = new UserChecker(); | ||
|
||
$this->assertNull($checker->checkPreAuth($this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock())); | ||
$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock(); | ||
$account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(false)); | ||
|
||
$checker->checkPostAuth($account); | ||
} | ||
|
||
public function testCheckPreAuthPass() | ||
/** | ||
* @group legacy | ||
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPreAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality. | ||
*/ | ||
public function testCheckPreAuthPassAdvancedUser() | ||
{ | ||
$checker = new UserChecker(); | ||
|
||
|
@@ -69,6 +88,17 @@ public function testCheckPreAuthPass() | |
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException | ||
*/ | ||
public function testCheckPreAuthAccountLocked() | ||
{ | ||
$checker = new UserChecker(); | ||
$checker->checkPreAuth(new User('John', 'password', array(), true, true, false, false)); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPreAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality. | ||
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException | ||
*/ | ||
public function testCheckPreAuthAccountLockedAdvancedUser() | ||
{ | ||
$checker = new UserChecker(); | ||
|
||
|
@@ -82,6 +112,17 @@ public function testCheckPreAuthAccountLocked() | |
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException | ||
*/ | ||
public function testCheckPreAuthDisabled() | ||
{ | ||
$checker = new UserChecker(); | ||
$checker->checkPreAuth(new User('John', 'password', array(), false, true, false, true)); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPreAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality. | ||
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException | ||
*/ | ||
public function testCheckPreAuthDisabledAdvancedUser() | ||
{ | ||
$checker = new UserChecker(); | ||
|
||
|
@@ -96,6 +137,17 @@ public function testCheckPreAuthDisabled() | |
* @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException | ||
*/ | ||
public function testCheckPreAuthAccountExpired() | ||
{ | ||
$checker = new UserChecker(); | ||
$checker->checkPreAuth(new User('John', 'password', array(), true, false, true, true)); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPreAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality. | ||
* @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException | ||
*/ | ||
public function testCheckPreAuthAccountExpiredAdvancedUser() | ||
{ | ||
$checker = new UserChecker(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just wondering since I'm not too familiar with the Symfony testing guidelines: Wouldn't it be easier and more refactoring-friendly to use the
::class
constants here instead of hand-writing the FQCN?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency in this case. I personally would update everything to use
::class
, but that might cause merge conflicts for no reason when merging changes from lower branches upwards.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough :) Thanks!
Opened #26349