Skip to content

Commit 1b800cd

Browse files
authored
test method is correctly detectied with data provider (fixes allure-framework#98, via allure-framework#99)
1 parent bd37424 commit 1b800cd

File tree

10 files changed

+170
-31
lines changed

10 files changed

+170
-31
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,17 @@ jobs:
4949
${{ matrix.composer-options }}
5050

5151
- name: Run tests
52-
if: ${{ matrix.os != 'windows-latest' }}
52+
if: ${{ matrix.os != 'windows-latest' && !contains(matrix.composer-options, '--prefer-lowest') }}
5353
run: composer test
5454

55+
- name: Run tests (lowest)
56+
if: ${{ matrix.os != 'windows-latest' && contains(matrix.composer-options, '--prefer-lowest') }}
57+
run: composer test-lowest
58+
5559
- name: Run tests (windows)
56-
if: ${{ matrix.os == 'windows-latest' }}
60+
if: ${{ matrix.os == 'windows-latest' && !contains(matrix.composer-options, '--prefer-lowest') }}
5761
run: composer test-windows
62+
63+
- name: Run tests (windows-lowest)
64+
if: ${{ matrix.os == 'windows-latest' && contains(matrix.composer-options, '--prefer-lowest') }}
65+
run: composer test-windows-lowest

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,52 @@
6060
"scripts": {
6161
"test-cs": "vendor/bin/phpcs -sp",
6262
"test-unit": "vendor/bin/phpunit --coverage-text",
63+
"test-unit-lowest": "vendor/bin/phpunit --configuration=phpunit.10.0.xml --coverage-text",
6364
"clear-allure-results": "rm -rf ./build/allure-results",
6465
"test-report": [
6566
"@clear-allure-results",
6667
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=positive",
6768
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative; exit 0"
6869
],
70+
"test-report-lowest": [
71+
"@clear-allure-results",
72+
"vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=positive",
73+
"vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=negative; exit 0"
74+
],
6975
"test-report-windows": [
7076
"@clear-allure-results",
7177
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=positive",
7278
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative & exit 0"
7379
],
80+
"test-report-windows-lowest": [
81+
"@clear-allure-results",
82+
"vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=positive",
83+
"vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=negative & exit 0"
84+
],
7485
"test-psalm": "vendor/bin/psalm --shepherd",
7586
"test": [
7687
"@test-cs",
7788
"@test-unit",
7889
"@test-report",
7990
"@test-psalm"
8091
],
92+
"test-lowest": [
93+
"@test-cs",
94+
"@test-unit-lowest",
95+
"@test-report-lowest",
96+
"@test-psalm"
97+
],
8198
"test-windows": [
8299
"@test-cs",
83100
"@test-unit",
84101
"@test-report-windows",
85102
"@test-psalm"
103+
],
104+
"test-windows-lowest": [
105+
"@test-cs",
106+
"@test-unit-lowest",
107+
"@test-report-windows-lowest",
108+
"@test-psalm"
86109
]
87110
}
88111
}

phpunit.10.0.report.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
5+
colors="true"
6+
displayDetailsOnIncompleteTests="true"
7+
displayDetailsOnSkippedTests="true"
8+
displayDetailsOnTestsThatTriggerDeprecations="true"
9+
displayDetailsOnTestsThatTriggerWarnings="true"
10+
displayDetailsOnTestsThatTriggerNotices="true"
11+
displayDetailsOnTestsThatTriggerErrors="true"
12+
defaultTestSuite="positive">
13+
<testsuites>
14+
<testsuite name="positive">
15+
<directory>test/report/Generate</directory>
16+
<exclude>test/report/Generate/NegativeTest.php</exclude>
17+
</testsuite>
18+
<testsuite name="negative">
19+
<file>test/report/Generate/NegativeTest.php</file>
20+
</testsuite>
21+
</testsuites>
22+
<extensions>
23+
<bootstrap class="Qameta\Allure\PHPUnit\AllureExtension" />
24+
</extensions>
25+
</phpunit>

phpunit.10.0.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
5+
colors="true"
6+
displayDetailsOnIncompleteTests="true"
7+
displayDetailsOnSkippedTests="true"
8+
displayDetailsOnTestsThatTriggerDeprecations="true"
9+
displayDetailsOnTestsThatTriggerWarnings="true"
10+
displayDetailsOnTestsThatTriggerNotices="true"
11+
displayDetailsOnTestsThatTriggerErrors="true"
12+
defaultTestSuite="unit">
13+
<testsuites>
14+
<testsuite name="unit">
15+
<directory>test/unit/</directory>
16+
</testsuite>
17+
</testsuites>
18+
<coverage>
19+
<include>
20+
<directory suffix=".php">src/</directory>
21+
</include>
22+
</coverage>
23+
</phpunit>

phpunit.report.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
55
colors="true"
6+
displayDetailsOnIncompleteTests="true"
7+
displayDetailsOnSkippedTests="true"
8+
displayDetailsOnTestsThatTriggerDeprecations="true"
9+
displayDetailsOnTestsThatTriggerWarnings="true"
10+
displayDetailsOnTestsThatTriggerNotices="true"
11+
displayDetailsOnTestsThatTriggerErrors="true"
612
defaultTestSuite="positive">
713
<testsuites>
814
<testsuite name="positive">

