Skip to content

Commit 6804fcc

Browse files
committed
Assert exact exception messages
1 parent 288443e commit 6804fcc

8 files changed

Lines changed: 11 additions & 11 deletions

‎tests/Authentication/Provider/SessionAuthenticationProviderTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function testAnErrorIsRaisedWhenNoUserProviderSupportsTheUser(): void
313313
->willReturn(false);
314314

315315
$this->expectException(\RuntimeException::class);
316-
$this->expectExceptionMessage(\sprintf('There is no user provider for user "%s".', InMemoryUser::class));
316+
$this->expectExceptionMessageIs(\sprintf('There is no user provider for user "%s". Shouldn\'t the "supportsClass()" method of your user provider return true for this classname?', InMemoryUser::class));
317317

318318
$this->authenticateWithSessionToken(
319319
new UsernamePasswordToken(new InMemoryUser('user', 'password', ['ROLE_USER']), 'main', ['ROLE_USER']),

‎tests/Authentication/Storage/DriverBackedTokenStorageTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testAnExceptionIsThrownIfTheTokenIsNotAddedToStorage(): void
6060
$storage = $this->createStorage(driver: $driver);
6161

6262
$this->expectException(StorageError::class);
63-
$this->expectExceptionMessage('Unable to add client "user" to storage');
63+
$this->expectExceptionMessageIs('Unable to add client "user" to storage');
6464

6565
/** @var MockObject&TokenInterface $token */
6666
$token = $this->createMock(TokenInterface::class);

‎tests/DependencyInjection/Compiler/ConfigureSessionAuthenticationProviderCompilerPassTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class ConfigureSessionAuthenticationProviderCompilerPassTest extends Abstr
1717
public function testTheFirewallsParameterIsRequiredWhenUsingAllFirewalls(): void
1818
{
1919
$this->expectException(RuntimeException::class);
20-
$this->expectExceptionMessage('The "firewalls" config for the session authentication provider is not set and the "security.firewalls" container parameter has not been set.');
20+
$this->expectExceptionMessageIs('The "firewalls" config for the session authentication provider is not set and the "security.firewalls" container parameter has not been set. Ensure the SecurityBundle is configured or set a list of firewalls to use.');
2121

2222
$this->registerSessionProvider(null);
2323

‎tests/DependencyInjection/Compiler/PingDBALConnectionsCompilerPassTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testTagsDbalConnectionsToBePinged(): void
3030
public function testThrowsAnExceptionIfAConnectionServiceIsNotConfigured(): void
3131
{
3232
$this->expectException(InvalidArgumentException::class);
33-
$this->expectExceptionMessage('The "database_connection" service does not exist in the container, please review the "server.periodic.dbal.connections" configuration for the BabDevWebSocketBundle to ensure all connections are set in your DoctrineBundle configuration.');
33+
$this->expectExceptionMessageIs('The "database_connection" service does not exist in the container, please review the "server.periodic.dbal.connections" configuration for the BabDevWebSocketBundle to ensure all connections are set in your DoctrineBundle configuration.');
3434

3535
$this->container->register('babdev_websocket_server.periodic_manager.ping_doctrine_dbal_connections', PingDoctrineDBALConnectionsPeriodicManager::class);
3636

‎tests/DependencyInjection/Compiler/ValidateSessionStorageOptionsCompilerPassTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class ValidateSessionStorageOptionsCompilerPassTest extends AbstractCompil
1313
public function testTheSessionOptionsAreRequiredWhenUsingASessionHandler(): void
1414
{
1515
$this->expectException(LogicException::class);
16-
$this->expectExceptionMessage('The "server.session.handler_service_id" option requires sessions to be enabled in the FrameworkBundle configuration ("framework.session")');
16+
$this->expectExceptionMessageIs('The "server.session.handler_service_id" option requires sessions to be enabled in the FrameworkBundle configuration ("framework.session"), as the websocket server reads sessions using the same options. To read sessions without the FrameworkBundle session configuration, use the "server.session.factory_service_id" or "server.session.storage_factory_service_id" option instead.');
1717

1818
$this->registerSessionStorageFactory();
1919

‎tests/PeriodicManager/ArrayPeriodicManagerRegistryTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testAddsAndRemovesAManager(): void
2929
public function testMultipleManagersWithTheSameNameAreNotAllowed(): void
3030
{
3131
$this->expectException(ManagerAlreadyRegistered::class);
32-
$this->expectExceptionMessage('A manager named "test" is already registered.');
32+
$this->expectExceptionMessageIs('A manager named "test" is already registered.');
3333

3434
$registry = new ArrayPeriodicManagerRegistry();
3535

‎tests/Routing/Loader/AttributeLoaderTest.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,31 @@ public function testNoRouteIsLoadedForAClassWithoutTheAttribute(): void
8181
public function testAnAbstractClassCannotBeLoaded(): void
8282
{
8383
$this->expectException(\InvalidArgumentException::class);
84-
$this->expectExceptionMessage(\sprintf('Attributes from class "%s" cannot be read as it is abstract.', AbstractMessageHandler::class));
84+
$this->expectExceptionMessageIs(\sprintf('Attributes from class "%s" cannot be read as it is abstract.', AbstractMessageHandler::class));
8585

8686
new AttributeLoader()->load(AbstractMessageHandler::class);
8787
}
8888

8989
public function testAClassWhichDoesNotExistCannotBeLoaded(): void
9090
{
9191
$this->expectException(\InvalidArgumentException::class);
92-
$this->expectExceptionMessage('Class "App\WebSocket\MissingMessageHandler" does not exist.');
92+
$this->expectExceptionMessageIs('Class "App\WebSocket\MissingMessageHandler" does not exist.');
9393

9494
new AttributeLoader()->load('App\WebSocket\MissingMessageHandler');
9595
}
9696

9797
public function testARequirementWithoutAPlaceholderNameIsRejected(): void
9898
{
9999
$this->expectException(\InvalidArgumentException::class);
100-
$this->expectExceptionMessage('A placeholder name must be a string (0 given).');
100+
$this->expectExceptionMessageIs(\sprintf('A placeholder name must be a string (0 given). Did you forget to specify the placeholder key for the requirement "\d+" of the route in "%s"?', InvalidRequirementMessageHandler::class));
101101

102102
new AttributeLoader()->load(InvalidRequirementMessageHandler::class);
103103
}
104104

105105
public function testAMessageHandlerWithoutAPathIsRejected(): void
106106
{
107107
$this->expectException(InvalidArgumentException::class);
108-
$this->expectExceptionMessage(\sprintf('The "%s" attribute on class "%s" must define a path.', AsMessageHandler::class, MissingPathMessageHandler::class));
108+
$this->expectExceptionMessageIs(\sprintf('The "%s" attribute on class "%s" must define a path.', AsMessageHandler::class, MissingPathMessageHandler::class));
109109

110110
new AttributeLoader()->load(MissingPathMessageHandler::class);
111111
}

‎tests/Server/Middleware/ResolveForwardedClientAddressFactoryTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testTheMiddlewareIsCreatedFromTheConfiguration(array $trustedPro
6565
public function testAnUnsupportedTrustedHeaderIsRejected(): void
6666
{
6767
$this->expectException(InvalidConfiguration::class);
68-
$this->expectExceptionMessage('The trusted header "x-real-ip" is not supported.');
68+
$this->expectExceptionMessageIs('The trusted header "x-real-ip" is not supported.');
6969

7070
ResolveForwardedClientAddressFactory::create(self::createStub(ServerMiddleware::class), ['10.0.0.1'], ['x-real-ip']);
7171
}

0 commit comments

Comments
 (0)