Skip to content

Commit 9bbcf95

Browse files
Merge pull request #118 from TheDragonCode/andrey-helldar-patch-1
Revise Pest testing guidelines and examples
2 parents 8d7d010 + 6a228bd commit 9bbcf95

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

.ai/guidelines/pest/core.blade.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- If you need to verify a feature is working, write or update a Unit / Feature test.
55

66
### 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".
88
- 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.
99
- Tests should test all of the happy paths, failure paths, and weird paths.
1010
- Tests live in the `tests/Feature` and `tests/Unit` directories.
@@ -33,29 +33,24 @@
3333
- To filter on a particular test name: `php vendor/bin/pest --filter=testName` (recommended after making a change to a related file).
3434
- 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.
3535

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-
4636
### Mocking
4737
- Mocking can be very helpful when appropriate.
4838
- 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.
4939
- You can also create partial mocks using the same import or self method.
5040

5141
### Datasets
5242
- 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.
5344

5445
<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', [
5847
'james' => '[email protected]',
5948
'taylor' => '[email protected]',
6049
]);
6150
</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

Comments
 (0)