Skip to content

Commit 342d359

Browse files
committed
feat: add data provider support
- Updated `composer.json` and `composer.lock` to require new versions of dependencies, including `qase/php-commons` and `phpunit/phpunit`. - Added a new `DataProviderTest` class to demonstrate the usage of data providers in PHPUnit. - Enhanced `QaseReporter` to extract and merge parameters from data providers, improving test metadata handling. - Introduced methods for extracting and normalizing data provider parameters to ensure accurate test reporting.
1 parent c0502c9 commit 342d359

File tree

4 files changed

+410
-39
lines changed

4 files changed

+410
-39
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require": {
2323
"php": "^8.1",
2424
"phpunit/phpunit": "^10 || ^11",
25-
"qase/php-commons": "^2.1.4"
25+
"qase/php-commons": "^2.1.7"
2626
},
2727
"autoload": {
2828
"psr-4": {
@@ -34,7 +34,7 @@
3434
"Tests\\": "tests/"
3535
}
3636
},
37-
"version": "2.1.4",
37+
"version": "2.1.5",
3838
"scripts": {
3939
"test": "phpunit"
4040
},

composer.lock

Lines changed: 46 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/DataProviderTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PHPUnit\Framework\Attributes\DataProvider;
6+
use PHPUnit\Framework\TestCase;
7+
use Qase\PHPUnitReporter\Attributes\Parameter;
8+
use Qase\PHPUnitReporter\Attributes\Title;
9+
10+
class DataProviderTest extends TestCase
11+
{
12+
/**
13+
* Return a list of versions to test
14+
*/
15+
public static function getProviderData(): array
16+
{
17+
return [
18+
'v1' => ['version', 'v1'],
19+
'v2' => ['version', 'v2'],
20+
'v3' => ['version', 'v3'],
21+
];
22+
}
23+
24+
#[
25+
DataProvider('getProviderData'),
26+
Parameter('version', ''),
27+
Title("Test version")
28+
]
29+
public function testVersion(string $paramName, string $version): void
30+
{
31+
$this->assertStringContainsString('v', $version, "Version includes v");
32+
}
33+
34+
/**
35+
* Simple data provider with indexed array
36+
*/
37+
public static function getSimpleData(): array
38+
{
39+
return [
40+
['value1'],
41+
['value2'],
42+
['value3'],
43+
];
44+
}
45+
46+
#[
47+
DataProvider('getSimpleData'),
48+
Title("Test simple data provider")
49+
]
50+
public function testSimple(string $value): void
51+
{
52+
$this->assertNotEmpty($value);
53+
}
54+
55+
/**
56+
* Data provider with associative array
57+
*/
58+
public static function getAssociativeData(): array
59+
{
60+
return [
61+
['browser' => 'chrome', 'version' => '120'],
62+
['browser' => 'firefox', 'version' => '121'],
63+
];
64+
}
65+
66+
#[
67+
DataProvider('getAssociativeData'),
68+
Title("Test associative data provider")
69+
]
70+
public function testAssociative(array $data): void
71+
{
72+
$this->assertArrayHasKey('browser', $data);
73+
$this->assertArrayHasKey('version', $data);
74+
}
75+
}
76+

0 commit comments

Comments
 (0)