You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `toBeCasedCorrectly()` method may be used to ensure that all class names match their file and directory path casing, verifying PSR-4 autoloading compliance.
112
+
113
+
```php
114
+
arch('app')
115
+
->expect('App')
116
+
->toBeCasedCorrectly();
117
+
```
118
+
119
+
For example, if a class is named `App\Models\UserProfile`, this expectation verifies that the file is located at `app/Models/UserProfile.php` — and not `app/Models/Userprofile.php` or `app/models/UserProfile.php`.
Copy file name to clipboardExpand all lines: datasets.md
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,6 +85,36 @@ test('The generator produces only integers', function ($i) {
85
85
});
86
86
```
87
87
88
+
## Named Parameters
89
+
90
+
When using datasets with associative arrays, Pest matches the dataset keys to the closure parameter names, regardless of order. This allows you to define your dataset in any key order and have the values automatically mapped to the correct parameters.
91
+
92
+
```php
93
+
it('has user data', function (string $email, string $name) {
it('has user data', function (string $email, string $name) {
113
+
expect($name)->toBeString();
114
+
expect($email)->toContain('@');
115
+
})->with('users');
116
+
```
117
+
88
118
## Bound Datasets
89
119
90
120
Pest's bound datasets can be used to obtain a dataset that is resolved after the `beforeEach()` method of your tests. This is particularly useful in Laravel applications (or any other Pest integration) where you may need a dataset of `App\Models\User` models that are created after your database schema is prepared by the `beforeEach()` method.
@@ -176,6 +206,34 @@ When running the example above, Pest's output will contain a description of each
You can attach a dataset to a `describe()` block, and all tests within that block will receive the dataset values.
212
+
213
+
```php
214
+
describe('user notifications', function () {
215
+
test('can send notification', function (string $channel) {
216
+
expect($channel)->toBeString();
217
+
});
218
+
219
+
test('can queue notification', function (string $channel) {
220
+
expect($channel)->toBeIn(['mail', 'sms']);
221
+
});
222
+
})->with(['mail', 'sms']);
223
+
```
224
+
225
+
You can also use `beforeEach()->with()` inside a `describe()` block to apply a dataset to all tests within that scope.
226
+
227
+
```php
228
+
describe('user settings', function () {
229
+
beforeEach()->with([10, 20, 30]);
230
+
231
+
test('receives the dataset value', function (int $value) {
232
+
expect($value)->toBeGreaterThan(0);
233
+
});
234
+
});
235
+
```
236
+
179
237
## Repeating Tests
180
238
181
239
In some cases, you may need to repeat a test multiple times for debugging purposes or to ensure that the test is stable. On these occasions, you may use the `repeat()` method to repeat a test a given number of times.
Copy file name to clipboardExpand all lines: filtering-tests.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,7 @@ This chapter will cover even more ways to filter which tests are executed by Pes
17
17
18
18
-[`--bail`](#bail)
19
19
-[`--dirty`](#dirty)
20
+
-[`--flaky`](#flaky)
20
21
-[`--filter`](#filter)
21
22
-[`--group`](#group)
22
23
-[`--exclude-group`](#exclude-group)
@@ -45,6 +46,52 @@ The `--dirty` option instructs Pest to only run tests that have uncommitted chan
45
46
46
47
> Note that, due to a limitation in Pest, test cases written using the PHPUnit syntax will always be considered dirty.
47
48
49
+
<aname="flaky"></a>
50
+
### `--flaky`
51
+
52
+
Some tests may occasionally fail due to external factors like network latency, timing issues, or third-party service instability. You can mark these tests as "flaky" using the `flaky()` method, and Pest will automatically retry them before reporting a failure.
53
+
54
+
```php
55
+
it('may have external dependencies', function () {
56
+
$response = Http::get('https://example.com/api');
57
+
58
+
expect($response->status())->toBe(200);
59
+
})->flaky();
60
+
```
61
+
62
+
By default, `flaky()` retries the test up to **3 times**. You can customize the number of retries by passing the `tries` parameter.
63
+
64
+
```php
65
+
it('may have external dependencies', function () {
66
+
$response = Http::get('https://example.com/api');
67
+
68
+
expect($response->status())->toBe(200);
69
+
})->flaky(tries: 5);
70
+
```
71
+
72
+
Between retries, Pest properly re-runs your `setUp` and `tearDown` lifecycle hooks, clears mock objects, and resets dynamic properties — ensuring each attempt starts from a clean state.
73
+
74
+
Note that `flaky()` will not retry tests that are skipped, incomplete, or that throw an expected exception (via `->throws()`). It only retries on unexpected failures.
75
+
76
+
The `flaky()` method can be combined with other test methods like `with()`, `repeat()`, and `describe()` blocks.
77
+
78
+
```php
79
+
it('works with datasets', function (string $url) {
80
+
$response = Http::get($url);
81
+
82
+
expect($response->status())->toBe(200);
83
+
})->flaky(tries: 2)->with([
84
+
'https://example.com/api/users',
85
+
'https://example.com/api/posts',
86
+
]);
87
+
```
88
+
89
+
To list all tests marked as flaky in your test suite, use the `--flaky` option.
Copy file name to clipboardExpand all lines: test-coverage.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,20 @@ Or, you can use the `--exactly` option to enforce that the coverage results matc
56
56
./vendor/bin/pest --coverage --exactly=99.3
57
57
```
58
58
59
+
## Hiding Uncovered Files
60
+
61
+
When working on a large codebase, the coverage report can be noisy with many files showing 0% coverage. You can use the `--only-covered` option to hide files with no coverage from the report, allowing you to focus on the files that are partially covered.
62
+
63
+
```bash
64
+
./vendor/bin/pest --coverage --only-covered
65
+
```
66
+
67
+
This option can be combined with `--min` or `--exactly` for threshold enforcement.
If there are certain sections of your application that cannot be tested and should be excluded from code coverage analysis, you can use `@codeCoverageIgnoreStart` and `@codeCoverageIgnoreEnd` comments in your source code to achieve this.
0 commit comments