Skip to content

Commit fd49404

Browse files
authored
support PHPUnit 10 (fixes allure-framework#85, via allure-framework#86)
1 parent 17d2a8a commit fd49404

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1335
-613
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
php-version:
20-
- "8.0"
2120
- "8.1"
2221
- "8.2"
22+
- "8.3"
2323
os:
2424
- ubuntu-latest
2525
- windows-latest
@@ -29,7 +29,7 @@ jobs:
2929
- "--prefer-lowest"
3030
steps:
3131
- name: Checkout
32-
uses: actions/checkout@v3.5.0
32+
uses: actions/checkout@v3
3333

3434
- name: Validate composer.json and composer.lock
3535
run: composer validate
@@ -49,19 +49,9 @@ jobs:
4949
${{ matrix.composer-options }}
5050

5151
- name: Run tests
52-
if: ${{ matrix.os != 'windows-latest' && matrix.php-version != '8.2' }}
52+
if: ${{ matrix.os != 'windows-latest' }}
5353
run: composer test
5454

5555
- name: Run tests (windows)
56-
if: ${{ matrix.os == 'windows-latest' && matrix.php-version != '8.2' }}
57-
run: composer test-windows
58-
59-
- name: Run tests (experimental)
60-
if: ${{ matrix.os != 'windows-latest' && matrix.php-version == '8.2' }}
61-
continue-on-error: true
62-
run: composer test
63-
64-
- name: Run tests (windows, experimental)
65-
if: ${{ matrix.os == 'windows-latest' && matrix.php-version == '8.2' }}
66-
continue-on-error: true
56+
if: ${{ matrix.os == 'windows-latest' }}
6757
run: composer test-windows

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ This adapter only generates JSON files containing information about tests. See [
3434

3535
## Installation && Usage
3636
**Note:** this adapter supports Allure 2.x.x only.
37+
38+
Supported PHP versions: 8.1-8.3.
39+
3740
In order to use this adapter you need to add a new dependency to your **composer.json** file:
3841
```
3942
{
4043
"require": {
41-
"php": "^8",
42-
"allure-framework/allure-phpunit": "^2"
44+
"php": "^8.1",
45+
"allure-framework/allure-phpunit": "^3"
4346
}
4447
}
4548
```
4649
Then add Allure test listener in **phpunit.xml** file:
4750
```xml
4851
<extensions>
49-
<extension class="Qameta\Allure\PHPUnit\AllureExtension">
50-
<!-- Optional arguments block; omit it if you want to use default values -->
51-
<arguments>
52-
<!-- Path to config file (default is config/allure.config.php) -->
53-
<string>config/allure.config.php</string>
54-
</arguments>
55-
</extension>
52+
<bootstrap class="Qameta\Allure\PHPUnit\AllureExtension">
53+
<!-- Path to config file (default is config/allure.config.php) -->
54+
<parameter name="config" value="config/allure.config.php" />
55+
</bootstrap>
5656
</extensions>
5757
```
5858
Config is common PHP file that should return an array:
@@ -84,17 +84,17 @@ After running PHPUnit tests a new folder will be created (**build/allure-results
8484
This adapter comes with a set of PHP annotations and traits allowing to use main Allure features.
8585

8686
### Human-readable test class or test method title
87-
In order to add such title to any test class or [test case](https://github.com/allure-framework/allure1/wiki/Glossary#test-case) method you need to annotate it with **#[Title]** annotation:
87+
In order to add such title to any test class or [test case](https://github.com/allure-framework/allure1/wiki/Glossary#test-case) method you need to annotate it with **#[DisplayName]** annotation:
8888
```php
8989
namespace Example\Tests;
9090

9191
use PHPUnit\Framework\TestCase;
92-
use Qameta\Allure\Attribute\Title;
92+
use Qameta\Allure\Attribute\DisplayName;
9393

94-
#[Title("Human-readable test class title")]
94+
#[DisplayName("Human-readable test class title")]
9595
class SomeTest extends TestCase
9696
{
97-
#[Title("Human-readable test method title")]
97+
#[DisplayName("Human-readable test method title")]
9898
public function testCaseMethod(): void
9999
{
100100
//Some implementation here...
@@ -251,7 +251,7 @@ class SomeTest extends TestCase
251251
Title("Second step"),
252252
Parameter("param2", "value2"),
253253
]
254-
private function stepTwo()
254+
private function stepTwo(): void
255255
{
256256
//Some implementation here...
257257
}

composer.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@
2929
"source": "https://github.com/allure-framework/allure-phpunit"
3030
},
3131
"require": {
32-
"php": "^8",
32+
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
3333
"allure-framework/allure-php-commons": "^2",
34-
"phpunit/phpunit": "^9"
34+
"phpunit/phpunit": "^10"
3535
},
3636
"require-dev": {
37-
"brianium/paratest": "^6.8",
37+
"brianium/paratest": "^7",
3838
"psalm/plugin-phpunit": "^0.18.4",
39-
"squizlabs/php_codesniffer": "^3.7.1",
40-
"vimeo/psalm": "^5.4"
39+
"squizlabs/php_codesniffer": "^3.7.2",
40+
"vimeo/psalm": "^5.15"
4141
},
4242
"conflict": {
43-
"amphp/byte-stream": "<1.5.1"
43+
"amphp/byte-stream": "<1.5.1",
44+
"brianium/paratest": "<7.0.3"
4445
},
4546
"autoload": {
4647
"psr-4": {
@@ -63,14 +64,12 @@
6364
"test-report": [
6465
"@clear-allure-results",
6566
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=positive",
66-
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative; exit 0",
67-
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=retries --repeat=3; exit 0"
67+
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative; exit 0"
6868
],
6969
"test-report-windows": [
7070
"@clear-allure-results",
7171
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=positive",
72-
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative & exit 0",
73-
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=retries --repeat=3 & exit 0"
72+
"vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative & exit 0"
7473
],
7574
"test-psalm": "vendor/bin/psalm --shepherd",
7675
"test": [

phpunit.report.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
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/9.5/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
55
colors="true"
66
defaultTestSuite="positive">
77
<testsuites>
88
<testsuite name="positive">
99
<directory>test/report/Generate</directory>
1010
<exclude>test/report/Generate/NegativeTest.php</exclude>
11-
<exclude>test/report/Generate/RetriesTest.php</exclude>
1211
</testsuite>
1312
<testsuite name="negative">
1413
<file>test/report/Generate/NegativeTest.php</file>
1514
</testsuite>
16-
<testsuite name="retries">
17-
<file>test/report/Generate/RetriesTest.php</file>
18-
</testsuite>
1915
</testsuites>
2016
<extensions>
21-
<extension class="Qameta\Allure\PHPUnit\AllureExtension" />
17+
<bootstrap class="Qameta\Allure\PHPUnit\AllureExtension" />
2218
</extensions>
2319
</phpunit>

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
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/9.5/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
55
colors="true"
66
defaultTestSuite="unit">
77
<testsuites>
88
<testsuite name="unit">
99
<directory>test/unit/</directory>
1010
</testsuite>
1111
</testsuites>
12-
<coverage processUncoveredFiles="true">
12+
<coverage>
1313
<include>
1414
<directory suffix=".php">src/</directory>
1515
</include>

psalm.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?xml version="1.0"?>
22
<psalm
33
errorLevel="1"
4+
findUnusedBaselineEntry="true"
5+
findUnusedCode="false"
6+
findUnusedPsalmSuppress="false"
7+
findUnusedVariablesAndParams="false"
48
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
59
xmlns="https://getpsalm.org/schema/config"
610
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">

src/AllureExtension.php

Lines changed: 27 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@
44

55
namespace Qameta\Allure\PHPUnit;
66

7-
use PHPUnit\Runner\AfterIncompleteTestHook;
8-
use PHPUnit\Runner\AfterRiskyTestHook;
9-
use PHPUnit\Runner\AfterSkippedTestHook;
10-
use PHPUnit\Runner\AfterSuccessfulTestHook;
11-
use PHPUnit\Runner\AfterTestErrorHook;
12-
use PHPUnit\Runner\AfterTestFailureHook;
13-
use PHPUnit\Runner\AfterTestHook;
14-
use PHPUnit\Runner\AfterTestWarningHook;
15-
use PHPUnit\Runner\BeforeTestHook;
7+
use PHPUnit\Runner\Extension\Extension;
8+
use PHPUnit\Runner\Extension\Facade;
9+
use PHPUnit\Runner\Extension\ParameterCollection;
10+
use PHPUnit\TextUI\Configuration\Configuration;
1611
use Qameta\Allure\Allure;
1712
use Qameta\Allure\Model\LinkType;
18-
use Qameta\Allure\Model\Status;
1913
use Qameta\Allure\PHPUnit\Internal\Config;
2014
use Qameta\Allure\PHPUnit\Internal\ConfigInterface;
2115
use Qameta\Allure\PHPUnit\Internal\DefaultThreadDetector;
@@ -29,37 +23,20 @@
2923

3024
use const DIRECTORY_SEPARATOR;
3125

32-
final class AllureExtension implements
33-
BeforeTestHook,
34-
AfterTestHook,
35-
AfterTestFailureHook,
36-
AfterTestErrorHook,
37-
AfterIncompleteTestHook,
38-
AfterSkippedTestHook,
39-
AfterTestWarningHook,
40-
AfterRiskyTestHook,
41-
AfterSuccessfulTestHook
26+
final class AllureExtension implements Extension
4227
{
4328
private const DEFAULT_OUTPUT_DIRECTORY = 'build' . DIRECTORY_SEPARATOR . 'allure-results';
4429

4530
private const DEFAULT_CONFIG_FILE = 'config' . DIRECTORY_SEPARATOR . 'allure.config.php';
4631

47-
private TestLifecycleInterface $testLifecycle;
48-
4932
public function __construct(
50-
string|array|ConfigInterface|TestLifecycleInterface|null $configOrTestLifecycle = null,
33+
private readonly ?TestLifecycleInterface $testLifecycle = null,
5134
) {
52-
$this->testLifecycle = $configOrTestLifecycle instanceof TestLifecycleInterface
53-
? $configOrTestLifecycle
54-
: $this->createTestLifecycle($configOrTestLifecycle);
5535
}
5636

57-
private function createTestLifecycle(string|array|ConfigInterface|null $configSource): TestLifecycleInterface
37+
private function createTestLifecycle(?string $configSource): TestLifecycleInterface
5838
{
59-
$config = $configSource instanceof ConfigInterface
60-
? $configSource
61-
: $this->loadConfig($configSource);
62-
39+
$config = new Config($this->loadConfigData($configSource));
6340
$this->setupAllure($config);
6441

6542
return new TestLifecycle(
@@ -95,15 +72,6 @@ private function setupAllure(ConfigInterface $config): void
9572
}
9673
}
9774

98-
private function loadConfig(string|array|null $configSource): ConfigInterface
99-
{
100-
return new Config(
101-
is_array($configSource)
102-
? $configSource
103-
: $this->loadConfigData($configSource),
104-
);
105-
}
106-
10775
private function loadConfigData(?string $configFile): array
10876
{
10977
$fileShouldExist = isset($configFile);
@@ -121,80 +89,26 @@ private function loadConfigData(?string $configFile): array
12189

12290
return [];
12391
}
124-
public function executeBeforeTest(string $test): void
125-
{
126-
$this
127-
->testLifecycle
128-
->switchTo($test)
129-
->reset()
130-
->create()
131-
->updateInfo()
132-
->start();
133-
}
134-
135-
public function executeAfterTest(string $test, float $time): void
136-
{
137-
$this
138-
->testLifecycle
139-
->switchTo($test)
140-
->stop()
141-
->updateRunInfo()
142-
->write();
143-
}
144-
145-
public function executeAfterTestFailure(string $test, string $message, float $time): void
146-
{
147-
$this
148-
->testLifecycle
149-
->switchTo($test)
150-
->updateDetectedStatus($message, Status::failed(), Status::failed());
151-
}
152-
153-
public function executeAfterTestError(string $test, string $message, float $time): void
154-
{
155-
$this
156-
->testLifecycle
157-
->switchTo($test)
158-
->updateDetectedStatus($message, Status::broken());
159-
}
160-
161-
public function executeAfterIncompleteTest(string $test, string $message, float $time): void
162-
{
163-
$this
164-
->testLifecycle
165-
->switchTo($test)
166-
->updateStatus($message, Status::broken());
167-
}
168-
169-
public function executeAfterSkippedTest(string $test, string $message, float $time): void
170-
{
171-
$this
172-
->testLifecycle
173-
->switchTo($test)
174-
->updateStatus($message, Status::skipped());
175-
}
17692

177-
public function executeAfterTestWarning(string $test, string $message, float $time): void
93+
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
17894
{
179-
$this
180-
->testLifecycle
181-
->switchTo($test)
182-
->updateStatus($message, Status::broken());
183-
}
184-
185-
public function executeAfterRiskyTest(string $test, string $message, float $time): void
186-
{
187-
$this
188-
->testLifecycle
189-
->switchTo($test)
190-
->updateStatus($message, Status::failed());
191-
}
192-
193-
public function executeAfterSuccessfulTest(string $test, float $time): void
194-
{
195-
$this
196-
->testLifecycle
197-
->switchTo($test)
198-
->updateStatus(status: Status::passed());
95+
$configSource = $parameters->has('config')
96+
? $parameters->get('config')
97+
: null;
98+
99+
$testLifecycle = $this->testLifecycle ?? $this->createTestLifecycle($configSource);
100+
101+
$facade->registerSubscribers(
102+
new Event\TestPreparationStartedSubscriber($testLifecycle),
103+
new Event\TestPreparedSubscriber($testLifecycle),
104+
new Event\TestFinishedSubscriber($testLifecycle),
105+
new Event\TestFailedSubscriber($testLifecycle),
106+
new Event\TestErroredSubscriber($testLifecycle),
107+
new Event\TestMarkedIncompleteSubscriber($testLifecycle),
108+
new Event\TestSkippedSubscriber($testLifecycle),
109+
new Event\TestWarningTriggeredSubscriber($testLifecycle),
110+
new Event\TestConsideredRiskySubscriber($testLifecycle),
111+
new Event\TestPassedSubscriber($testLifecycle),
112+
);
199113
}
200114
}

0 commit comments

Comments
 (0)