Skip to content

Commit 4ca59ad

Browse files
Use typed properties in tests as much as possible
1 parent ef6567d commit 4ca59ad

25 files changed

+109
-112
lines changed

Tests/Authentication/AuthenticatorManagerTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\Authentication;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Psr\Log\AbstractLogger;
1617
use Psr\Log\LoggerInterface;
@@ -37,12 +38,12 @@
3738

3839
class AuthenticatorManagerTest extends TestCase
3940
{
40-
private $tokenStorage;
41-
private $eventDispatcher;
42-
private $request;
43-
private $user;
44-
private $token;
45-
private $response;
41+
private MockObject&TokenStorageInterface $tokenStorage;
42+
private EventDispatcher $eventDispatcher;
43+
private Request $request;
44+
private InMemoryUser $user;
45+
private MockObject&TokenInterface $token;
46+
private Response $response;
4647

4748
protected function setUp(): void
4849
{
@@ -343,7 +344,7 @@ public function testLogsUseTheDecoratedAuthenticatorWhenItIsTraceable()
343344
->willReturn($this->response);
344345

345346
$logger = new class() extends AbstractLogger {
346-
public $logContexts = [];
347+
public array $logContexts = [];
347348

348349
public function log($level, $message, array $context = []): void
349350
{

Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\Authentication;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Psr\Log\LoggerInterface;
1617
use Symfony\Component\HttpFoundation\ParameterBag;
@@ -26,13 +27,13 @@
2627

2728
class DefaultAuthenticationFailureHandlerTest extends TestCase
2829
{
29-
private $httpKernel;
30-
private $httpUtils;
31-
private $logger;
32-
private $request;
33-
private $response;
34-
private $session;
35-
private $exception;
30+
private MockObject&HttpKernelInterface $httpKernel;
31+
private MockObject&HttpUtils $httpUtils;
32+
private MockObject&LoggerInterface $logger;
33+
private Request $request;
34+
private Response $response;
35+
private MockObject&SessionInterface $session;
36+
private AuthenticationException $exception;
3637

3738
protected function setUp(): void
3839
{

Tests/Authenticator/AbstractLoginFormAuthenticatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static function provideSupportsData(): iterable
9898

9999
class ConcreteFormAuthenticator extends AbstractLoginFormAuthenticator
100100
{
101-
private $loginUrl;
101+
private string $loginUrl;
102102

103103
public function __construct(string $loginUrl)
104104
{

Tests/Authenticator/FormLoginAuthenticatorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\Authenticator;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpFoundation\Session\SessionInterface;
@@ -28,11 +29,10 @@
2829

2930
class FormLoginAuthenticatorTest extends TestCase
3031
{
31-
private $userProvider;
32-
private $successHandler;
33-
private $failureHandler;
34-
/** @var FormLoginAuthenticator */
35-
private $authenticator;
32+
private InMemoryUserProvider $userProvider;
33+
private MockObject&AuthenticationSuccessHandlerInterface $successHandler;
34+
private MockObject&AuthenticationFailureHandlerInterface $failureHandler;
35+
private FormLoginAuthenticator $authenticator;
3636

3737
protected function setUp(): void
3838
{

Tests/Authenticator/HttpBasicAuthenticatorTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,19 @@
2424

2525
class HttpBasicAuthenticatorTest extends TestCase
2626
{
27-
private $userProvider;
28-
private $hasherFactory;
29-
private $hasher;
30-
private $authenticator;
27+
private InMemoryUserProvider $userProvider;
28+
private HttpBasicAuthenticator $authenticator;
3129

3230
protected function setUp(): void
3331
{
3432
$this->userProvider = new InMemoryUserProvider();
35-
$this->hasherFactory = $this->createMock(PasswordHasherFactoryInterface::class);
36-
$this->hasher = $this->createMock(PasswordHasherInterface::class);
37-
$this->hasherFactory
33+
34+
$hasherFactory = $this->createMock(PasswordHasherFactoryInterface::class);
35+
$hasher = $this->createMock(PasswordHasherInterface::class);
36+
$hasherFactory
3837
->expects($this->any())
3938
->method('getPasswordHasher')
40-
->willReturn($this->hasher);
39+
->willReturn($hasher);
4140

4241
$this->authenticator = new HttpBasicAuthenticator('test', $this->userProvider);
4342
}

Tests/Authenticator/InMemoryAccessTokenHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class InMemoryAccessTokenHandler implements AccessTokenHandlerInterface
2020
/**
2121
* @var array<string, UserBadge>
2222
*/
23-
private $accessTokens = [];
23+
private array $accessTokens = [];
2424

2525
public function getUserBadgeFrom(string $accessToken): UserBadge
2626
{

Tests/Authenticator/JsonLoginAuthenticatorTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ class JsonLoginAuthenticatorTest extends TestCase
2929
{
3030
use ExpectDeprecationTrait;
3131

32-
private $userProvider;
33-
/** @var JsonLoginAuthenticator */
34-
private $authenticator;
32+
private InMemoryUserProvider $userProvider;
33+
private JsonLoginAuthenticator $authenticator;
3534

3635
protected function setUp(): void
3736
{

Tests/Authenticator/LoginLinkAuthenticatorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\Authenticator;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\Security\Core\User\UserInterface;
@@ -27,11 +28,10 @@
2728

2829
class LoginLinkAuthenticatorTest extends TestCase
2930
{
30-
private $loginLinkHandler;
31-
private $successHandler;
32-
private $failureHandler;
33-
/** @var LoginLinkAuthenticator */
34-
private $authenticator;
31+
private MockObject&LoginLinkHandlerInterface $loginLinkHandler;
32+
private MockObject&AuthenticationSuccessHandlerInterface $successHandler;
33+
private MockObject&AuthenticationFailureHandlerInterface $failureHandler;
34+
private LoginLinkAuthenticator $authenticator;
3535

3636
protected function setUp(): void
3737
{

Tests/Authenticator/RememberMeAuthenticatorTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\Authenticator;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\HttpFoundation\Cookie;
1617
use Symfony\Component\HttpFoundation\Request;
@@ -25,9 +26,9 @@
2526

2627
class RememberMeAuthenticatorTest extends TestCase
2728
{
28-
private $rememberMeHandler;
29-
private $tokenStorage;
30-
private $authenticator;
29+
private MockObject&RememberMeHandlerInterface $rememberMeHandler;
30+
private TokenStorage $tokenStorage;
31+
private RememberMeAuthenticator $authenticator;
3132

3233
protected function setUp(): void
3334
{

Tests/Authenticator/X509AuthenticatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
class X509AuthenticatorTest extends TestCase
2222
{
23-
private $userProvider;
24-
private $authenticator;
23+
private InMemoryUserProvider $userProvider;
24+
private X509Authenticator $authenticator;
2525

2626
protected function setUp(): void
2727
{

Tests/EventListener/CheckCredentialsListenerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\EventListener;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
1617
use Symfony\Component\PasswordHasher\PasswordHasherInterface;
@@ -28,9 +29,9 @@
2829

2930
class CheckCredentialsListenerTest extends TestCase
3031
{
31-
private $hasherFactory;
32-
private $listener;
33-
private $user;
32+
private MockObject&PasswordHasherFactoryInterface $hasherFactory;
33+
private CheckCredentialsListener $listener;
34+
private InMemoryUser $user;
3435

3536
protected function setUp(): void
3637
{

Tests/EventListener/CheckRememberMeConditionsListenerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
class CheckRememberMeConditionsListenerTest extends TestCase
2828
{
29-
private $listener;
30-
private $request;
31-
private $response;
29+
private CheckRememberMeConditionsListener $listener;
30+
private Request $request;
31+
private Response $response;
3232

3333
protected function setUp(): void
3434
{
@@ -59,6 +59,7 @@ public function testSuccessfulJsonLoginWithoutSupportingAuthenticator()
5959
public function testSuccessfulLoginWithoutRequestParameter()
6060
{
6161
$this->request = Request::create('/login');
62+
$this->response = new Response();
6263
$passport = $this->createPassport([new RememberMeBadge()]);
6364

6465
$this->listener->onSuccessfulLogin($this->createLoginSuccessfulEvent($passport));

Tests/EventListener/CsrfProtectionListenerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\EventListener;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
1617
use Symfony\Component\Security\Core\User\InMemoryUser;
@@ -25,8 +26,8 @@
2526

2627
class CsrfProtectionListenerTest extends TestCase
2728
{
28-
private $csrfTokenManager;
29-
private $listener;
29+
private MockObject&CsrfTokenManagerInterface $csrfTokenManager;
30+
private CsrfProtectionListener $listener;
3031

3132
protected function setUp(): void
3233
{

Tests/EventListener/LoginThrottlingListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
class LoginThrottlingListenerTest extends TestCase
3030
{
31-
private $requestStack;
32-
private $listener;
31+
private RequestStack $requestStack;
32+
private LoginThrottlingListener $listener;
3333

3434
protected function setUp(): void
3535
{

Tests/EventListener/PasswordMigratingListenerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\EventListener;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
@@ -31,9 +32,9 @@
3132

3233
class PasswordMigratingListenerTest extends TestCase
3334
{
34-
private $hasherFactory;
35-
private $listener;
36-
private $user;
35+
private MockObject&PasswordHasherFactoryInterface $hasherFactory;
36+
private PasswordMigratingListener $listener;
37+
private UserInterface&PasswordAuthenticatedUserInterface $user;
3738

3839
protected function setUp(): void
3940
{

Tests/EventListener/RememberMeListenerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\EventListener;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpFoundation\Response;
@@ -27,10 +28,10 @@
2728

2829
class RememberMeListenerTest extends TestCase
2930
{
30-
private $rememberMeHandler;
31-
private $listener;
32-
private $request;
33-
private $response;
31+
private MockObject&RememberMeHandlerInterface $rememberMeHandler;
32+
private RememberMeListener $listener;
33+
private Request $request;
34+
private Response $response;
3435

3536
protected function setUp(): void
3637
{

Tests/EventListener/SessionStrategyListenerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\EventListener;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpFoundation\Session\SessionInterface;
@@ -25,10 +26,10 @@
2526

2627
class SessionStrategyListenerTest extends TestCase
2728
{
28-
private $sessionAuthenticationStrategy;
29-
private $listener;
30-
private $request;
31-
private $token;
29+
private MockObject&SessionAuthenticationStrategyInterface $sessionAuthenticationStrategy;
30+
private SessionStrategyListener $listener;
31+
private Request $request;
32+
private NullToken $token;
3233

3334
protected function setUp(): void
3435
{

Tests/EventListener/UserCheckerListenerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\EventListener;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent;
1617
use Symfony\Component\Security\Core\User\InMemoryUser;
@@ -25,9 +26,9 @@
2526

2627
class UserCheckerListenerTest extends TestCase
2728
{
28-
private $userChecker;
29-
private $listener;
30-
private $user;
29+
private MockObject&UserCheckerInterface $userChecker;
30+
private UserCheckerListener $listener;
31+
private InMemoryUser $user;
3132

3233
protected function setUp(): void
3334
{

Tests/EventListener/UserProviderListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
class UserProviderListenerTest extends TestCase
2424
{
25-
private $userProvider;
26-
private $listener;
25+
private InMemoryUserProvider $userProvider;
26+
private UserProviderListener $listener;
2727

2828
protected function setUp(): void
2929
{

0 commit comments

Comments
 (0)