Skip to content

Commit 51854aa

Browse files
Merge branch '5.1' into 5.2
* 5.1: Use createMock() and use import instead of FQCN
2 parents 3a2622d + 911f6b5 commit 51854aa

9 files changed

+26
-25
lines changed

Tests/DataCollector/SecurityDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function testGetFirewallReturnsNull()
188188
public function testGetListeners()
189189
{
190190
$request = new Request();
191-
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
191+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
192192
$event->setResponse($response = new Response());
193193
$listener = function ($e) use ($event, &$listenerCalled) {
194194
$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;
@@ -597,7 +598,7 @@ public function testCustomAccessDecisionManagerService()
597598

598599
public function testAccessDecisionManagerServiceAndStrategyCannotBeUsedAtTheSameTime()
599600
{
600-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
601+
$this->expectException(InvalidConfigurationException::class);
601602
$this->expectExceptionMessage('Invalid configuration for path "security.access_decision_manager": "strategy" and "service" cannot be used together.');
602603
$this->getContainer('access_decision_manager_service_and_strategy');
603604
}
@@ -615,14 +616,14 @@ public function testAccessDecisionManagerOptionsAreNotOverriddenByImplicitStrate
615616

616617
public function testFirewallUndefinedUserProvider()
617618
{
618-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
619+
$this->expectException(InvalidConfigurationException::class);
619620
$this->expectExceptionMessage('Invalid firewall "main": user provider "undefined" not found.');
620621
$this->getContainer('firewall_undefined_provider');
621622
}
622623

623624
public function testFirewallListenerUndefinedProvider()
624625
{
625-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
626+
$this->expectException(InvalidConfigurationException::class);
626627
$this->expectExceptionMessage('Invalid firewall "main": user provider "undefined" not found.');
627628
$this->getContainer('listener_undefined_provider');
628629
}

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;
@@ -42,7 +43,7 @@ public function testAddValidConfiguration(array $inputConfig, array $expectedCon
4243
*/
4344
public function testAddInvalidConfiguration(array $inputConfig)
4445
{
45-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
46+
$this->expectException(InvalidConfigurationException::class);
4647
$factory = new GuardAuthenticationFactory();
4748
$nodeDefinition = new ArrayNodeDefinition('guard');
4849
$factory->addConfiguration($nodeDefinition);

Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class SecurityExtensionTest extends TestCase
4444
{
4545
public function testInvalidCheckPath()
4646
{
47-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
47+
$this->expectException(InvalidConfigurationException::class);
4848
$this->expectExceptionMessage('The check_path "/some_area/login_check" for login method "form_login" is not matched by the firewall pattern "/secured_area/.*".');
4949
$container = $this->getRawContainer();
5050

@@ -68,7 +68,7 @@ public function testInvalidCheckPath()
6868

6969
public function testFirewallWithoutAuthenticationListener()
7070
{
71-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
71+
$this->expectException(InvalidConfigurationException::class);
7272
$this->expectExceptionMessage('No authentication listener registered for firewall "some_firewall"');
7373
$container = $this->getRawContainer();
7474

@@ -89,7 +89,7 @@ public function testFirewallWithoutAuthenticationListener()
8989

9090
public function testFirewallWithInvalidUserProvider()
9191
{
92-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
92+
$this->expectException(InvalidConfigurationException::class);
9393
$this->expectExceptionMessage('Unable to create definition for "security.user.provider.concrete.my_foo" user provider');
9494
$container = $this->getRawContainer();
9595

@@ -208,7 +208,7 @@ public function testPerListenerProvider()
208208

209209
public function testMissingProviderForListener()
210210
{
211-
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
211+
$this->expectException(InvalidConfigurationException::class);
212212
$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.');
213213
$container = $this->getRawContainer();
214214
$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]);

0 commit comments

Comments
 (0)