fixed obsolete getMock() usage

This commit is contained in:
Fabien Potencier 2016-12-19 17:14:19 +01:00
parent 6126018b9f
commit 2819a57172
5 changed files with 21 additions and 21 deletions

View File

@ -33,14 +33,14 @@ class GlobalVariablesTest extends TestCase
public function testGetTokenNoToken()
{
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
$this->container->set('security.token_storage', $tokenStorage);
$this->assertNull($this->globals->getToken());
}
public function testGetToken()
{
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
$this->container->set('security.token_storage', $tokenStorage);

View File

@ -18,7 +18,7 @@ class Psr6CacheClearerTest extends \PHPUnit_Framework_TestCase
{
public function testClearPoolsInjectedInConstructor()
{
$pool = $this->getMock(CacheItemPoolInterface::class);
$pool = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
$pool
->expects($this->once())
->method('clear');
@ -28,7 +28,7 @@ class Psr6CacheClearerTest extends \PHPUnit_Framework_TestCase
public function testClearPool()
{
$pool = $this->getMock(CacheItemPoolInterface::class);
$pool = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
$pool
->expects($this->once())
->method('clear');
@ -51,12 +51,12 @@ class Psr6CacheClearerTest extends \PHPUnit_Framework_TestCase
*/
public function testClearPoolsInjectedByAdder()
{
$pool1 = $this->getMock(CacheItemPoolInterface::class);
$pool1 = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
$pool1
->expects($this->once())
->method('clear');
$pool2 = $this->getMock(CacheItemPoolInterface::class);
$pool2 = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
$pool2
->expects($this->once())
->method('clear');

View File

@ -165,7 +165,7 @@ class RouterListenerTest extends \PHPUnit_Framework_TestCase
{
$requestStack = new RequestStack();
$requestMatcher = $this->getMock('Symfony\Component\Routing\Matcher\RequestMatcherInterface');
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
$requestMatcher->expects($this->never())->method('matchRequest');
$dispatcher = new EventDispatcher();

View File

@ -233,7 +233,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
public function testSwitchUser()
{
$token = $this->getToken(array(new Role('the role')));
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$user->expects($this->any())->method('getRoles')->will($this->returnValue(array()));
$this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
@ -263,7 +263,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
public function testSwitchUserKeepsOtherQueryStringParameters()
{
$token = $this->getToken(array(new Role('the role')));
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$user->expects($this->any())->method('getRoles')->will($this->returnValue(array()));
$this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));

View File

@ -35,8 +35,8 @@ class UsernamePasswordJsonAuthenticationListenerTest extends \PHPUnit_Framework_
private function createListener(array $options = array(), $success = true)
{
$tokenStorage = $this->getMock(TokenStorageInterface::class);
$authenticationManager = $this->getMock(AuthenticationManagerInterface::class);
$tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock();
$authenticationManager = $this->getMockBuilder(AuthenticationManagerInterface::class)->getMock();
if ($success) {
$authenticationManager->method('authenticate')->willReturn(true);
@ -44,9 +44,9 @@ class UsernamePasswordJsonAuthenticationListenerTest extends \PHPUnit_Framework_
$authenticationManager->method('authenticate')->willThrowException(new AuthenticationException());
}
$authenticationSuccessHandler = $this->getMock(AuthenticationSuccessHandlerInterface::class);
$authenticationSuccessHandler = $this->getMockBuilder(AuthenticationSuccessHandlerInterface::class)->getMock();
$authenticationSuccessHandler->method('onAuthenticationSuccess')->willReturn(new Response('ok'));
$authenticationFailureHandler = $this->getMock(AuthenticationFailureHandlerInterface::class);
$authenticationFailureHandler = $this->getMockBuilder(AuthenticationFailureHandlerInterface::class)->getMock();
$authenticationFailureHandler->method('onAuthenticationFailure')->willReturn(new Response('ko'));
$this->listener = new UsernamePasswordJsonAuthenticationListener($tokenStorage, $authenticationManager, 'providerKey', $authenticationSuccessHandler, $authenticationFailureHandler, $options);
@ -56,7 +56,7 @@ class UsernamePasswordJsonAuthenticationListenerTest extends \PHPUnit_Framework_
{
$this->createListener();
$request = new Request(array(), array(), array(), array(), array(), array(), '{"username": "dunglas", "password": "foo"}');
$event = new GetResponseEvent($this->getMock(KernelInterface::class), $request, KernelInterface::MASTER_REQUEST);
$event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST);
$this->listener->handle($event);
$this->assertEquals('ok', $event->getResponse()->getContent());
@ -66,7 +66,7 @@ class UsernamePasswordJsonAuthenticationListenerTest extends \PHPUnit_Framework_
{
$this->createListener(array(), false);
$request = new Request(array(), array(), array(), array(), array(), array(), '{"username": "dunglas", "password": "foo"}');
$event = new GetResponseEvent($this->getMock(KernelInterface::class), $request, KernelInterface::MASTER_REQUEST);
$event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST);
$this->listener->handle($event);
$this->assertEquals('ko', $event->getResponse()->getContent());
@ -76,7 +76,7 @@ class UsernamePasswordJsonAuthenticationListenerTest extends \PHPUnit_Framework_
{
$this->createListener(array('username_path' => 'user.login', 'password_path' => 'user.pwd'));
$request = new Request(array(), array(), array(), array(), array(), array(), '{"user": {"login": "dunglas", "pwd": "foo"}}');
$event = new GetResponseEvent($this->getMock(KernelInterface::class), $request, KernelInterface::MASTER_REQUEST);
$event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST);
$this->listener->handle($event);
$this->assertEquals('ok', $event->getResponse()->getContent());
@ -89,7 +89,7 @@ class UsernamePasswordJsonAuthenticationListenerTest extends \PHPUnit_Framework_
{
$this->createListener();
$request = new Request(array(), array(), array(), array(), array(), array(), '{"usr": "dunglas", "password": "foo"}');
$event = new GetResponseEvent($this->getMock(KernelInterface::class), $request, KernelInterface::MASTER_REQUEST);
$event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST);
$this->listener->handle($event);
}
@ -101,7 +101,7 @@ class UsernamePasswordJsonAuthenticationListenerTest extends \PHPUnit_Framework_
{
$this->createListener();
$request = new Request(array(), array(), array(), array(), array(), array(), '{"username": "dunglas", "pass": "foo"}');
$event = new GetResponseEvent($this->getMock(KernelInterface::class), $request, KernelInterface::MASTER_REQUEST);
$event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST);
$this->listener->handle($event);
}
@ -113,7 +113,7 @@ class UsernamePasswordJsonAuthenticationListenerTest extends \PHPUnit_Framework_
{
$this->createListener();
$request = new Request(array(), array(), array(), array(), array(), array(), '{"username": 1, "password": "foo"}');
$event = new GetResponseEvent($this->getMock(KernelInterface::class), $request, KernelInterface::MASTER_REQUEST);
$event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST);
$this->listener->handle($event);
}
@ -125,7 +125,7 @@ class UsernamePasswordJsonAuthenticationListenerTest extends \PHPUnit_Framework_
{
$this->createListener();
$request = new Request(array(), array(), array(), array(), array(), array(), '{"username": "dunglas", "password": 1}');
$event = new GetResponseEvent($this->getMock(KernelInterface::class), $request, KernelInterface::MASTER_REQUEST);
$event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST);
$this->listener->handle($event);
}
@ -138,7 +138,7 @@ class UsernamePasswordJsonAuthenticationListenerTest extends \PHPUnit_Framework_
$this->createListener();
$username = str_repeat('x', Security::MAX_USERNAME_LENGTH + 1);
$request = new Request(array(), array(), array(), array(), array(), array(), sprintf('{"username": "%s", "password": 1}', $username));
$event = new GetResponseEvent($this->getMock(KernelInterface::class), $request, KernelInterface::MASTER_REQUEST);
$event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST);
$this->listener->handle($event);
}