Skip to content

Commit 95c7535

Browse files
Fix JWT authentication test file with static container (#1565)
* Fix JWT authentication test file with static container * Remove the last residue of previous code to get static container
1 parent ba15d2c commit 95c7535

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

core/jwt.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ security:
120120
# https://symfony.com/doc/current/security.html#c-hashing-passwords
121121
password_hashers:
122122
App\Entity\User: 'auto'
123-
123+
124124
# https://symfony.com/doc/current/security/authenticator_manager.html
125125
enable_authenticator_manager: true
126126
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
@@ -280,11 +280,11 @@ And register this service in `config/services.yaml`:
280280
```yaml
281281
# api/config/services.yaml
282282
services:
283-
# ...
283+
# ...
284284
285285
App\OpenApi\JwtDecorator:
286286
decorates: 'api_platform.openapi.factory'
287-
arguments: ['@.inner']
287+
arguments: ['@.inner']
288288
```
289289

290290
## Testing
@@ -308,14 +308,15 @@ class AuthenticationTest extends ApiTestCase
308308
public function testLogin(): void
309309
{
310310
$client = self::createClient();
311+
$container = self::getContainer();
311312
312313
$user = new User();
313314
$user->setEmail('[email protected]');
314315
$user->setPassword(
315-
self::$container->get('security.user_password_hasher')->hashPassword($user, '$3CR3T')
316+
$container->get('security.user_password_hasher')->hashPassword($user, '$3CR3T')
316317
);
317318
318-
$manager = self::$container->get('doctrine')->getManager();
319+
$manager = $container->get('doctrine')->getManager();
319320
$manager->persist($user);
320321
$manager->flush();
321322
@@ -351,7 +352,7 @@ Since now we have a `JWT` authentication, functional tests require us to log in
351352

352353
Hashers are used for 2 reasons:
353354

354-
1. To generate a hash for a raw password (`self::$container->get('security.user_password_hasher')->hashPassword($user, '$3CR3T')`)
355+
1. To generate a hash for a raw password (`$container->get('security.user_password_hasher')->hashPassword($user, '$3CR3T')`)
355356
2. To verify a password during authentication
356357

357358
While hashing and verifying 1 password is quite a fast operation, doing it hundreds or even thousands of times in a tests suite becomes a bottleneck, because reliable hashing algorithms are slow by their nature.

0 commit comments

Comments
 (0)