|
1 | | -## Testing |
| 1 | +## Pest |
| 2 | + |
| 3 | +### Testing |
2 | 4 | - If you need to verify a feature is working, write or update a Unit / Feature test. |
3 | 5 |
|
4 | | -# Pest Tests |
| 6 | +### Pest Tests |
5 | 7 | - All tests must be written using Pest. |
6 | | -- You must not remove any tests or test files from the tests directory without approval. These are not temporary or helper files, these are core to the application. |
7 | | -- Tests should test all of the unhappy paths, happy paths, and weird paths. |
| 8 | +- You must not remove any tests or test files from the tests directory without approval. These are not temporary or helper files - these are core to the application. |
| 9 | +- Tests should test all of the happy paths, failure paths, and weird paths. |
8 | 10 | - Tests live in the `tests/Feature` and `tests/Unit` directories. |
9 | 11 | - Pest tests look and behave like this: |
10 | | -<code-snippet name="Basic example Pest test" lang="php"> |
| 12 | +<code-snippet name="Basic Pest Test Example" lang="php"> |
11 | 13 | it('is true', function () { |
12 | 14 | expect(true)->toBeTrue(); |
13 | 15 | }); |
14 | 16 | </code-snippet> |
15 | 17 |
|
16 | | -# Running Tests |
17 | | -- Run the minimal number of tests, using an appropriate filter, before finalizing code edits. |
18 | | -- Run all tests: `php artisan test`. |
19 | | -- Run all tests in a file: `php artisan test tests/Feature/ExampleTest.php`. |
20 | | -- Filter on particular test name: `php artisan test --filter=testName` (recommended after making a change to a related file). |
21 | | -- When the tests relating to your changes are passing, ask the user if they'd like to run the entire test suite to ensure everything is still passing. |
| 18 | +### Running Tests |
| 19 | +- Run the minimal number of tests using an appropriate filter before finalizing code edits. |
| 20 | +- To run all tests: `php artisan test`. |
| 21 | +- To run all tests in a file: `php artisan test tests/Feature/ExampleTest.php`. |
| 22 | +- To filter on a particular test name: `php artisan test --filter=testName` (recommended after making a change to a related file). |
| 23 | +- When the tests relating to your changes are passing, ask the user if they would like to run the entire test suite to ensure everything is still passing. |
22 | 24 |
|
23 | | -## Pest Assertions |
24 | | -- When asserting status codes on a response, use the specific method like `assertForbidden`, `assertNotFound` etc, instead of using `assertStatus(403)` or similar, e.g.: |
25 | | -<code-snippet name="Pest asserting postJson response" lang="php"> |
| 25 | +### Pest Assertions |
| 26 | +- When asserting status codes on a response, use the specific method like `assertForbidden` and `assertNotFound` instead of using `assertStatus(403)` or similar, e.g.: |
| 27 | +<code-snippet name="Pest Example Asserting postJson Response" lang="php"> |
26 | 28 | it('returns all', function () { |
27 | 29 | $response = $this->postJson('/api/docs', []); |
28 | 30 |
|
29 | 31 | $response->assertSuccessful(); |
30 | 32 | }); |
31 | 33 | </code-snippet> |
32 | 34 |
|
33 | | -## Mocking |
34 | | -- Mocking can be very helpful. |
35 | | -- When mocking, you can use the pest function `Pest\Laravel\mock`, and always import it before usage with `use function Pest\Laravel\mock;`. Alternatively you can use `$this->mock()` if existing tests do. |
| 35 | +### Mocking |
| 36 | +- Mocking can be very helpful when appropriate. |
| 37 | +- When mocking, you can use the `Pest\Laravel\mock` Pest function, but always import it via `use function Pest\Laravel\mock;` before using it. Alternatively, you can use `$this->mock()` if existing tests do. |
36 | 38 | - You can also create partial mocks using the same import or self method. |
37 | 39 |
|
38 | | -## Datasets |
39 | | -- Use datasets in Pest to simplify tests which have a lot of duplicated data. This often the case when testing validation rules, so often go with the solution of using datasets when writing tests for validation rules. |
| 40 | +### Datasets |
| 41 | +- Use datasets in Pest to simplify tests which have a lot of duplicated data. This often the case when testing validation rules, so consider going with this solutionwhen writing tests for validation rules. |
40 | 42 |
|
41 | | -<code-snippet name="Pest dataset example" lang="php"> |
| 43 | +<code-snippet name="Pest Dataset Example" lang="php"> |
42 | 44 | it('has emails', function (string $email) { |
43 | 45 | expect($email)->not->toBeEmpty(); |
44 | 46 | })->with([ |
|
0 commit comments