|
4 | 4 | - If you need to verify a feature is working, write or update a Unit / Feature test. |
5 | 5 |
|
6 | 6 | ### Pest Tests |
7 | | -- All tests must be written using Pest. Use `php artisan make:test --pest <name>`. |
| 7 | +- All tests must be written using Pest. Create a php file named PascalCaseTest, where "Test" is a mandatory suffix. For example, "CustomFeedTest.php". |
8 | 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 | 9 | - Tests should test all of the happy paths, failure paths, and weird paths. |
10 | 10 | - Tests live in the `tests/Feature` and `tests/Unit` directories. |
|
33 | 33 | - To filter on a particular test name: `php vendor/bin/pest --filter=testName` (recommended after making a change to a related file). |
34 | 34 | - 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. |
35 | 35 |
|
36 | | -### Pest Assertions |
37 | | -- When asserting status codes on a response, use the specific method like `assertForbidden` and `assertNotFound` instead of using `assertStatus(403)` or similar, e.g.: |
38 | | -<code-snippet name="Pest Example Asserting postJson Response" lang="php"> |
39 | | -it('returns all', function () { |
40 | | - $response = $this->postJson('/api/docs', []); |
41 | | - |
42 | | - $response->assertSuccessful(); |
43 | | -}); |
44 | | -</code-snippet> |
45 | | - |
46 | 36 | ### Mocking |
47 | 37 | - Mocking can be very helpful when appropriate. |
48 | 38 | - 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. |
49 | 39 | - You can also create partial mocks using the same import or self method. |
50 | 40 |
|
51 | 41 | ### Datasets |
52 | 42 | - Use datasets in Pest to simplify tests which have a lot of duplicated data. This is often the case when testing validation rules, so consider going with this solution when writing tests for validation rules. |
| 43 | +- - Check whether the dataset with the required data set exists in the files in the “datasets” folder. If the required set exists, use its name; otherwise, create a new one. |
53 | 44 |
|
54 | 45 | <code-snippet name="Pest Dataset Example" lang="php"> |
55 | | -it('has emails', function (string $email) { |
56 | | - expect($email)->not->toBeEmpty(); |
57 | | -})->with([ |
| 46 | +dataset('emails with names', [ |
58 | 47 | |
59 | 48 | |
60 | 49 | ]); |
61 | 50 | </code-snippet> |
| 51 | + |
| 52 | +<code-snippet name="Pest Dataset Using Example" lang="php"> |
| 53 | +it('has emails', function (string $email) { |
| 54 | + expect($email)->not->toBeEmpty(); |
| 55 | +})->with('emails with names'); |
| 56 | +</code-snippet> |
0 commit comments