Skip to content

Commit

Permalink
Use willReturn() instead of will(returnValue()).
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed May 30, 2019
1 parent d9fca82 commit 8e80d4e
Show file tree
Hide file tree
Showing 29 changed files with 229 additions and 229 deletions.
2 changes: 1 addition & 1 deletion Tests/AccessMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private function getRequestMatcher($request, $matches)
$requestMatcher = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestMatcherInterface')->getMock();
$requestMatcher->expects($this->once())
->method('matches')->with($request)
->will($this->returnValue($matches));
->willReturn($matches);

return $requestMatcher;
}
Expand Down
18 changes: 9 additions & 9 deletions Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp()

$this->session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock();
$this->request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
$this->request->expects($this->any())->method('getSession')->will($this->returnValue($this->session));
$this->request->expects($this->any())->method('getSession')->willReturn($this->session);
$this->exception = $this->getMockBuilder('Symfony\Component\Security\Core\Exception\AuthenticationException')->setMethods(['getMessage'])->getMock();
}

Expand All @@ -47,12 +47,12 @@ public function testForward()
->method('set')->with(Security::AUTHENTICATION_ERROR, $this->exception);
$this->httpUtils->expects($this->once())
->method('createRequest')->with($this->request, '/login')
->will($this->returnValue($subRequest));
->willReturn($subRequest);

$response = new Response();
$this->httpKernel->expects($this->once())
->method('handle')->with($subRequest, HttpKernelInterface::SUB_REQUEST)
->will($this->returnValue($response));
->willReturn($response);

$handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, $options, $this->logger);
$result = $handler->onAuthenticationFailure($this->request, $this->exception);
Expand All @@ -65,7 +65,7 @@ public function testRedirect()
$response = new Response();
$this->httpUtils->expects($this->once())
->method('createRedirectResponse')->with($this->request, '/login')
->will($this->returnValue($response));
->willReturn($response);

$handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, [], $this->logger);
$result = $handler->onAuthenticationFailure($this->request, $this->exception);
Expand All @@ -92,7 +92,7 @@ public function testExceptionIsPassedInRequestOnForward()

$this->httpUtils->expects($this->once())
->method('createRequest')->with($this->request, '/login')
->will($this->returnValue($subRequest));
->willReturn($subRequest);

$this->session->expects($this->never())->method('set');

Expand All @@ -117,7 +117,7 @@ public function testForwardIsLogged()

$this->httpUtils->expects($this->once())
->method('createRequest')->with($this->request, '/login')
->will($this->returnValue($this->getRequest()));
->willReturn($this->getRequest());

