Skip to content

Commit

Permalink
Merge branch '4.4' into 5.2
Browse files Browse the repository at this point in the history
* 4.4:
  Use createMock() instead of a getter
  [ErrorHandler] Fix strpos error when trying to call a method without a name
  use proper keys to not override appended files
  Fix console logger according to PSR-3
  • Loading branch information
jderusse committed Jan 28, 2021
2 parents 6c7314e + 0eb87f9 commit a468c86
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Tests/Authentication/AuthenticationTrustResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ protected function getRememberMeToken()
protected function getResolver()
{
return new AuthenticationTrustResolver(
'Symfony\\Component\\Security\\Core\\Authentication\\Token\\AnonymousToken',
'Symfony\\Component\\Security\\Core\\Authentication\\Token\\RememberMeToken'
AnonymousToken::class,
RememberMeToken::class
);
}
}
Expand Down
60 changes: 25 additions & 35 deletions Tests/User/ChainUserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ class ChainUserProviderTest extends TestCase
{
public function testLoadUserByUsername()
{
$provider1 = $this->getProvider();
$provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('loadUserByUsername')
->with($this->equalTo('foo'))
->willThrowException(new UsernameNotFoundException('not found'))
;

$provider2 = $this->getProvider();
$provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('loadUserByUsername')
->with($this->equalTo('foo'))
->willReturn($account = $this->getAccount())
->willReturn($account = $this->createMock(UserInterface::class))
;

$provider = new ChainUserProvider([$provider1, $provider2]);
Expand All @@ -47,15 +47,15 @@ public function testLoadUserByUsername()
public function testLoadUserByUsernameThrowsUsernameNotFoundException()
{
$this->expectException(UsernameNotFoundException::class);
$provider1 = $this->getProvider();
$provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('loadUserByUsername')
->with($this->equalTo('foo'))
->willThrowException(new UsernameNotFoundException('not found'))
;

$provider2 = $this->getProvider();
$provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('loadUserByUsername')
Expand All @@ -69,14 +69,14 @@ public function testLoadUserByUsernameThrowsUsernameNotFoundException()

public function testRefreshUser()
{
$provider1 = $this->getProvider();
$provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
->willReturn(false)
;

$provider2 = $this->getProvider();
$provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
Expand All @@ -89,7 +89,7 @@ public function testRefreshUser()
->willThrowException(new UnsupportedUserException('unsupported'))
;

$provider3 = $this->getProvider();
$provider3 = $this->createMock(UserProviderInterface::class);
$provider3
->expects($this->once())
->method('supportsClass')
Expand All @@ -99,16 +99,16 @@ public function testRefreshUser()
$provider3
->expects($this->once())
->method('refreshUser')
->willReturn($account = $this->getAccount())
->willReturn($account = $this->createMock(UserInterface::class))
;

$provider = new ChainUserProvider([$provider1, $provider2, $provider3]);
$this->assertSame($account, $provider->refreshUser($this->getAccount()));
$this->assertSame($account, $provider->refreshUser($this->createMock(UserInterface::class)));
}

public function testRefreshUserAgain()
{
$provider1 = $this->getProvider();
$provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
Expand All @@ -121,7 +121,7 @@ public function testRefreshUserAgain()
->willThrowException(new UsernameNotFoundException('not found'))
;

$provider2 = $this->getProvider();
$provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
Expand All @@ -131,17 +131,17 @@ public function testRefreshUserAgain()
$provider2
->expects($this->once())
->method('refreshUser')
->willReturn($account = $this->getAccount())
->willReturn($account = $this->createMock(UserInterface::class))
;

$provider = new ChainUserProvider([$provider1, $provider2]);
$this->assertSame($account, $provider->refreshUser($this->getAccount()));
$this->assertSame($account, $provider->refreshUser($this->createMock(UserInterface::class)));
}

public function testRefreshUserThrowsUnsupportedUserException()
{
$this->expectException(UnsupportedUserException::class);
$provider1 = $this->getProvider();
$provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
Expand All @@ -154,7 +154,7 @@ public function testRefreshUserThrowsUnsupportedUserException()
->willThrowException(new UnsupportedUserException('unsupported'))
;

$provider2 = $this->getProvider();
$provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
Expand All @@ -168,20 +168,20 @@ public function testRefreshUserThrowsUnsupportedUserException()
;

$provider = new ChainUserProvider([$provider1, $provider2]);
$provider->refreshUser($this->getAccount());
$provider->refreshUser($this->createMock(UserInterface::class));
}

public function testSupportsClass()
{
$provider1 = $this->getProvider();
$provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
->with($this->equalTo('foo'))
->willReturn(false)
;

$provider2 = $this->getProvider();
$provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
Expand All @@ -195,15 +195,15 @@ public function testSupportsClass()

public function testSupportsClassWhenNotSupported()
{
$provider1 = $this->getProvider();
$provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
->with($this->equalTo('foo'))
->willReturn(false)
;

$provider2 = $this->getProvider();
$provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
Expand All @@ -217,7 +217,7 @@ public function testSupportsClassWhenNotSupported()

public function testAcceptsTraversable()
{
$provider1 = $this->getProvider();
$provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
Expand All @@ -230,7 +230,7 @@ public function testAcceptsTraversable()
->willThrowException(new UnsupportedUserException('unsupported'))
;

$provider2 = $this->getProvider();
$provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
Expand All @@ -240,11 +240,11 @@ public function testAcceptsTraversable()
$provider2
->expects($this->once())
->method('refreshUser')
->willReturn($account = $this->getAccount())
->willReturn($account = $this->createMock(UserInterface::class))
;

$provider = new ChainUserProvider(new \ArrayObject([$provider1, $provider2]));
$this->assertSame($account, $provider->refreshUser($this->getAccount()));
$this->assertSame($account, $provider->refreshUser($this->createMock(UserInterface::class)));
}

public function testPasswordUpgrades()
Expand All @@ -268,14 +268,4 @@ public function testPasswordUpgrades()
$provider = new ChainUserProvider([$provider1, $provider2]);
$provider->upgradePassword($user, 'foobar');
}

protected function getAccount()
{
return $this->createMock(UserInterface::class);
}

protected function getProvider()
{
return $this->createMock(UserProviderInterface::class);
}
}
7 changes: 1 addition & 6 deletions Tests/Validator/Constraints/UserPasswordValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function setUp(): void
{
$user = $this->createUser();
$this->tokenStorage = $this->createTokenStorage($user);
$this->encoder = $this->createPasswordEncoder();
$this->encoder = $this->createMock(PasswordEncoderInterface::class);
$this->encoderFactory = $this->createEncoderFactory($this->encoder);

parent::setUp();
Expand Down Expand Up @@ -154,11 +154,6 @@ protected function createUser()
return $mock;
}

protected function createPasswordEncoder($isPasswordValid = true)
{
return $this->createMock(PasswordEncoderInterface::class);
}

protected function createEncoderFactory($encoder = null)
{
$mock = $this->createMock(EncoderFactoryInterface::class);
Expand Down

0 comments on commit a468c86

Please sign in to comment.