|
1 | 1 | ## Testing |
2 | | -If you need to verify a feature is working, write or update a Unit / Feature test. |
| 2 | +- If you need to verify a feature is working, write or update a Unit / Feature test. |
3 | 3 |
|
4 | 4 | # Pest Tests |
5 | 5 | - All tests must be written using Pest. |
6 | 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 | 7 | - Tests should test all of the the unhappy paths, happy paths, and weird paths. |
8 | 8 | - Tests live in the `tests/Feature` and `tests/Unit` directories. |
9 | 9 | - Pest tests look and behave like this: |
10 | | -<code-snippet lang="php"> |
| 10 | +<code-snippet name="Basic example Pest test" lang="php"> |
11 | 11 | it('is true', function () { |
12 | 12 | expect(true)->toBeTrue(); |
13 | 13 | }); |
|
22 | 22 |
|
23 | 23 | ## Pest Assertions |
24 | 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> |
| 25 | +<code-snippet name="Pest asserting postJson response" lang="php"> |
26 | 26 | it('returns all', function () { |
27 | 27 | $response = $this->postJson('/api/docs', []); |
28 | 28 |
|
|
32 | 32 |
|
33 | 33 | ## Mocking |
34 | 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;` or you can use `$this->mock()`. |
| 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. |
36 | 36 | - You can also create partial mocks using the same import or self method. |
37 | 37 |
|
38 | 38 | ## Datasets |
39 | 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 | 40 |
|
41 | | -<code-snippet lang="php" package="pest"> |
| 41 | +<code-snippet name="Pest dataset example" lang="php"> |
42 | 42 | it('has emails', function (string $email) { |
43 | 43 | expect($email)->not->toBeEmpty(); |
44 | 44 | })->with([ |
|
0 commit comments