Skip to content

Commit b2cd6ea

Browse files
OskarStarknicolas-grekas
authored andcommitted
Use createMock() and use import instead of FQCN
1 parent fbe6552 commit b2cd6ea

10 files changed

+34
-32
lines changed

Tests/DataCollector/SecurityDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function testGetFirewallReturnsNull()
220220
public function testGetListeners()
221221
{
222222
$request = new Request();
223-
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
223+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
224224
$event->setResponse($response = new Response());
225225
$listener = function ($e) use ($event, &$listenerCalled) {
226226
$listenerCalled += $e === $event;

Tests/Debug/TraceableFirewallListenerTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ class TraceableFirewallListenerTest extends TestCase
2929
public function testOnKernelRequestRecordsListeners()
3030
{
3131
$request = new Request();
32-
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
32+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
3333
$event->setResponse($response = new Response());
3434
$listener = function ($e) use ($event, &$listenerCalled) {
3535
$listenerCalled += $e === $event;
3636
};
37-
$firewallMap = $this
38-
->getMockBuilder(FirewallMap::class)
39-
->disableOriginalConstructor()
40-
->getMock();
37+
$firewallMap = $this->createMock(FirewallMap::class);
4138
$firewallMap
4239
->expects($this->once())
4340
->method('getFirewallConfig')

Tests/DependencyInjection/CompleteConfigurationTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
1616
use Symfony\Bundle\SecurityBundle\SecurityBundle;
17+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1718
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
1920
use Symfony\Component\DependencyInjection\Reference;
@@ -610,7 +611,7 @@ public function testCustomAccessDecisionManagerService()
610611

611612
public function testAccessDecisionManagerServiceAndStrategyCannotBeUsedAtTheSameTime()
612613
{
613-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
614+
$this->expectException(InvalidConfigurationException::class);
614615
$this->expectExceptionMessage('Invalid configuration for path "security.access_decision_manager": "strategy" and "service" cannot be used together.');
615616
$this->getContainer('access_decision_manager_service_and_strategy');
616617
}
@@ -628,14 +629,14 @@ public function testAccessDecisionManagerOptionsAreNotOverriddenByImplicitStrate
628629

629630
public function testFirewallUndefinedUserProvider()
630631
{
631-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
632+
$this->expectException(InvalidConfigurationException::class);
632633
$this->expectExceptionMessage('Invalid firewall "main": user provider "undefined" not found.');
633634
$this->getContainer('firewall_undefined_provider');
634635
}
635636

636637
public function testFirewallListenerUndefinedProvider()
637638
{
638-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
639+
$this->expectException(InvalidConfigurationException::class);
639640
$this->expectExceptionMessage('Invalid firewall "main": user provider "undefined" not found.');
640641
$this->getContainer('listener_undefined_provider');
641642
}

Tests/DependencyInjection/MainConfigurationTest.php

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

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\SecurityBundle\DependencyInjection\MainConfiguration;
16+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1617
use Symfony\Component\Config\Definition\Processor;
1718

1819
class MainConfigurationTest extends TestCase
@@ -34,7 +35,7 @@ class MainConfigurationTest extends TestCase
3435

3536
public function testNoConfigForProvider()
3637
{
37-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
38+
$this->expectException(InvalidConfigurationException::class);
3839
$config = [
3940
'providers' => [
4041
'stub' => [],
@@ -48,7 +49,7 @@ public function testNoConfigForProvider()
4849

4950
public function testManyConfigForProvider()
5051
{
51-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
52+
$this->expectException(InvalidConfigurationException::class);
5253
$config = [
5354
'providers' => [
5455
'stub' => [

Tests/DependencyInjection/Security/Factory/AbstractFactoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Security\Factory;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Reference;
1718

@@ -127,7 +128,7 @@ public function getSuccessHandlers()
127128

128129
protected function callFactory($id, $config, $userProviderId, $defaultEntryPointId)
129130
{
130-
$factory = $this->getMockForAbstractClass(\Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory::class, []);
131+
$factory = $this->getMockForAbstractClass(AbstractFactory::class);
131132

132133
$factory
133134
->expects($this->once())

Tests/DependencyInjection/Security/Factory/GuardAuthenticationFactoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\GuardAuthenticationFactory;
1616
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
17+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1718
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
1920
use Symfony\Component\DependencyInjection\Reference;
@@ -41,7 +42,7 @@ public function testAddValidConfiguration(array $inputConfig, array $expectedCon
4142
*/
4243
public function testAddInvalidConfiguration(array $inputConfig)
4344
{
44-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
45+
$this->expectException(InvalidConfigurationException::class);
4546
$factory = new GuardAuthenticationFactory();
4647
$nodeDefinition = new ArrayNodeDefinition('guard');
4748
$factory->addConfiguration($nodeDefinition);

Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
1717
use Symfony\Bundle\SecurityBundle\SecurityBundle;
1818
use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider\DummyProvider;
19+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1920
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
2021
use Symfony\Component\DependencyInjection\ContainerBuilder;
2122
use Symfony\Component\DependencyInjection\Reference;
@@ -26,7 +27,7 @@ class SecurityExtensionTest extends TestCase
2627
{
2728
public function testInvalidCheckPath()
2829
{
29-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
30+
$this->expectException(InvalidConfigurationException::class);
3031
$this->expectExceptionMessage('The check_path "/some_area/login_check" for login method "form_login" is not matched by the firewall pattern "/secured_area/.*".');
3132
$container = $this->getRawContainer();
3233

@@ -50,7 +51,7 @@ public function testInvalidCheckPath()
5051

5152
public function testFirewallWithoutAuthenticationListener()
5253
{
53-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
54+
$this->expectException(InvalidConfigurationException::class);
5455
$this->expectExceptionMessage('No authentication listener registered for firewall "some_firewall"');
5556
$container = $this->getRawContainer();
5657

@@ -71,7 +72,7 @@ public function testFirewallWithoutAuthenticationListener()
7172

7273
public function testFirewallWithInvalidUserProvider()
7374
{
74-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
75+
$this->expectException(InvalidConfigurationException::class);
7576
$this->expectExceptionMessage('Unable to create definition for "security.user.provider.concrete.my_foo" user provider');
7677
$container = $this->getRawContainer();
7778

@@ -190,7 +191,7 @@ public function testPerListenerProvider()
190191

191192
public function testMissingProviderForListener()
192193
{
193-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
194+
$this->expectException(InvalidConfigurationException::class);
194195
$this->expectExceptionMessage('Not configuring explicitly the provider for the "http_basic" listener on "ambiguous" firewall is ambiguous as there is more than one registered provider.');
195196
$container = $this->getRawContainer();
196197
$container->loadFromExtension('security', [

Tests/Functional/UserPasswordEncoderCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function testThrowsExceptionOnNoConfiguredEncoders()
301301
$this->expectException(\RuntimeException::class);
302302
$this->expectExceptionMessage('There are no configured encoders for the "security" extension.');
303303
$application = new ConsoleApplication();
304-
$application->add(new UserPasswordEncoderCommand($this->getMockBuilder(EncoderFactoryInterface::class)->getMock(), []));
304+
$application->add(new UserPasswordEncoderCommand($this->createMock(EncoderFactoryInterface::class), []));
305305

306306
$passwordEncoderCommand = $application->find('security:encode-password');
307307

Tests/Security/FirewallMapTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testGetListenersWithEmptyMap()
3030
$request = new Request();
3131

3232
$map = [];
33-
$container = $this->getMockBuilder(Container::class)->getMock();
33+
$container = $this->createMock(Container::class);
3434
$container->expects($this->never())->method('get');
3535

3636
$firewallMap = new FirewallMap($container, $map);
@@ -46,7 +46,7 @@ public function testGetListenersWithInvalidParameter()
4646
$request->attributes->set(self::ATTRIBUTE_FIREWALL_CONTEXT, 'foo');
4747

4848
$map = [];
49-
$container = $this->getMockBuilder(Container::class)->getMock();
49+
$container = $this->createMock(Container::class);
5050
$container->expects($this->never())->method('get');
5151

5252
$firewallMap = new FirewallMap($container, $map);
@@ -60,27 +60,27 @@ public function testGetListeners()
6060
{
6161
$request = new Request();
6262

63-
$firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock();
63+
$firewallContext = $this->createMock(FirewallContext::class);
6464

6565
$firewallConfig = new FirewallConfig('main', 'user_checker');
6666
$firewallContext->expects($this->once())->method('getConfig')->willReturn($firewallConfig);
6767

6868
$listener = function () {};
6969
$firewallContext->expects($this->once())->method('getListeners')->willReturn([$listener]);
7070

71-
$exceptionListener = $this->getMockBuilder(ExceptionListener::class)->disableOriginalConstructor()->getMock();
71+
$exceptionListener = $this->createMock(ExceptionListener::class);
7272
$firewallContext->expects($this->once())->method('getExceptionListener')->willReturn($exceptionListener);
7373

74-
$logoutListener = $this->getMockBuilder(LogoutListener::class)->disableOriginalConstructor()->getMock();
74+
$logoutListener = $this->createMock(LogoutListener::class);
7575
$firewallContext->expects($this->once())->method('getLogoutListener')->willReturn($logoutListener);
7676

77-
$matcher = $this->getMockBuilder(RequestMatcherInterface::class)->getMock();
77+
$matcher = $this->createMock(RequestMatcherInterface::class);
7878
$matcher->expects($this->once())
7979
->method('matches')
8080
->with($request)
8181
->willReturn(true);
8282

83-
$container = $this->getMockBuilder(Container::class)->getMock();
83+
$container = $this->createMock(Container::class);
8484
$container->expects($this->exactly(2))->method('get')->willReturn($firewallContext);
8585

8686
$firewallMap = new FirewallMap($container, ['security.firewall.map.context.foo' => $matcher]);

Tests/SecurityUserValueResolverTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public function testResolveNoToken()
3737

3838
public function testResolveNoUser()
3939
{
40-
$mock = $this->getMockBuilder(UserInterface::class)->getMock();
41-
$token = $this->getMockBuilder(TokenInterface::class)->getMock();
40+
$mock = $this->createMock(UserInterface::class);
41+
$token = $this->createMock(TokenInterface::class);
4242
$tokenStorage = new TokenStorage();
4343
$tokenStorage->setToken($token);
4444

@@ -59,8 +59,8 @@ public function testResolveWrongType()
5959

6060
public function testResolve()
6161
{
62-
$user = $this->getMockBuilder(UserInterface::class)->getMock();
63-
$token = $this->getMockBuilder(TokenInterface::class)->getMock();
62+
$user = $this->createMock(UserInterface::class);
63+
$token = $this->createMock(TokenInterface::class);
6464
$token->expects($this->any())->method('getUser')->willReturn($user);
6565
$tokenStorage = new TokenStorage();
6666
$tokenStorage->setToken($token);
@@ -74,8 +74,8 @@ public function testResolve()
7474

7575
public function testIntegration()
7676
{
77-
$user = $this->getMockBuilder(UserInterface::class)->getMock();
78-
$token = $this->getMockBuilder(TokenInterface::class)->getMock();
77+
$user = $this->createMock(UserInterface::class);
78+
$token = $this->createMock(TokenInterface::class);
7979
$token->expects($this->any())->method('getUser')->willReturn($user);
8080
$tokenStorage = new TokenStorage();
8181
$tokenStorage->setToken($token);
@@ -86,7 +86,7 @@ public function testIntegration()
8686

8787
public function testIntegrationNoUser()
8888
{
89-
$token = $this->getMockBuilder(TokenInterface::class)->getMock();
89+
$token = $this->createMock(TokenInterface::class);
9090
$tokenStorage = new TokenStorage();
9191
$tokenStorage->setToken($token);
9292

0 commit comments

Comments
 (0)