Skip to content

Commit 9f30c6c

Browse files
committed
Document refreshApplication method for multi-request tests
1 parent 6621156 commit 9f30c6c

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

http-tests.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,50 @@ class ExampleTest extends TestCase
9696

9797
In general, each of your tests should only make one request to your application. Unexpected behavior may occur if multiple requests are executed within a single test method.
9898

99+
> [!NOTE]
100+
> If you need to perform multiple requests to compare different endpoints within a single test, you should manually reboot the application between requests to ensure a clean state.
101+
102+
You may use the `refreshApplication` method to reset the service container and application state during a test:
103+
104+
```php tab=Pest
105+
<?php
106+
107+
test('parity between legacy and new endpoints', function () {
108+
$legacyResponse = $this->get('/api/legacy/resource');
109+
110+
$this->refreshApplication();
111+
112+
$newResponse = $this->get('/api/v1/resource');
113+
114+
expect($newResponse->json())->toBe($legacyResponse->json());
115+
});
116+
```
117+
118+
```php tab=PHPUnit
119+
<?php
120+
121+
namespace Tests\Feature;
122+
123+
use Tests\TestCase;
124+
125+
class ExampleTest extends TestCase
126+
{
127+
/**
128+
* A basic test example.
129+
*/
130+
public function test_parity_between_endpoints(): void
131+
{
132+
$legacyResponse = $this->get('/api/legacy/resource');
133+
134+
$this->refreshApplication();
135+
136+
$newResponse = $this->get('/api/v1/resource');
137+
138+
$this->assertEquals($legacyResponse->json(), $newResponse->json());
139+
}
140+
}
141+
```
142+
99143
> [!NOTE]
100144
> For convenience, the CSRF middleware is automatically disabled when running tests.
101145

0 commit comments

Comments
 (0)