You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/jwt.md
+40-49Lines changed: 40 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -298,69 +298,60 @@ services:
298
298
autoconfigure: false
299
299
```
300
300
301
-
## Testing with Behat
301
+
## Testing
302
302
303
-
Let's configure Behat to automatically send an `Authorization` HTTP header containing a valid JWT token when a scenario is marked with a `@login` annotation. Edit `features/bootstrap/FeatureContext.php` and add the following methods:
303
+
To test your authentication with `ApiTestCase`, you can write a method as below:
304
304
305
305
```php
306
306
<?php
307
-
// features/bootstrap/FeatureContext.php
307
+
// tests/AuthenticationTest.php
308
308
309
+
namespace App\Tests;
310
+
311
+
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
309
312
use App\Entity\User;
310
-
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
311
-
use Behatch\Context\RestContext;
313
+
use Hautelook\AliceBundle\PhpUnit\ReloadDatabaseTrait;
312
314
313
-
class FeatureContext implements Context, SnippetAcceptingContext
315
+
class AuthenticationTest extends ApiTestCase
314
316
{
315
-
// ...
316
-
// Must be after createDatabase() and dropDatabase() functions (the order matters)
Finally, mark your scenarios with the `@login` annotation to automatically add a valid `Authorization` header, and with `@logout` to be sure to destroy the token after this scenario.
357
+
Refer to [Testing the API](../distribution/testing.md) for more information about testing API Platform.
0 commit comments