|
12 | 12 | - [Testing File Uploads](#testing-file-uploads) |
13 | 13 | - [Testing Views](#testing-views) |
14 | 14 | - [Rendering Blade and Components](#rendering-blade-and-components) |
| 15 | +- [Caching Routes](#caching-routes) |
15 | 16 | - [Available Assertions](#available-assertions) |
16 | 17 | - [Response Assertions](#response-assertions) |
17 | 18 | - [Authentication Assertions](#authentication-assertions) |
@@ -938,6 +939,51 @@ $view = $this->component(Profile::class, ['name' => 'Taylor']); |
938 | 939 | $view->assertSee('Taylor'); |
939 | 940 | ``` |
940 | 941 |
|
| 942 | +<a name="caching-routes"></a> |
| 943 | +## Caching Routes |
| 944 | + |
| 945 | +Before a test runs, Laravel boots a fresh instance of the application, including collecting all defined routes. If your applications have many route files, you may wish to add the `Illuminate\Foundation\Testing\WithCachedRoutes` trait to your test cases. On tests which use this trait, routes are built once and stored in memory, meaning the route collection process is only run once for all tests in your suite: |
| 946 | + |
| 947 | +```php tab=Pest |
| 948 | +<?php |
| 949 | + |
| 950 | +use App\Http\Controllers\UserController; |
| 951 | +use Illuminate\Foundation\Testing\WithCachedRoutes; |
| 952 | + |
| 953 | +pest()->use(WithCachedRoutes::class); |
| 954 | + |
| 955 | +test('basic example', function () { |
| 956 | + $this->get(action([UserController::class, 'index'])); |
| 957 | + |
| 958 | + // ... |
| 959 | +}); |
| 960 | +``` |
| 961 | + |
| 962 | +```php tab=PHPUnit |
| 963 | +<?php |
| 964 | + |
| 965 | +namespace Tests\Feature; |
| 966 | + |
| 967 | +use App\Http\Controllers\UserController; |
| 968 | +use Illuminate\Foundation\Testing\WithCachedRoutes; |
| 969 | +use Tests\TestCase; |
| 970 | + |
| 971 | +class BasicTest extends TestCase |
| 972 | +{ |
| 973 | + use WithCachedRoutes; |
| 974 | + |
| 975 | + /** |
| 976 | + * A basic functional test example. |
| 977 | + */ |
| 978 | + public function test_basic_example(): void |
| 979 | + { |
| 980 | + $response = $this->get(action([UserController::class, 'index'])); |
| 981 | + |
| 982 | + // ... |
| 983 | + } |
| 984 | +} |
| 985 | +``` |
| 986 | + |
941 | 987 | <a name="available-assertions"></a> |
942 | 988 | ## Available Assertions |
943 | 989 |
|
|
0 commit comments