Skip to content

Commit 6ebb8f4

Browse files
committed
Add dataset labels section to data-providers documentation
1 parent 882c6a3 commit 6ebb8f4

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

docs/data-providers.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ public function testSum(int $a, int $b, int $expected): void
2222

2323
Each `DataSet` is an array of arguments passed to the test method. The test runs three times with different values.
2424

25+
### Dataset Labels
26+
27+
The second argument is an optional label. It appears in reports and helps identify which scenario failed:
28+
29+
```php
30+
#[DataSet([1, 1, 2], 'positive numbers')]
31+
#[DataSet([-1, -1, -2], 'negative numbers')]
32+
#[DataSet([0, 0, 0], 'zeros')]
33+
public function testSum(int $a, int $b, int $expected): void { ... }
34+
```
2535

2636
## DataProvider
2737

@@ -80,3 +90,18 @@ public function testUser($data): void { ... }
8090
```
8191

8292
Invokable objects are particularly useful for separating data loading logic. For example, loading test cases from JSON/CSV files into a dedicated class keeps your test code clean.
93+
94+
### Dataset Labels
95+
96+
Labels are set via string array keys:
97+
98+
```php
99+
public function userDataProvider(): array
100+
{
101+
return [
102+
'valid email' => ['test@example.com', true],
103+
'invalid format' => ['not-an-email', false],
104+
'empty string' => ['', false],
105+
];
106+
}
107+
```

ru/docs/data-providers.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ public function testSum(int $a, int $b, int $expected): void
2222

2323
Каждый `DataSet` — массив аргументов, которые передаются в тестовый метод. Тест запустится три раза с разными значениями.
2424

25+
### Метки датасетов
26+
27+
Второй аргумент — опциональная метка. Отображается в отчётах и помогает понять, какой именно сценарий упал:
28+
29+
```php
30+
#[DataSet([1, 1, 2], 'positive numbers')]
31+
#[DataSet([-1, -1, -2], 'negative numbers')]
32+
#[DataSet([0, 0, 0], 'zeros')]
33+
public function testSum(int $a, int $b, int $expected): void { ... }
34+
```
2535

2636
## DataProvider
2737

@@ -80,3 +90,18 @@ public function testUser($data): void { ... }
8090
```
8191

8292
Вызываемые объекты особенно полезны для разделения логики загрузки данных. Например, загрузка тестов из JSON/CSV файлов в выделенный класс позволяет сохранить код тестов чистым.
93+
94+
### Метки датасетов
95+
96+
Метки задаются через строковые ключи массива:
97+
98+
```php
99+
public function userDataProvider(): array
100+
{
101+
return [
102+
'valid email' => ['test@example.com', true],
103+
'invalid format' => ['not-an-email', false],
104+
'empty string' => ['', false],
105+
];
106+
}
107+
```

0 commit comments

Comments
 (0)