$this->logger
->expects($this->once())
Expand All @@ -143,7 +143,7 @@ public function testFailurePathCanBeOverwrittenWithRequest()
{
$this->request->expects($this->once())
->method('get')->with('_failure_path')
->will($this->returnValue('/auth/login'));
->willReturn('/auth/login');

$this->httpUtils->expects($this->once())
->method('createRedirectResponse')->with($this->request, '/auth/login');
Expand All @@ -156,7 +156,7 @@ public function testFailurePathCanBeOverwrittenWithNestedAttributeInRequest()
{
$this->request->expects($this->once())
->method('get')->with('_failure_path')
->will($this->returnValue(['value' => '/auth/login']));
->willReturn(['value' => '/auth/login']);

$this->httpUtils->expects($this->once())
->method('createRedirectResponse')->with($this->request, '/auth/login');
Expand All @@ -171,7 +171,7 @@ public function testFailurePathParameterCanBeOverwritten()

$this->request->expects($this->once())
->method('get')->with('_my_failure_path')
->will($this->returnValue('/auth/login'));
->willReturn('/auth/login');

$this->httpUtils->expects($this->once())
->method('createRedirectResponse')->with($this->request, '/auth/login');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DefaultAuthenticationSuccessHandlerTest extends TestCase
public function testRequestRedirections(Request $request, $options, $redirectedUrl)
{
$urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock();
$urlGenerator->expects($this->any())->method('generate')->will($this->returnValue('http://localhost/login'));
$urlGenerator->expects($this->any())->method('generate')->willReturn('http://localhost/login');
$httpUtils = new HttpUtils($urlGenerator);
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$handler = new DefaultAuthenticationSuccessHandler($httpUtils, $options);
Expand All @@ -37,7 +37,7 @@ public function testRequestRedirections(Request $request, $options, $redirectedU
public function getRequestRedirections()
{
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock();
$session->expects($this->once())->method('get')->with('_security.admin.target_path')->will($this->returnValue('/admin/dashboard'));
$session->expects($this->once())->method('get')->with('_security.admin.target_path')->willReturn('/admin/dashboard');
$session->expects($this->once())->method('remove')->with('_security.admin.target_path');
$requestWithSession = Request::create('/');
$requestWithSession->setSession($session);
Expand Down
20 changes: 10 additions & 10 deletions Tests/Authentication/SimpleAuthenticationHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testOnAuthenticationSuccessFallsBackToDefaultHandlerIfSimpleIsNo
$this->successHandler->expects($this->once())
->method('onAuthenticationSuccess')
->with($this->request, $this->token)
->will($this->returnValue($this->response));
->willReturn($this->response);

$handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
Expand All @@ -70,7 +70,7 @@ public function testOnAuthenticationSuccessCallsSimpleAuthenticator()
$authenticator->expects($this->once())
->method('onAuthenticationSuccess')
->with($this->request, $this->token)
->will($this->returnValue($this->response));
->willReturn($this->response);

$handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
Expand All @@ -91,7 +91,7 @@ public function testOnAuthenticationSuccessThrowsAnExceptionIfNonResponseIsRetur
$authenticator->expects($this->once())
->method('onAuthenticationSuccess')
->with($this->request, $this->token)
->will($this->returnValue(new \stdClass()));
->willReturn(new \stdClass());

$handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
$handler->onAuthenticationSuccess($this->request, $this->token);
Expand All @@ -102,13 +102,13 @@ public function testOnAuthenticationSuccessFallsBackToDefaultHandlerIfNullIsRetu
$this->successHandler->expects($this->once())
->method('onAuthenticationSuccess')
->with($this->request, $this->token)
->will($this->returnValue($this->response));
->willReturn($this->response);

$authenticator = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Tests\TestSuccessHandlerInterface');
$authenticator->expects($this->once())
->method('onAuthenticationSuccess')
->with($this->request, $this->token)
->will($this->returnValue(null));
->willReturn(null);

$handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
Expand All @@ -123,7 +123,7 @@ public function testOnAuthenticationFailureFallsBackToDefaultHandlerIfSimpleIsNo
$this->failureHandler->expects($this->once())
->method('onAuthenticationFailure')
->with($this->request, $this->authenticationException)
->will($this->returnValue($this->response));
->willReturn($this->response);

$handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
$result = $handler->onAuthenticationFailure($this->request, $this->authenticationException);
Expand All @@ -140,7 +140,7 @@ public function testOnAuthenticationFailureCallsSimpleAuthenticator()
$authenticator->expects($this->once())
->method('onAuthenticationFailure')
->with($this->request, $this->authenticationException)
->will($this->returnValue($this->response));
->willReturn($this->response);

$handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
$result = $handler->onAuthenticationFailure($this->request, $this->authenticationException);
Expand All @@ -161,7 +161,7 @@ public function testOnAuthenticationFailureThrowsAnExceptionIfNonResponseIsRetur
$authenticator->expects($this->once())
->method('onAuthenticationFailure')
->with($this->request, $this->authenticationException)
->will($this->returnValue(new \stdClass()));
->willReturn(new \stdClass());

$handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
$handler->onAuthenticationFailure($this->request, $this->authenticationException);
Expand All @@ -172,13 +172,13 @@ public function testOnAuthenticationFailureFallsBackToDefaultHandlerIfNullIsRetu
$this->failureHandler->expects($this->once())
->method('onAuthenticationFailure')
->with($this->request, $this->authenticationException)
->will($this->returnValue($this->response));
->willReturn($this->response);

$authenticator = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Tests\TestFailureHandlerInterface');
$authenticator->expects($this->once())
->method('onAuthenticationFailure')
->with($this->request, $this->authenticationException)
->will($this->returnValue(null));
->willReturn(null);

$handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
$result = $handler->onAuthenticationFailure($this->request, $this->authenticationException);
Expand Down
6 changes: 3 additions & 3 deletions Tests/EntryPoint/FormAuthenticationEntryPointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testStart()
->expects($this->once())
->method('createRedirectResponse')
->with($this->equalTo($request), $this->equalTo('/the/login/path'))
->will($this->returnValue($response))
->willReturn($response)
;

$entryPoint = new FormAuthenticationEntryPoint($httpKernel, $httpUtils, '/the/login/path', false);
Expand All @@ -48,15 +48,15 @@ public function testStartWithUseForward()
->expects($this->once())
->method('createRequest')
->with($this->equalTo($request), $this->equalTo('/the/login/path'))
->will($this->returnValue($subRequest))
->willReturn($subRequest)
;

$httpKernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$httpKernel
->expects($this->once())
->method('handle')
->with($this->equalTo($subRequest), $this->equalTo(HttpKernelInterface::SUB_REQUEST))
->will($this->returnValue($response))
->willReturn($response)
;

$entryPoint = new FormAuthenticationEntryPoint($httpKernel, $httpUtils, '/the/login/path', true);
Expand Down
32 changes: 16 additions & 16 deletions Tests/Firewall/AbstractPreAuthenticatedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testHandleWithValidValues()
$tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue(null))
->willReturn(null)
;
$tokenStorage
->expects($this->once())
Expand All @@ -44,7 +44,7 @@ public function testHandleWithValidValues()
->expects($this->once())
->method('authenticate')
->with($this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken'))
->will($this->returnValue($token))
->willReturn($token)
;

$listener = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Firewall\AbstractPreAuthenticatedListener', [
Expand All @@ -55,13 +55,13 @@ public function testHandleWithValidValues()
$listener
->expects($this->once())
->method('getPreAuthenticatedData')
->will($this->returnValue($userCredentials));
->willReturn($userCredentials);

$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock();
$event
->expects($this->any())
->method('getRequest')
->will($this->returnValue($request))
->willReturn($request)
;

$listener->handle($event);
Expand All @@ -77,7 +77,7 @@ public function testHandleWhenAuthenticationFails()
$tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue(null))
->willReturn(null)
;
$tokenStorage
->expects($this->never())
Expand All @@ -101,13 +101,13 @@ public function testHandleWhenAuthenticationFails()
$listener
->expects($this->once())
->method('getPreAuthenticatedData')
->will($this->returnValue($userCredentials));
->willReturn($userCredentials);

$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock();
$event
->expects($this->any())
->method('getRequest')
->will($this->returnValue($request))
->willReturn($request)
;

$listener->handle($event);
Expand All @@ -125,7 +125,7 @@ public function testHandleWhenAuthenticationFailsWithDifferentToken()
$tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($token))
->willReturn($token)
;
$tokenStorage
->expects($this->never())
Expand All @@ -149,13 +149,13 @@ public function testHandleWhenAuthenticationFailsWithDifferentToken()
$listener
->expects($this->once())
->method('getPreAuthenticatedData')
->will($this->returnValue($userCredentials));
->willReturn($userCredentials);

$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock();
$event
->expects($this->any())
->method('getRequest')
->will($this->returnValue($request))
->willReturn($request)
;

$listener->handle($event);
Expand All @@ -173,7 +173,7 @@ public function testHandleWithASimilarAuthenticatedToken()
$tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($token))
->willReturn($token)
;

$authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock();
Expand All @@ -190,13 +190,13 @@ public function testHandleWithASimilarAuthenticatedToken()
$listener
->expects($this->once())
->method('getPreAuthenticatedData')
->will($this->returnValue($userCredentials));
->willReturn($userCredentials);

$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock();
$event
->expects($this->any())
->method('getRequest')
->will($this->returnValue($request))
->willReturn($request)
;

$listener->handle($event);
Expand All @@ -214,7 +214,7 @@ public function testHandleWithAnInvalidSimilarToken()
$tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($token))
->willReturn($token)
;
$tokenStorage
->expects($this->once())
Expand All @@ -239,13 +239,13 @@ public function testHandleWithAnInvalidSimilarToken()
$listener
->expects($this->once())
->method('getPreAuthenticatedData')
->will($this->returnValue($userCredentials));
->willReturn($userCredentials);

$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock();
$event
->expects($this->any())
->method('getRequest')
->will($this->returnValue($request))
->willReturn($request)
;

$listener->handle($event);
Expand Down
Loading

0 comments on commit 8e80d4e

Please sign in to comment.