Skip to content

Commit

Permalink
Remove calls to getMockForAbstractClass()
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed May 15, 2024
1 parent 42a12aa commit 49c9c6d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Tests/EventListener/PasswordMigratingListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function testUnsupportedPassport()

public function testUpgradeWithUpgrader()
{
$passwordUpgrader = $this->getMockForAbstractClass(TestMigratingUserProvider::class);
$passwordUpgrader = $this->createMock(TestMigratingUserProvider::class);
$passwordUpgrader->expects($this->once())
->method('upgradePassword')
->with($this->user, 'new-hash')
Expand All @@ -120,7 +120,7 @@ public function testUpgradeWithUpgrader()

public function testUpgradeWithoutUpgrader()
{
$userLoader = $this->getMockForAbstractClass(TestMigratingUserProvider::class);
$userLoader = $this->createMock(TestMigratingUserProvider::class);
$userLoader->expects($this->any())->method('loadUserByIdentifier')->willReturn($this->user);

$userLoader->expects($this->exactly(2))
Expand Down
74 changes: 45 additions & 29 deletions Tests/Firewall/AbstractPreAuthenticatedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ public function testHandleWithValidValues()
->willReturn($token)
;

$listener = $this->getMockForAbstractClass(AbstractPreAuthenticatedListener::class, [
$tokenStorage,
$authenticationManager,
'TheProviderKey',
]);
$listener = $this->getMockBuilder(AbstractPreAuthenticatedListener::class)
->setConstructorArgs([
$tokenStorage,
$authenticationManager,
'TheProviderKey',
])
->onlyMethods(['getPreAuthenticatedData'])
->getMock();

$listener
->expects($this->once())
->method('getPreAuthenticatedData')
Expand Down Expand Up @@ -95,12 +99,15 @@ public function testHandleWhenAuthenticationFails()
->willThrowException($exception)
;

$listener = $this->getMockForAbstractClass(
AbstractPreAuthenticatedListener::class, [
$tokenStorage,
$authenticationManager,
'TheProviderKey',
]);
$listener = $this->getMockBuilder(AbstractPreAuthenticatedListener::class)
->setConstructorArgs([
$tokenStorage,
$authenticationManager,
'TheProviderKey',
])
->onlyMethods(['getPreAuthenticatedData'])
->getMock();

$listener
->expects($this->once())
->method('getPreAuthenticatedData')
Expand Down Expand Up @@ -137,12 +144,15 @@ public function testHandleWhenAuthenticationFailsWithDifferentToken()
->willThrowException($exception)
;

$listener = $this->getMockForAbstractClass(
AbstractPreAuthenticatedListener::class, [
$tokenStorage,
$authenticationManager,
'TheProviderKey',
]);
$listener = $this->getMockBuilder(AbstractPreAuthenticatedListener::class)
->setConstructorArgs([
$tokenStorage,
$authenticationManager,
'TheProviderKey',
])
->onlyMethods(['getPreAuthenticatedData'])
->getMock();

$listener
->expects($this->once())
->method('getPreAuthenticatedData')
Expand Down Expand Up @@ -174,12 +184,15 @@ public function testHandleWithASimilarAuthenticatedToken()
->method('authenticate')
;

$listener = $this->getMockForAbstractClass(
AbstractPreAuthenticatedListener::class, [
$tokenStorage,
$authenticationManager,
'TheProviderKey',
]);
$listener = $this->getMockBuilder(AbstractPreAuthenticatedListener::class)
->setConstructorArgs([
$tokenStorage,
$authenticationManager,
'TheProviderKey',
])
->onlyMethods(['getPreAuthenticatedData'])
->getMock();

$listener
->expects($this->once())
->method('getPreAuthenticatedData')
Expand Down Expand Up @@ -217,12 +230,15 @@ public function testHandleWithAnInvalidSimilarToken()
->willThrowException($exception)
;

$listener = $this->getMockForAbstractClass(
AbstractPreAuthenticatedListener::class, [
$tokenStorage,
$authenticationManager,
'TheProviderKey',
]);
$listener = $this->getMockBuilder(AbstractPreAuthenticatedListener::class)
->setConstructorArgs([
$tokenStorage,
$authenticationManager,
'TheProviderKey',
])
->onlyMethods(['getPreAuthenticatedData'])
->getMock();

$listener
->expects($this->once())
->method('getPreAuthenticatedData')
Expand Down
9 changes: 6 additions & 3 deletions Tests/RememberMe/AbstractRememberMeServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,12 @@ protected function getService($userProvider = null, $options = [], $logger = nul
$userProvider = $this->getProvider();
}

return $this->getMockForAbstractClass(AbstractRememberMeServices::class, [
[$userProvider], 'foosecret', 'fookey', $options, $logger,
]);
return $this->getMockBuilder(AbstractRememberMeServices::class)
->setConstructorArgs([
[$userProvider], 'foosecret', 'fookey', $options, $logger,
])
->onlyMethods(['processAutoLoginCookie', 'onLoginSuccess'])
->getMock();
}

protected function getProvider()
Expand Down

0 comments on commit 49c9c6d

Please sign in to comment.