[Security] Fix return type declarations

This commit is contained in:
Alexander M. Turek 2019-08-23 12:37:41 +02:00 committed by Nicolas Grekas
parent c1b7118d7c
commit e0d79f71ed
12 changed files with 33 additions and 11 deletions

View File

@ -58,7 +58,7 @@ class ArgumentMetadata
*
* The type is the PHP class in 5.5+ and additionally the basic type in PHP 7.0+.
*
* @return string
* @return string|null
*/
public function getType()
{

View File

@ -18,6 +18,9 @@ use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
class DaoAuthenticationProviderTest extends TestCase
{
/**
* @group legacy
*/
public function testRetrieveUserWhenProviderDoesNotReturnAnUserInterface()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationServiceException');

View File

@ -62,6 +62,9 @@ class UserAuthenticationProviderTest extends TestCase
$provider->authenticate($this->getSupportedToken());
}
/**
* @group legacy
*/
public function testAuthenticateWhenProviderDoesNotReturnAnUserInterface()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationServiceException');

View File

@ -12,10 +12,10 @@
namespace Symfony\Component\Security\Guard\Tests\Provider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Guard\AuthenticatorInterface;
use Symfony\Component\Security\Guard\Provider\GuardAuthenticationProvider;
use Symfony\Component\Security\Guard\Token\GuardTokenInterface;
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
use Symfony\Component\Security\Guard\Token\PreAuthenticationGuardToken;
@ -68,7 +68,7 @@ class GuardAuthenticationProviderTest extends TestCase
->with($enteredCredentials, $mockedUser)
// authentication works!
->willReturn(true);
$authedToken = $this->getMockBuilder(TokenInterface::class)->getMock();
$authedToken = $this->getMockBuilder(GuardTokenInterface::class)->getMock();
$authenticatorB->expects($this->once())
->method('createAuthenticatedToken')
->with($mockedUser, $providerKey)
@ -130,7 +130,7 @@ class GuardAuthenticationProviderTest extends TestCase
->with($enteredCredentials, $mockedUser)
// authentication works!
->willReturn(true);
$authedToken = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$authedToken = $this->getMockBuilder(GuardTokenInterface::class)->getMock();
$authenticatorB->expects($this->once())
->method('createAuthenticatedToken')
->with($mockedUser, $providerKey)

View File

@ -31,7 +31,7 @@ interface AuthenticationSuccessHandlerInterface
* is called by authentication listeners inheriting from
* AbstractAuthenticationListener.
*
* @return Response never null
* @return Response
*/
public function onAuthenticationSuccess(Request $request, TokenInterface $token);
}

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Http\Tests\Authentication;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Core\Security;
@ -62,7 +63,7 @@ class DefaultAuthenticationFailureHandlerTest extends TestCase
public function testRedirect()
{
$response = new Response();
$response = new RedirectResponse('/login');
$this->httpUtils->expects($this->once())
->method('createRedirectResponse')->with($this->request, '/login')
->willReturn($response);

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Http\Tests\EntryPoint;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Http\EntryPoint\FormAuthenticationEntryPoint;
@ -21,7 +22,7 @@ class FormAuthenticationEntryPointTest extends TestCase
public function testStart()
{
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->disableOriginalConstructor()->disableOriginalClone()->getMock();
$response = new Response();
$response = new RedirectResponse('/the/login/path');
$httpKernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$httpUtils = $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')->getMock();

View File

@ -72,6 +72,9 @@ class ExceptionListenerTest extends TestCase
];
}
/**
* @group legacy
*/
public function testExceptionWhenEntryPointReturnsBadValue()
{
$event = $this->createEvent(new AuthenticationException());

View File

@ -122,6 +122,9 @@ class LogoutListenerTest extends TestCase
$listener->handle($event);
}
/**
* @group legacy
*/
public function testSuccessHandlerReturnsNonResponse()
{
$this->expectException('RuntimeException');

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Tests\Http\Firewall;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
@ -40,6 +41,10 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
->method('checkRequestPath')
->willReturn(true)
;
$httpUtils
->method('createRedirectResponse')
->willReturn(new RedirectResponse('/hello'))
;
$failureHandler = $this->getMockBuilder('Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface')->getMock();
$failureHandler
@ -52,7 +57,7 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
$authenticationManager
->expects($ok ? $this->once() : $this->never())
->method('authenticate')
->willReturn(new Response())
->willReturnArgument(0)
;
$listener = new UsernamePasswordFormAuthenticationListener(
@ -61,7 +66,7 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
$this->getMockBuilder('Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface')->getMock(),
$httpUtils,
'TheProviderKey',
$this->getMockBuilder('Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface')->getMock(),
new DefaultAuthenticationSuccessHandler($httpUtils),
$failureHandler,
['require_previous_session' => false]
);

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Security\Http\Tests\Logout;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Http\Logout\DefaultLogoutSuccessHandler;
class DefaultLogoutSuccessHandlerTest extends TestCase
@ -20,7 +20,7 @@ class DefaultLogoutSuccessHandlerTest extends TestCase
public function testLogout()
{
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
$response = new Response();
$response = new RedirectResponse('/dashboard');
$httpUtils = $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')->getMock();
$httpUtils->expects($this->once())

View File

@ -39,6 +39,9 @@ class AbstractRememberMeServicesTest extends TestCase
$this->assertNull($service->autoLogin(new Request()));
}
/**
* @group legacy
*/
public function testAutoLoginThrowsExceptionWhenImplementationDoesNotReturnUserInterface()
{
$this->expectException('RuntimeException');