Skip to content

Commit 4fd31b7

Browse files
minor #52157 [Tests] Move expectException closer to the place of the expectation to avoid false positives (OskarStark)
This PR was merged into the 6.4 branch. Discussion ---------- [Tests] Move `expectException` closer to the place of the expectation to avoid false positives | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | -- | License | MIT If you guys like this PR, I will fix the other places as well Should be merged after merge & upmerge of: * #52365 Commits ------- 6115ab0751 [Tests] Move expectException closer to the place of the expectation to avoid false positives
2 parents 05a979c + 3e8a7a6 commit 4fd31b7

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

Tests/DependencyInjection/Compiler/AddSecurityVotersPassTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ class AddSecurityVotersPassTest extends TestCase
2424
{
2525
public function testNoVoters()
2626
{
27-
$this->expectException(LogicException::class);
28-
$this->expectExceptionMessage('No security voters found. You need to tag at least one with "security.voter".');
2927
$container = new ContainerBuilder();
3028
$container
3129
->register('security.access.decision_manager', AccessDecisionManager::class)
3230
->addArgument([])
3331
;
3432

3533
$compilerPass = new AddSecurityVotersPass();
34+
35+
$this->expectException(LogicException::class);
36+
$this->expectExceptionMessage('No security voters found. You need to tag at least one with "security.voter".');
37+
3638
$compilerPass->process($container);
3739
}
3840

Tests/DependencyInjection/MainConfigurationTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class MainConfigurationTest extends TestCase
3636

3737
public function testNoConfigForProvider()
3838
{
39-
$this->expectException(InvalidConfigurationException::class);
4039
$config = [
4140
'providers' => [
4241
'stub' => [],
@@ -45,12 +44,14 @@ public function testNoConfigForProvider()
4544

4645
$processor = new Processor();
4746
$configuration = new MainConfiguration([], []);
47+
48+
$this->expectException(InvalidConfigurationException::class);
49+
4850
$processor->processConfiguration($configuration, [$config]);
4951
}
5052

5153
public function testManyConfigForProvider()
5254
{
53-
$this->expectException(InvalidConfigurationException::class);
5455
$config = [
5556
'providers' => [
5657
'stub' => [
@@ -62,6 +63,9 @@ public function testManyConfigForProvider()
6263

6364
$processor = new Processor();
6465
$configuration = new MainConfiguration([], []);
66+
67+
$this->expectException(InvalidConfigurationException::class);
68+
6569
$processor->processConfiguration($configuration, [$config]);
6670
}
6771

Tests/DependencyInjection/Security/Factory/AccessTokenFactoryTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ public static function getOidcUserInfoConfiguration(): iterable
145145

146146
public function testMultipleTokenHandlersSet()
147147
{
148-
$this->expectException(InvalidConfigurationException::class);
149-
$this->expectExceptionMessage('You cannot configure multiple token handlers.');
150-
151148
$config = [
152149
'token_handler' => [
153150
'id' => 'in_memory_token_handler_service_id',
@@ -156,6 +153,10 @@ public function testMultipleTokenHandlersSet()
156153
];
157154

158155
$factory = new AccessTokenFactory($this->createTokenHandlerFactories());
156+
157+
$this->expectException(InvalidConfigurationException::class);
158+
$this->expectExceptionMessage('You cannot configure multiple token handlers.');
159+
159160
$this->processConfig($config, $factory);
160161
}
161162

Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ class SecurityExtensionTest extends TestCase
4545

4646
public function testInvalidCheckPath()
4747
{
48-
$this->expectException(InvalidConfigurationException::class);
49-
$this->expectExceptionMessage('The check_path "/some_area/login_check" for login method "form_login" is not matched by the firewall pattern "/secured_area/.*".');
5048
$container = $this->getRawContainer();
5149

5250
$container->loadFromExtension('security', [
@@ -64,13 +62,14 @@ public function testInvalidCheckPath()
6462
],
6563
]);
6664

65+
$this->expectException(InvalidConfigurationException::class);
66+
$this->expectExceptionMessage('The check_path "/some_area/login_check" for login method "form_login" is not matched by the firewall pattern "/secured_area/.*".');
67+
6768
$container->compile();
6869
}
6970

7071
public function testFirewallWithInvalidUserProvider()
7172
{
72-
$this->expectException(InvalidConfigurationException::class);
73-
$this->expectExceptionMessage('Unable to create definition for "security.user.provider.concrete.my_foo" user provider');
7473
$container = $this->getRawContainer();
7574

7675
$extension = $container->getExtension('security');
@@ -89,6 +88,9 @@ public function testFirewallWithInvalidUserProvider()
8988
],
9089
]);
9190

91+
$this->expectException(InvalidConfigurationException::class);
92+
$this->expectExceptionMessage('Unable to create definition for "security.user.provider.concrete.my_foo" user provider');
93+
9294
$container->compile();
9395
}
9496

@@ -161,8 +163,6 @@ public function testPerListenerProvider()
161163

162164
public function testMissingProviderForListener()
163165
{
164-
$this->expectException(InvalidConfigurationException::class);
165-
$this->expectExceptionMessage('Not configuring explicitly the provider for the "http_basic" authenticator on "ambiguous" firewall is ambiguous as there is more than one registered provider.');
166166
$container = $this->getRawContainer();
167167
$container->loadFromExtension('security', [
168168
'providers' => [
@@ -178,6 +178,9 @@ public function testMissingProviderForListener()
178178
],
179179
]);
180180

181+
$this->expectException(InvalidConfigurationException::class);
182+
$this->expectExceptionMessage('Not configuring explicitly the provider for the "http_basic" authenticator on "ambiguous" firewall is ambiguous as there is more than one registered provider.');
183+
181184
$container->compile();
182185
}
183186

@@ -692,9 +695,6 @@ public static function provideEntryPointFirewalls(): iterable
692695
*/
693696
public function testEntryPointRequired(array $firewall, string $messageRegex)
694697
{
695-
$this->expectException(InvalidConfigurationException::class);
696-
$this->expectExceptionMessageMatches($messageRegex);
697-
698698
$container = $this->getRawContainer();
699699
$container->loadFromExtension('security', [
700700
'providers' => [
@@ -706,6 +706,9 @@ public function testEntryPointRequired(array $firewall, string $messageRegex)
706706
],
707707
]);
708708

709+
$this->expectException(InvalidConfigurationException::class);
710+
$this->expectExceptionMessageMatches($messageRegex);
711+
709712
$container->compile();
710713
}
711714

0 commit comments

Comments
 (0)