phpunit.xml.dist

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
55
colors="true"
6+
displayDetailsOnIncompleteTests="true"
7+
displayDetailsOnSkippedTests="true"
8+
displayDetailsOnTestsThatTriggerDeprecations="true"
9+
displayDetailsOnTestsThatTriggerWarnings="true"
10+
displayDetailsOnTestsThatTriggerNotices="true"
11+
displayDetailsOnTestsThatTriggerErrors="true"
612
defaultTestSuite="unit">
713
<testsuites>
814
<testsuite name="unit">
915
<directory>test/unit/</directory>
1016
</testsuite>
1117
</testsuites>
12-
<coverage>
18+
<source>
1319
<include>
14-
<directory suffix=".php">src/</directory>
20+
<directory>src/</directory>
1521
</include>
16-
</coverage>
22+
<exclude>
23+
<directory>vendor/</directory>
24+
</exclude>
25+
</source>
1726
</phpunit>

src/Internal/TestLifecycle.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,26 @@ private function getCurrentTest(): TestInfo
165165

166166
private function buildTestInfo(string $test, ?string $host = null, ?string $thread = null): TestInfo
167167
{
168-
$dataLabelMatchResult = preg_match(
169-
'#^([^\s]+)\s+with\s+data\s+set\s+(\#\d+|".+")\s+\(.+\)$#',
168+
/** @var list<string> $matches */
169+
$classAndMethodMatchResult = preg_match(
170+
'#^(\S+)(.*)$#',
170171
$test,
171172
$matches,
172173
);
173-
174-
/** @var list<string> $matches */
175-
if (1 === $dataLabelMatchResult) {
176-
$classAndMethod = $matches[1] ?? null;
177-
$dataLabel = $matches[2] ?? '?';
178-
} else {
179-
$classAndMethod = $test;
174+
[$classAndMethod, $dataSetInfo] = 1 === $classAndMethodMatchResult
175+
? [$matches[1] ?? null, $matches[2] ?? null]
176+
: [$test, null];
177+
$dataLabelMatchResult = isset($dataSetInfo)
178+
? preg_match(
179+
'/^\s+with\s+data\s+set\s+(?:(#\d+)|"(.*)")$/',
180+
$dataSetInfo,
181+
$matches,
182+
)
183+
: false;
184+
$dataLabel = 1 === $dataLabelMatchResult
185+
? $matches[2] ?? $matches[1] ?? null
186+
: null;
187+
if ('' === $dataLabel) {
180188
$dataLabel = null;
181189
}
182190

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Qameta\Allure\PHPUnit\Test\Report\Generate;
6+
7+
use PHPUnit\Framework\Attributes\DataProvider;
8+
use PHPUnit\Framework\TestCase;
9+
use Qameta\Allure\Allure;
10+
use Qameta\Allure\Attribute\DisplayName;
11+
12+
class DataProviderTest extends TestCase
13+
{
14+
#[DataProvider('providerNamed'), DisplayName('Test with named data set')]
15+
public function testNamedDataSet(int $x, int $y): void
16+
{
17+
Allure::runStep(fn () => self::assertSame($x, $y));
18+
}
19+
20+
public static function providerNamed(): iterable
21+
{
22+
return [
23+
'Simple name' => [1, 1],
24+
'' => [2, 2],
25+
'"Double-quoted" name' => [3, 3],
26+
"'Single-quoted' name" => [4, 4],
27+
' ' => [5, 5],
28+
];
29+
}
30+
31+
#[DataProvider('providerListed')]
32+
public function testListedDataSet(int $x, int $y): void
33+
{
34+
Allure::runStep(fn () => self::assertSame($x, $y));
35+
}
36+
37+
public static function providerListed(): iterable
38+
{
39+
return [
40+
[1, 1],
41+
[2, 2],
42+
];
43+
}
44+
}

test/report/Generate/NegativeTest.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
namespace Qameta\Allure\PHPUnit\Test\Report\Generate;
66

7-
use PHPUnit\Event;
7+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
88
use PHPUnit\Framework\TestCase;
99
use Qameta\Allure\Allure;
1010
use Qameta\Allure\Attribute\DisplayName;
1111
use Qameta\Allure\PHPUnit\ExceptionDetailsTrait;
1212
use RuntimeException;
1313

14+
use function trigger_error;
15+
16+
use const E_USER_WARNING;
17+
1418
class NegativeTest extends TestCase
1519
{
1620
use ExceptionDetailsTrait;
@@ -51,22 +55,10 @@ function () {
5155
);
5256
}
5357

54-
#[DisplayName('Test that emits warning is reported as broken')]
58+
#[DisplayName('Test that emits warning is reported as broken'), DoesNotPerformAssertions]
5559
public function testWarning(): void
5660
{
57-
/**
58-
* @psalm-suppress InternalMethod
59-
* @psalm-suppress InternalClass
60-
* @psalm-suppress TooManyArguments
61-
*/
62-
Event\Facade::emitter()->testTriggeredWarning(
63-
$this->valueObjectForEvents(),
64-
"Test triggered warning",
65-
__FILE__,
66-
__LINE__,
67-
false,
68-
);
69-
self::assertTrue(true);
61+
trigger_error('"Test triggered warning"', E_USER_WARNING);
7062
}
7163

7264
#[DisplayName('Skipped test is reported as skipped')]

test/unit/Event/EventTestTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ protected function createTestWarningTriggeredEvent(
261261
'file',
262262
1,
263263
false,
264+
false,
264265
);
265266
}
266267
}

0 commit comments

Comments
 (0)