├── .gitattributes
├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── dependabot.yml
├── release.yml
└── workflows
│ ├── build.yml
│ └── labels-verify.yml
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── phpcs.xml.dist
├── phpunit.10.0.report.xml
├── phpunit.10.0.xml
├── phpunit.report.xml
├── phpunit.xml.dist
├── psalm.xml.dist
├── scripts
└── CiScripts.php
├── src
├── AllureAdapter.php
├── AllureAdapterInterface.php
├── AllureExtension.php
├── Event
│ ├── TestConsideredRiskySubscriber.php
│ ├── TestErroredSubscriber.php
│ ├── TestFailedSubscriber.php
│ ├── TestFinishedSubscriber.php
│ ├── TestMarkedIncompleteSubscriber.php
│ ├── TestPassedSubscriber.php
│ ├── TestPreparationStartedSubscriber.php
│ ├── TestPreparedSubscriber.php
│ ├── TestSkippedSubscriber.php
│ └── TestWarningTriggeredSubscriber.php
├── ExceptionDetailsTrait.php
├── Internal
│ ├── Config.php
│ ├── ConfigInterface.php
│ ├── DefaultThreadDetector.php
│ ├── TestInfo.php
│ ├── TestLifecycle.php
│ ├── TestLifecycleInterface.php
│ ├── TestRunInfo.php
│ ├── TestStartInfo.php
│ ├── TestUpdater.php
│ └── TestUpdaterInterface.php
└── Setup
│ └── ThreadDetectorInterface.php
└── test
├── report
├── Generate
│ ├── Annotation
│ │ ├── TitleClassLevelLegacyTest.php
│ │ ├── TitleClassLevelMixedTest.php
│ │ ├── TitleClassLevelNativeTest.php
│ │ └── TitleTest.php
│ ├── AnnotationTest.php
│ ├── DataProviderTest.php
│ └── NegativeTest.php
└── Hook
│ ├── OnLifecycleErrorHook.php
│ └── OnSetupHook.php
└── unit
├── AllureAdapterTest.php
├── Event
├── EventTestTrait.php
├── TestConsideredRiskySubscriberTest.php
├── TestErroredSubscriberTest.php
├── TestFailedSubscriberTest.php
├── TestFinishedSubscriberTest.php
├── TestMarkedIncompleteSubscriberTest.php
├── TestPassedSubscriberTest.php
├── TestPreparationStartedSubscriberTest.php
├── TestPreparedSubscriberTest.php
├── TestSkippedSubscriberTest.php
└── TestWarningTriggeredSubscriberTest.php
├── ExceptionDetailsTraitTest.php
├── Internal
├── ConfigTest.php
├── DefaultThreadDetectorTest.php
├── TestInfoTest.php
├── TestLifecycleHook.php
├── TestLinkTemplate.php
├── TestRunInfoTest.php
├── TestStartInfoTest.php
└── TestThreadDetector.php
├── Setup
└── OnSetupHook.php
└── TestTestLifecycle.php
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Define the line ending behavior of the different file extensions
2 | # Set default behavior, in case users don't have core.autocrlf set.
3 | * text text=auto eol=lf
4 |
5 | .php diff=php
6 |
7 | # Declare files that will always have CRLF line endings on checkout.
8 | *.bat eol=crlf
9 |
10 | # Declare files that will always have LF line endings on checkout.
11 | *.pem eol=lf
12 |
13 | # Denote all files that are truly binary and should not be modified.
14 | *.png binary
15 | *.jpg binary
16 | *.gif binary
17 | *.ico binary
18 | *.mo binary
19 | *.pdf binary
20 | *.phar binary
21 | *.woff binary
22 | *.woff2 binary
23 | *.ttf binary
24 | *.otf binary
25 | *.eot binary
26 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "github-actions"
4 | directory: "/"
5 | schedule:
6 | interval: "daily"
7 | labels:
8 | - "type:dependencies"
9 |
10 | - package-ecosystem: "composer"
11 | directory: "/"
12 | schedule:
13 | interval: "daily"
14 | labels:
15 | - "type:dependencies"
16 |
--------------------------------------------------------------------------------
/.github/release.yml:
--------------------------------------------------------------------------------
1 | # release.yml
2 |
3 | changelog:
4 | categories:
5 | - title: '🚀 New Features'
6 | labels:
7 | - 'type:new feature'
8 | - title: '🔬 Improvements'
9 | labels:
10 | - 'type:improvement'
11 | - title: '🐞 Bug Fixes'
12 | labels:
13 | - 'type:bug'
14 | - title: '⬆️ Dependency Updates'
15 | labels:
16 | - 'type:dependencies'
17 | - title: '⛔️ Security'
18 | labels:
19 | - 'type:security'
20 | - title: '👻 Internal changes'
21 | labels:
22 | - 'type:internal'
23 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | workflow_dispatch:
5 | pull_request:
6 | branches:
7 | - '*'
8 | push:
9 | branches:
10 | - 'main'
11 |
12 | jobs:
13 | tests:
14 | name: PHP ${{ matrix.php-version }} PHPUnit ${{matrix.phpunit-version}} on ${{ matrix.os }} (${{ matrix.prefer-lowest }})
15 | runs-on: ${{ matrix.os }}
16 | strategy:
17 | fail-fast: false
18 | matrix:
19 | php-version:
20 | - "8.1"
21 | - "8.2"
22 | - "8.3"
23 | - "8.4"
24 | os:
25 | - ubuntu-latest
26 | - windows-latest
27 | - macOS-latest
28 | phpunit-version:
29 | - "10"
30 | - "11"
31 | - "12"
32 | prefer-lowest:
33 | - ""
34 | - "--prefer-lowest"
35 | exclude:
36 | # PHPUnit ^11 requires PHP 8.2
37 | - phpunit-version: "11"
38 | php-version: "8.1"
39 |
40 | # PHPUnit ^12 requires PHP 8.3
41 | - phpunit-version: "12"
42 | php-version: "8.1"
43 | - phpunit-version: "12"
44 | php-version: "8.2"
45 | include:
46 | # PHPUnit ^10.5.32 is incompatible with paratest 7.3.
47 | # Paratest 7.4.6, which fixes the incompatibility, requires PHP 8.2
48 | - php-version: "8.1"
49 | phpunit-version: "10"
50 | update-constraints: "'--with=phpunit/phpunit:<10.5.32'"
51 |
52 | # PHPUnit ~11.0 || ~11.1 can't double readonly classes, which fails some tests
53 | # We constraint PHPUnit 11 to ^11.2 until we find a better solution
54 | - phpunit-version: "11"
55 | update-constraints: "'--with=phpunit/phpunit:^11.2'"
56 | steps:
57 | - name: Checkout
58 | uses: actions/checkout@v4
59 |
60 | - name: Set up PHP ${{ matrix.php-version }}
61 | uses: shivammathur/setup-php@v2
62 | with:
63 | php-version: ${{ matrix.php-version }}
64 | extensions: pcntl, posix
65 | coverage: xdebug
66 | ini-values: error_reporting=E_ALL
67 |
68 | - name: Validate composer.json and composer.lock
69 | run: composer validate
70 |
71 | - name: Install dependencies
72 | run: >
73 | composer update --prefer-dist --no-progress
74 | ${{ matrix.prefer-lowest }}
75 | '--with=phpunit/phpunit:^${{ matrix.phpunit-version }}'
76 | ${{ matrix.update-constraints }}
77 | shell: bash
78 |
79 | - name: Set PHPUnit version
80 | id: set-phpunit-version
81 | run: |
82 | echo "Tested against PHPUnit **v$(composer print-phpunit-version)**" >> "$GITHUB_STEP_SUMMARY"
83 | echo "PHPUNIT_SCHEMA_VERSION=$(composer print-phpunit-schema-version)" >> "$GITHUB_OUTPUT"
84 | shell: bash
85 |
86 | - name: Run tests
87 | if: ${{ matrix.os != 'windows-latest' && steps.set-phpunit-version.outputs.PHPUNIT_SCHEMA_VERSION != '10.0' }}
88 | run: composer test
89 |
90 | - name: Run tests (phpunit10.0)
91 | if: ${{ matrix.os != 'windows-latest' && steps.set-phpunit-version.outputs.PHPUNIT_SCHEMA_VERSION == '10.0' }}
92 | run: composer test-phpunit10.0
93 |
94 | - name: Run tests (windows)
95 | if: ${{ matrix.os == 'windows-latest' && steps.set-phpunit-version.outputs.PHPUNIT_SCHEMA_VERSION != '10.0' }}
96 | run: composer test-windows
97 |
98 | - name: Run tests (windows-phpunit10.0)
99 | if: ${{ matrix.os == 'windows-latest' && steps.set-phpunit-version.outputs.PHPUNIT_SCHEMA_VERSION == '10.0' }}
100 | run: composer test-windows-phpunit10.0
101 |
--------------------------------------------------------------------------------
/.github/workflows/labels-verify.yml:
--------------------------------------------------------------------------------
1 | name: "Verify type labels"
2 |
3 | on:
4 | pull_request:
5 | types: [ labeled, unlabeled ]
6 |
7 | jobs:
8 | triage:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - uses: zwaldowski/match-label-action@v4
12 | with:
13 | allowed: 'type:bug,type:new feature,type:improvement,type:dependencies,type:internal,type:invalid'
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /vendor/
3 | /composer.lock
4 | /phpunit.xml
5 | /phpcs.xml
6 | /psalm.xml
7 | .phpunit.result.cache
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2022 Qameta Software OÜ
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Allure PHPUnit adapter
2 |
3 | [](https://packagist.org/packages/allure-framework/allure-phpunit)
4 | [](https://github.com/allure-framework/allure-phpunit/actions/workflows/build.yml)
5 | [](https://shepherd.dev/github/allure-framework/allure-phpunit)
6 | [](https://shepherd.dev/github/allure-framework/allure-phpunit)
7 | [](https://packagist.org/packages/allure-framework/allure-phpunit)
8 | [](https://packagist.org/packages/allure-framework/allure-phpunit)
9 |
10 | This an official PHPUnit adapter for Allure Framework - a flexible, lightweight and multi-language framework for writing self-documenting tests.
11 |
12 | ## Table of Contents
13 | * [What is this for?](#what-is-this-for)
14 | * [Example Project](#example-project)
15 | * [How to Generate Report](#how-to-generate-report)
16 | * [Installation and Usage](#installation-and-usage)
17 | * [Main Features](#main-features)
18 | * [Title](#human-readable-test-class-or-test-method-title)
19 | * [Description](#extended-test-class-or-test-method-description)
20 | * [Test severity](#set-test-severity)
21 | * [Test parameters](#specify-test-parameters-information)
22 | * [Features and Stories](#map-test-classes-and-test-methods-to-features-and-stories)
23 | * [Attachments](#attach-files-to-report)
24 | * [Steps](#divide-test-methods-into-steps)
25 |
26 | ## What is this for?
27 | The main purpose of this adapter is to accumulate information about your tests and write it out to a set of JSON files: one for each test class. Then you can use a standalone command line tool or a plugin for popular continuous integration systems to generate an HTML page showing your tests in a good form.
28 |
29 | ## Examples
30 | Please take a look at [these example tests](./test/report/Generate).
31 |
32 | ## How to generate report
33 | This adapter only generates JSON files containing information about tests. See [wiki section](https://docs.qameta.io/allure/#_reporting) on how to generate report.
34 |
35 | ## Installation && Usage
36 | **Note:** this adapter supports Allure 2.x.x only.
37 |
38 | Supported PHP versions: 8.1-8.4.
39 |
40 | In order to use this adapter you need to add a new dependency to your **composer.json** file:
41 | ```
42 | {
43 | "require": {
44 | "php": "^8.1",
45 | "allure-framework/allure-phpunit": "^3"
46 | }
47 | }
48 | ```
49 | Then add Allure test listener in **phpunit.xml** file:
50 | ```xml
51 |
52 |
53 |
54 |
55 |
56 |
57 | ```
58 | Config is common PHP file that should return an array:
59 | ```php
60 | 'build/allure-results',
65 | 'linkTemplates' => [
66 | // Class or object must implement \Qameta\Allure\Setup\LinkTemplateInterface
67 | 'tms' => \My\LinkTemplate::class,
68 | ],
69 | 'setupHook' => function (): void {
70 | // Some actions performed before starting the lifecycle
71 | },
72 | // Class or object must implement \Qameta\Allure\PHPUnit\Setup\ThreadDetectorInterface
73 | 'threadDetector' => \My\ThreadDetector::class,
74 | 'lifecycleHooks' => [
75 | // Class or object must implement one of \Qameta\Allure\Hook\LifecycleHookInterface descendants.
76 | \My\LifecycleHook::class,
77 | ],
78 | ];
79 | ```
80 |
81 | After running PHPUnit tests a new folder will be created (**build/allure-results** in the example above). This folder will contain generated JSON files. See [framework help](https://docs.qameta.io/allure/#_reporting) for details about how to generate report from JSON files. By default generated report will only show a limited set of information but you can use cool Allure features by adding a minimum of test code changes. Read next section for details.
82 |
83 | ## Main features
84 | This adapter comes with a set of PHP annotations and traits allowing to use main Allure features.
85 |
86 | ### 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 **#[DisplayName]** annotation:
88 | ```php
89 | namespace Example\Tests;
90 |
91 | use PHPUnit\Framework\TestCase;
92 | use Qameta\Allure\Attribute\DisplayName;
93 |
94 | #[DisplayName("Human-readable test class title")]
95 | class SomeTest extends TestCase
96 | {
97 | #[DisplayName("Human-readable test method title")]
98 | public function testCaseMethod(): void
99 | {
100 | //Some implementation here...
101 | }
102 | }
103 | ```
104 |
105 | ### Extended test class or test method description
106 | Similarly you can add detailed description for each test class and [test method](https://github.com/allure-framework/allure1/wiki/Glossary#test-case). To add such description simply use **#[Description]** annotation:
107 | ```php
108 | namespace Example\Tests;
109 |
110 | use PHPUnit\Framework\TestCase;
111 | use Qameta\Allure\Attribute\Description;
112 |
113 | #[Description("Detailed description for **test** class")]
114 | class SomeTest extends TestCase
115 | {
116 | #[Description("Detailed description for test class", isHtml: true)]
117 | public function testCaseMethod(): void
118 | {
119 | //Some implementation here...
120 | }
121 | }
122 | ```
123 | Description can be added in Markdown format (which is default one) or in HTML format. For HTML simply pass `true` value for optional `isHtml` argument.
124 |
125 | ### Set test severity
126 | **#[Severity]** annotation is used in order to prioritize test methods by severity:
127 |
128 | ```php
129 | namespace Example\Tests;
130 |
131 | use PHPUnit\Framework\TestCase;
132 | use Qameta\Allure\Attribute\Severity;
133 |
134 | class SomeTest extends TestCase
135 | {
136 | #[Severity(Severity::MINOR)]
137 | public function testCaseMethod(): void
138 | {
139 | //Some implementation here...
140 | }
141 | }
142 | ```
143 |
144 | ### Specify test parameters information
145 | In order to add information about test method [parameters](https://github.com/allure-framework/allure-core/wiki/Glossary#parameter) you should use **#[Parameter]** annotation. You can also use static shortcut if your marameter has dynamic value:
146 |
147 | ```php
148 | namespace Example\Tests;
149 |
150 | use PHPUnit\Framework\TestCase;
151 | use Qameta\Allure\Allure;
152 | use Qameta\Allure\Attribute\Parameter;
153 |
154 | class SomeTest extends TestCase
155 | {
156 | #[
157 | Parameter("param1", "value1"),
158 | Parameter("param2", "value2"),
159 | ]
160 | public function testCaseMethod(): void
161 | {
162 | //Some implementation here...
163 | Allure::parameter("param3", $someVar);
164 | }
165 | }
166 | ```
167 |
168 | ### Map test classes and test methods to features and stories
169 | In some development approaches tests are classified by [stories](https://github.com/allure-framework/allure-core/wiki/Glossary#user-story) and [features](https://github.com/allure-framework/allure-core/wiki/Glossary#feature). If you're using this then you can annotate your test with **#[Story]** and **#[Feature]** annotations:
170 | ```php
171 | namespace Example\Tests;
172 |
173 | use PHPUnit\Framework\TestCase;
174 | use Qameta\Allure\Attribute\Feature;
175 | use Qameta\Allure\Attribute\Story;
176 |
177 | #[
178 | Story("story1"),
179 | Story("story2"),
180 | Feature("feature1"),
181 | Feature("feature2"),
182 | Feature("feature3"),
183 | ]
184 | class SomeTest extends TestCase
185 | {
186 | #[
187 | Story("story3"),
188 | Feature("feature4"),
189 | ]
190 | public function testCaseMethod(): void
191 | {
192 | //Some implementation here...
193 | }
194 | }
195 | ```
196 | You will then be able to filter tests by specified features and stories in generated Allure report.
197 |
198 | ### Attach files to report
199 | If you wish to [attach some files](https://github.com/allure-framework/allure-core/wiki/Glossary#attachment) generated during PHPUnit run (screenshots, log files, dumps and so on) to report - then you need to use static shortcuts in your test class:
200 | ```php
201 | namespace Example\Tests;
202 |
203 | use PHPUnit\Framework\TestCase;
204 | use Qameta\Allure\Allure;
205 |
206 | class SomeTest extends TestCase
207 | {
208 |
209 | public function testCaseMethod()
210 | {
211 | //Some implementation here...
212 | Allure::attachment("Attachment 1", "attachment content", 'text/plain');
213 | Allure::attachmentFile("Attachment 2", "/path/to/file.png", 'image/png');
214 | //Some implementation here...
215 | }
216 | }
217 | ```
218 | In order to create an [attachment](https://github.com/allure-framework/allure-core/wiki/Glossary#attachment) simply call **Allure::attachment()** method. This method accepts human-readable name, string content and MIME attachment type. To attach a file, use **Allure::attachmentFile()** method that accepts file name instead of string content.
219 |
220 | ### Divide test methods into steps
221 | Allure framework also supports very useful feature called [steps](https://github.com/allure-framework/allure-core/wiki/Glossary#test-step). Consider a test method which has complex logic inside and several assertions. When an exception is thrown or one of assertions fails sometimes it's very difficult to determine which one caused the failure. Allure steps allow dividing test method logic into several isolated pieces having independent run statuses such as **passed** or **failed**. This allows to have much cleaner understanding of what really happens. In order to use steps simply use static shortcuts:
222 |
223 | ```php
224 | namespace Example\Tests;
225 |
226 | use PHPUnit\Framework\TestCase;
227 | use Qameta\Allure\Allure;
228 | use Qameta\Allure\Attribute\Parameter;
229 | use Qameta\Allure\Attribute\Title;
230 | use Qameta\Allure\StepContextInterface;
231 |
232 | class SomeTest extends TestCase
233 | {
234 |
235 | public function testCaseMethod(): void
236 | {
237 | //Some implementation here...
238 | $x = Allure::runStep(
239 | #[Title('First step')]
240 | function (StepContextInterface $step): string {
241 | $step->parameter('param1', $someValue);
242 |
243 | return 'foo';
244 | },
245 | );
246 | Allure::runStep([$this, 'stepTwo']);
247 | //Some implementation here...
248 | }
249 |
250 | #[
251 | Title("Second step"),
252 | Parameter("param2", "value2"),
253 | ]
254 | private function stepTwo(): void
255 | {
256 | //Some implementation here...
257 | }
258 | }
259 | ```
260 | The entire test method execution status will depend on every step but information about steps status will be stored separately.
261 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "allure-framework/allure-phpunit",
3 | "keywords": [
4 | "phpunit",
5 | "testing",
6 | "report",
7 | "steps",
8 | "attachments",
9 | "cases",
10 | "allure"
11 | ],
12 | "description": "Allure PHPUnit integration",
13 | "homepage": "https://allurereport.org/",
14 | "license": "Apache-2.0",
15 | "authors": [
16 | {
17 | "name": "Ivan Krutov",
18 | "email": "vania-pooh@yandex-team.ru",
19 | "role": "Developer"
20 | },
21 | {
22 | "name": "Edward Surov",
23 | "email": "zoohie@gmail.com",
24 | "role": "Developer"
25 | }
26 | ],
27 | "support": {
28 | "email": "allure@qameta.io",
29 | "source": "https://github.com/allure-framework/allure-phpunit"
30 | },
31 | "require": {
32 | "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
33 | "allure-framework/allure-php-commons": "^2.0",
34 | "phpunit/phpunit": "^10.0.5 || ^11 || ^12.0.1"
35 | },
36 | "require-dev": {
37 | "brianium/paratest": "^7",
38 | "psalm/plugin-phpunit": "^0.19.5",
39 | "squizlabs/php_codesniffer": "^3.7.2",
40 | "vimeo/psalm": "^6.10"
41 | },
42 | "conflict": {
43 | "amphp/byte-stream": "<1.5.1",
44 | "amphp/dns": "<2.2.0",
45 | "amphp/socket": "<2.3.1",
46 | "amphp/cache": "<2.0.1",
47 | "amphp/process": "<2.0.3",
48 | "amphp/parser": "<1.1.1",
49 | "daverandom/libdns": "<2.1.0",
50 | "spatie/array-to-xml": "<3.3.0",
51 | "ramsey/uuid": "<4.3.0",
52 | "brianium/paratest": "<7.0.3"
53 | },
54 | "autoload": {
55 | "psr-4": {
56 | "Qameta\\Allure\\PHPUnit\\": "src/"
57 | }
58 | },
59 | "autoload-dev": {
60 | "psr-0": {
61 | "Yandex": "test/"
62 | },
63 | "psr-4": {
64 | "Qameta\\Allure\\PHPUnit\\Test\\Unit\\": "test/unit/",
65 | "Qameta\\Allure\\PHPUnit\\Test\\Report\\": "test/report/",
66 | "Qameta\\Allure\\PHPUnit\\Scripts\\": "scripts/"
67 | }
68 | },
69 | "scripts": {
70 | "test-cs": "vendor/bin/phpcs -sp",
71 | "test-unit": "vendor/bin/phpunit --coverage-text",
72 | "test-unit-phpunit10.0": "vendor/bin/phpunit --configuration=phpunit.10.0.xml --coverage-text",
73 | "clear-allure-results": "rm -rf ./build/allure-results",
74 | "test-report": [
75 | "@clear-allure-results",
76 | "vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=positive",
77 | "vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative; exit 0"
78 | ],
79 | "test-report-phpunit10.0": [
80 | "@clear-allure-results",
81 | "vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=positive",
82 | "vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=negative; exit 0"
83 | ],
84 | "test-report-windows": [
85 | "@clear-allure-results",
86 | "vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=positive",
87 | "vendor/bin/paratest --processes=3 --configuration=phpunit.report.xml --testsuite=negative & exit 0"
88 | ],
89 | "test-report-windows-phpunit10.0": [
90 | "@clear-allure-results",
91 | "vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=positive",
92 | "vendor/bin/paratest --processes=3 --configuration=phpunit.10.0.report.xml --testsuite=negative & exit 0"
93 | ],
94 | "test-psalm": "vendor/bin/psalm --shepherd",
95 | "test": [
96 | "@test-cs",
97 | "@test-unit",
98 | "@test-report",
99 | "@test-psalm"
100 | ],
101 | "test-phpunit10.0": [
102 | "@test-cs",
103 | "@test-unit-phpunit10.0",
104 | "@test-report-phpunit10.0",
105 | "@test-psalm"
106 | ],
107 | "test-windows": [
108 | "@test-cs",
109 | "@test-unit",
110 | "@test-report-windows",
111 | "@test-psalm"
112 | ],
113 | "test-windows-phpunit10.0": [
114 | "@test-cs",
115 | "@test-unit-phpunit10.0",
116 | "@test-report-windows-phpunit10.0",
117 | "@test-psalm"
118 | ],
119 | "print-phpunit-version": [
120 | "Qameta\\Allure\\PHPUnit\\Scripts\\CiScripts::printPhpUnitVersion"
121 | ],
122 | "print-phpunit-schema-version": [
123 | "Qameta\\Allure\\PHPUnit\\Scripts\\CiScripts::printConfigSchemaVersion"
124 | ]
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/phpcs.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 | Qameta Coding Standards
4 |
5 | src
6 | test
7 |
8 |
9 |
10 |
11 |
12 |
13 | */test/*Test.php
14 |
15 |
16 |
--------------------------------------------------------------------------------
/phpunit.10.0.report.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 | test/report/Generate
16 | test/report/Generate/NegativeTest.php
17 |
18 |
19 | test/report/Generate/NegativeTest.php
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/phpunit.10.0.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 | test/unit/
16 |
17 |
18 |
19 |
20 | src/
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/phpunit.report.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 | test/report/Generate
16 | test/report/Generate/NegativeTest.php
17 |
18 |
19 | test/report/Generate/NegativeTest.php
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 | test/unit/
16 |
17 |
18 |
19 |
20 | src/
21 |
22 |
23 | vendor/
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/psalm.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/scripts/CiScripts.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 | private array $lastStarts = [];
24 |
25 | /**
26 | * @var array
27 | */
28 | private array $lastRuns = [];
29 |
30 | private ?Throwable $lastException = null;
31 |
32 | private function __construct()
33 | {
34 | }
35 |
36 | public static function getInstance(): AllureAdapterInterface
37 | {
38 | return self::$instance ??= new self();
39 | }
40 |
41 | public static function setInstance(AllureAdapterInterface $instance): void
42 | {
43 | self::$instance = $instance;
44 | }
45 |
46 | public static function reset(): void
47 | {
48 | self::$instance = null;
49 | }
50 |
51 | #[\Override]
52 | public function resetLastException(): void
53 | {
54 | $this->lastException = null;
55 | }
56 |
57 | #[\Override]
58 | public function setLastException(Throwable $e): void
59 | {
60 | $this->lastException = $e;
61 | }
62 |
63 | #[\Override]
64 | public function getLastException(): ?Throwable
65 | {
66 | return $this->lastException;
67 | }
68 |
69 | #[\Override]
70 | public function registerStart(ContainerResult $containerResult, TestResult $testResult, TestInfo $info): string
71 | {
72 | $this->lastStarts[$info->getTest()] = new TestStartInfo(
73 | containerId: $containerResult->getUuid(),
74 | testId: $testResult->getUuid(),
75 | );
76 |
77 | return $testResult->getUuid();
78 | }
79 |
80 | #[\Override]
81 | public function getContainerId(TestInfo $info): string
82 | {
83 | $startInfo = $this->lastStarts[$info->getTest()] ?? null;
84 |
85 | return $startInfo?->getContainerId()
86 | ?? throw new LogicException("Container not registered: {$info->getTest()}");
87 | }
88 |
89 | #[\Override]
90 | public function getTestId(TestInfo $info): string
91 | {
92 | $startInfo = $this->lastStarts[$info->getTest()] ?? null;
93 |
94 | return $startInfo?->getTestId()
95 | ?? throw new LogicException("Test not registered: {$info->getTest()}");
96 | }
97 |
98 | #[\Override]
99 | public function registerRun(TestResult $testResult, TestInfo $info): TestRunInfo
100 | {
101 | $testCaseId = $this->buildTestCaseId($testResult, $info);
102 | $historyId = $this->buildHistoryId($testResult, $info, $testCaseId);
103 |
104 | $previousRunInfo = $this->lastRuns[$historyId] ?? null;
105 | $currentRunInfo = new TestRunInfo(
106 | testInfo: $info,
107 | uuid: $testResult->getUuid(),
108 | rerunOf: $previousRunInfo?->getUuid(),
109 | runIndex: 1 + ($previousRunInfo?->getRunIndex() ?? -1),
110 | testCaseId: $testCaseId,
111 | historyId: $historyId,
112 | );
113 | $this->lastRuns[$historyId] = $currentRunInfo;
114 |
115 | return $currentRunInfo;
116 | }
117 |
118 | /**
119 | * @param TestResult $test
120 | * @return list
121 | */
122 | private function getIncludedParameters(TestResult $test): array
123 | {
124 | return array_values(
125 | array_filter(
126 | $test->getParameters(),
127 | fn (Parameter $parameter): bool => $parameter->getExcluded() !== true,
128 | ),
129 | );
130 | }
131 |
132 | private function buildTestCaseId(TestResult $test, TestInfo $info): string
133 | {
134 | $parameterNames = implode(
135 | '::',
136 | array_map(
137 | fn (Parameter $parameter): string => $parameter->getName(),
138 | $this->getIncludedParameters($test),
139 | ),
140 | );
141 |
142 | return md5("{$info->getName()}::{$parameterNames}");
143 | }
144 |
145 | private function buildHistoryId(TestResult $test, TestInfo $info, string $testCaseId): string
146 | {
147 | $parameterValues = implode(
148 | '::',
149 | array_map(
150 | fn (Parameter $parameter) => $parameter->getValue() ?? '',
151 | $this->getIncludedParameters($test),
152 | ),
153 | );
154 |
155 | return md5("{$testCaseId}::{$info->getName()}::{$parameterValues}");
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/src/AllureAdapterInterface.php:
--------------------------------------------------------------------------------
1 | loadConfigData($configSource));
40 | $this->setupAllure($config);
41 |
42 | return new TestLifecycle(
43 | Allure::getLifecycle(),
44 | Allure::getConfig()->getResultFactory(),
45 | Allure::getConfig()->getStatusDetector(),
46 | $config->getThreadDetector() ?? new DefaultThreadDetector(),
47 | AllureAdapter::getInstance(),
48 | new TestUpdater(Allure::getConfig()->getLinkTemplates()),
49 | );
50 | }
51 |
52 | private function setupAllure(ConfigInterface $config): void
53 | {
54 | Allure::getLifecycleConfigurator()->setOutputDirectory(
55 | $config->getOutputDirectory() ?? self::DEFAULT_OUTPUT_DIRECTORY,
56 | );
57 |
58 | foreach ($config->getLinkTemplates() as $linkType => $linkTemplate) {
59 | Allure::getLifecycleConfigurator()->addLinkTemplate(
60 | LinkType::fromOptionalString($linkType),
61 | $linkTemplate,
62 | );
63 | }
64 |
65 | if (!empty($config->getLifecycleHooks())) {
66 | Allure::getLifecycleConfigurator()->addHooks(...$config->getLifecycleHooks());
67 | }
68 |
69 | $setupHook = $config->getSetupHook();
70 | if (isset($setupHook)) {
71 | $setupHook();
72 | }
73 | }
74 |
75 | private function loadConfigData(?string $configFile): array
76 | {
77 | $fileShouldExist = isset($configFile);
78 | $configFile ??= self::DEFAULT_CONFIG_FILE;
79 | if (file_exists($configFile)) {
80 | /** @psalm-var mixed $data */
81 | $data = require $configFile;
82 |
83 | return is_array($data)
84 | ? $data
85 | : throw new RuntimeException("Config file {$configFile} must return array");
86 | } elseif ($fileShouldExist) {
87 | throw new RuntimeException("Config file {$configFile} doesn't exist");
88 | }
89 |
90 | return [];
91 | }
92 |
93 | #[\Override]
94 | public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
95 | {
96 | $configSource = $parameters->has('config')
97 | ? $parameters->get('config')
98 | : null;
99 |
100 | $testLifecycle = $this->testLifecycle ?? $this->createTestLifecycle($configSource);
101 |
102 | $facade->registerSubscribers(
103 | new Event\TestPreparationStartedSubscriber($testLifecycle),
104 | new Event\TestPreparedSubscriber($testLifecycle),
105 | new Event\TestFinishedSubscriber($testLifecycle),
106 | new Event\TestFailedSubscriber($testLifecycle),
107 | new Event\TestErroredSubscriber($testLifecycle),
108 | new Event\TestMarkedIncompleteSubscriber($testLifecycle),
109 | new Event\TestSkippedSubscriber($testLifecycle),
110 | new Event\TestWarningTriggeredSubscriber($testLifecycle),
111 | new Event\TestConsideredRiskySubscriber($testLifecycle),
112 | new Event\TestPassedSubscriber($testLifecycle),
113 | );
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/src/Event/TestConsideredRiskySubscriber.php:
--------------------------------------------------------------------------------
1 | test();
24 | $method = $test instanceof TestMethod ? $test->nameWithClass() : null;
25 | if (!isset($method)) {
26 | return;
27 | }
28 |
29 | $this
30 | ->testLifecycle
31 | ->switchTo($method)
32 | ->updateStatus($event->message(), Status::failed());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Event/TestErroredSubscriber.php:
--------------------------------------------------------------------------------
1 | test();
24 | $method = $test instanceof TestMethod ? $test->nameWithClass() : null;
25 | if (!isset($method)) {
26 | return;
27 | }
28 |
29 | $this
30 | ->testLifecycle
31 | ->switchTo($method)
32 | ->updateDetectedStatus($event->throwable()->message(), Status::broken());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Event/TestFailedSubscriber.php:
--------------------------------------------------------------------------------
1 | test();
24 | $method = $test instanceof TestMethod ? $test->nameWithClass() : null;
25 | if (!isset($method)) {
26 | return;
27 | }
28 |
29 | $this
30 | ->testLifecycle
31 | ->switchTo($method)
32 | ->updateDetectedStatus($event->throwable()->message(), Status::failed(), Status::failed());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Event/TestFinishedSubscriber.php:
--------------------------------------------------------------------------------
1 | test();
23 | $method = $test instanceof TestMethod ? $test->nameWithClass() : null;
24 | if (!isset($method)) {
25 | return;
26 | }
27 |
28 | $this
29 | ->testLifecycle
30 | ->switchTo($method)
31 | ->stop()
32 | ->updateRunInfo()
33 | ->write();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Event/TestMarkedIncompleteSubscriber.php:
--------------------------------------------------------------------------------
1 | test();
24 | $method = $test instanceof TestMethod ? $test->nameWithClass() : null;
25 | if (!isset($method)) {
26 | return;
27 | }
28 |
29 | $this
30 | ->testLifecycle
31 | ->switchTo($method)
32 | ->updateStatus($event->throwable()->message(), Status::broken());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Event/TestPassedSubscriber.php:
--------------------------------------------------------------------------------
1 | test();
24 | $method = $test instanceof TestMethod ? $test->nameWithClass() : null;
25 | if (!isset($method)) {
26 | return;
27 | }
28 |
29 | $this
30 | ->testLifecycle
31 | ->switchTo($method)
32 | ->updateStatus(status: Status::passed());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Event/TestPreparationStartedSubscriber.php:
--------------------------------------------------------------------------------
1 | test();
23 | $method = $test instanceof TestMethod ? $test->nameWithClass() : null;
24 | if (!isset($method)) {
25 | return;
26 | }
27 |
28 | $this
29 | ->testLifecycle
30 | ->switchTo($method)
31 | ->reset()
32 | ->create();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Event/TestPreparedSubscriber.php:
--------------------------------------------------------------------------------
1 | test();
23 | $method = $test instanceof TestMethod ? $test->nameWithClass() : null;
24 | if (!isset($method)) {
25 | return;
26 | }
27 |
28 | $this
29 | ->testLifecycle
30 | ->switchTo($method)
31 | ->updateInfo()
32 | ->start();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Event/TestSkippedSubscriber.php:
--------------------------------------------------------------------------------
1 | test();
24 | $method = $test instanceof TestMethod ? $test->nameWithClass() : null;
25 | if (!isset($method)) {
26 | return;
27 | }
28 |
29 | $this
30 | ->testLifecycle
31 | ->switchTo($method)
32 | ->updateStatus($event->message(), Status::skipped());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Event/TestWarningTriggeredSubscriber.php:
--------------------------------------------------------------------------------
1 | test();
24 | $method = $test instanceof TestMethod ? $test : null;
25 | if (!isset($method)) {
26 | return;
27 | }
28 |
29 | $this
30 | ->testLifecycle
31 | ->switchTo($method->nameWithClass())
32 | ->updateStatus($event->message(), Status::broken());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/ExceptionDetailsTrait.php:
--------------------------------------------------------------------------------
1 | setLastException($t);
14 | throw $t;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Internal/Config.php:
--------------------------------------------------------------------------------
1 | data[$key])) {
31 | return null;
32 | }
33 |
34 | /** @psalm-var mixed $outputDirectory */
35 | $outputDirectory = $this->data[$key];
36 |
37 | return is_string($outputDirectory)
38 | ? $outputDirectory
39 | : throw new RuntimeException("Config key \"{$key}\" should contain a string");
40 | }
41 |
42 | /**
43 | * @return array
44 | */
45 | #[\Override]
46 | public function getLinkTemplates(): array
47 | {
48 | $key = 'linkTemplates';
49 | $linkTemplates = [];
50 | /** @psalm-var mixed $linkTemplateSource */
51 | foreach ($this->getArrayFromData($key) as $linkKey => $linkTemplateSource) {
52 | if (!is_string($linkKey)) {
53 | throw new RuntimeException(
54 | "Config key \"{$key}\" should contain an array with string keys only",
55 | );
56 | }
57 | $linkTemplates[$linkKey] = $this->buildObject(
58 | "{$key}/{$linkKey}",
59 | $linkTemplateSource,
60 | LinkTemplateInterface::class,
61 | );
62 | }
63 |
64 | return $linkTemplates;
65 | }
66 |
67 | private function getArrayFromData(string $key): array
68 | {
69 | /** @psalm-var mixed $source */
70 | $source = $this->data[$key] ?? [];
71 |
72 | return is_array($source)
73 | ? $source
74 | : throw new RuntimeException("Config key \"{$key}\" should contain an array");
75 | }
76 |
77 | /**
78 | * @template T
79 | * @param string $key
80 | * @param mixed $source
81 | * @param class-string $expectedClass
82 | * @return T
83 | * @psalm-suppress MixedMethodCall
84 | */
85 | private function buildObject(string $key, mixed $source, string $expectedClass): object
86 | {
87 | return match (true) {
88 | $source instanceof $expectedClass => $source,
89 | $this->isExpectedClassName($source, $expectedClass) => new $source(),
90 | is_callable($source) => $this->buildObject($key, $source(), $expectedClass),
91 | default => throw new RuntimeException(
92 | "Config key \"{$key}\" contains invalid source of {$expectedClass}",
93 | ),
94 | };
95 | }
96 |
97 | /**
98 | * @template T
99 | * @param mixed $source
100 | * @param class-string $expectedClass
101 | * @return bool
102 | * @psalm-assert-if-true class-string $source
103 | */
104 | private function isExpectedClassName(mixed $source, string $expectedClass): bool
105 | {
106 | return $this->isClassName($source) && is_a($source, $expectedClass, true);
107 | }
108 |
109 | /**
110 | * @psalm-assert-if-true class-string $source
111 | */
112 | private function isClassName(mixed $source): bool
113 | {
114 | return is_string($source) && class_exists($source);
115 | }
116 |
117 | #[\Override]
118 | public function getSetupHook(): ?callable
119 | {
120 | $key = 'setupHook';
121 | /** @psalm-var mixed $source */
122 | $source = $this->data[$key] ?? null;
123 |
124 | return isset($source)
125 | ? $this->buildCallable($key, $source)
126 | : null;
127 | }
128 |
129 | /**
130 | * @psalm-suppress MixedMethodCall
131 | */
132 | private function buildCallable(string $key, mixed $source): callable
133 | {
134 | return match (true) {
135 | is_callable($source) => $source,
136 | $this->isClassName($source) => $this->buildCallable($key, new $source()),
137 | default => throw new RuntimeException("Config key \"{$key}\" should contain a callable"),
138 | };
139 | }
140 |
141 | #[\Override]
142 | public function getThreadDetector(): ?ThreadDetectorInterface
143 | {
144 | $key = 'threadDetector';
145 | /** @var mixed $threadDetector */
146 | $threadDetector = $this->data[$key] ?? null;
147 |
148 | return isset($threadDetector)
149 | ? $this->buildObject($key, $threadDetector, ThreadDetectorInterface::class)
150 | : null;
151 | }
152 |
153 | /**
154 | * @return list
155 | */
156 | #[\Override]
157 | public function getLifecycleHooks(): array
158 | {
159 | $key = 'lifecycleHooks';
160 | $hooks = [];
161 | /** @psalm-var mixed $hookSource */
162 | foreach ($this->getArrayFromData($key) as $index => $hookSource) {
163 | if (!is_int($index)) {
164 | throw new RuntimeException(
165 | "Config key \"{$key}\" should contain an array with integer keys only",
166 | );
167 | }
168 | $hooks[] = $this->buildObject(
169 | "{$key}/{$index}",
170 | $hookSource,
171 | LifecycleHookInterface::class,
172 | );
173 | }
174 |
175 | return $hooks;
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/src/Internal/ConfigInterface.php:
--------------------------------------------------------------------------------
1 |
17 | */
18 | public function getLinkTemplates(): array;
19 |
20 | public function getSetupHook(): ?callable;
21 |
22 | public function getThreadDetector(): ?ThreadDetectorInterface;
23 |
24 | /**
25 | * @return list
26 | */
27 | public function getLifecycleHooks(): array;
28 | }
29 |
--------------------------------------------------------------------------------
/src/Internal/DefaultThreadDetector.php:
--------------------------------------------------------------------------------
1 | hostName ??= @gethostname();
37 |
38 | return false === $this->hostName ? null : $this->hostName;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Internal/TestInfo.php:
--------------------------------------------------------------------------------
1 | test;
33 | }
34 |
35 | /**
36 | * @return class-string|null
37 | */
38 | public function getClass(): ?string
39 | {
40 | return $this->class;
41 | }
42 |
43 | public function getMethod(): ?string
44 | {
45 | return $this->method;
46 | }
47 |
48 | public function getDataLabel(): ?string
49 | {
50 | return $this->dataLabel;
51 | }
52 |
53 | public function getFullName(): ?string
54 | {
55 | return isset($this->class, $this->method)
56 | ? "{$this->class}::{$this->method}"
57 | : null;
58 | }
59 |
60 | public function getName(): string
61 | {
62 | return $this->getFullName() ?? $this->getTest();
63 | }
64 |
65 | public function getHost(): ?string
66 | {
67 | return $this->host;
68 | }
69 |
70 | public function getThread(): ?string
71 | {
72 | return $this->thread;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/Internal/TestLifecycle.php:
--------------------------------------------------------------------------------
1 | resultFactory->createContainer();
42 | $this->lifecycle->startContainer($containerResult);
43 |
44 | $testResult = $this->resultFactory->createTest();
45 | $this->lifecycle->scheduleTest($testResult, $containerResult->getUuid());
46 |
47 | $this->adapter->registerStart($containerResult, $testResult, $this->getCurrentTest());
48 |
49 | return $this;
50 | }
51 |
52 | #[\Override]
53 | public function updateInfo(): self
54 | {
55 | $this->lifecycle->updateTest(
56 | fn (TestResult $testResult) => $this->testUpdater->setInfo($testResult, $this->getCurrentTest()),
57 | $this->adapter->getTestId($this->getCurrentTest()),
58 | );
59 |
60 | return $this;
61 | }
62 |
63 | #[\Override]
64 | public function start(): self
65 | {
66 | $this->lifecycle->startTest(
67 | $this->adapter->getTestId($this->getCurrentTest()),
68 | );
69 |
70 | return $this;
71 | }
72 |
73 | #[\Override]
74 | public function stop(): self
75 | {
76 | $this->lifecycle->stopTest(
77 | $this->adapter->getTestId($this->getCurrentTest()),
78 | );
79 | $this->lifecycle->stopContainer(
80 | $this->adapter->getContainerId($this->getCurrentTest()),
81 | );
82 |
83 | return $this;
84 | }
85 |
86 | #[\Override]
87 | public function updateRunInfo(): self
88 | {
89 | $this->lifecycle->updateTest(
90 | fn (TestResult $testResult) => $this->testUpdater->setRunInfo(
91 | $testResult,
92 | $this->adapter->registerRun($testResult, $this->getCurrentTest()),
93 | ),
94 | $this->adapter->getTestId($this->getCurrentTest()),
95 | );
96 |
97 | return $this;
98 | }
99 |
100 | #[\Override]
101 | public function write(): self
102 | {
103 | $this->lifecycle->writeTest(
104 | $this->adapter->getTestId($this->getCurrentTest()),
105 | );
106 | $this->lifecycle->writeContainer(
107 | $this->adapter->getContainerId($this->getCurrentTest()),
108 | );
109 |
110 | return $this;
111 | }
112 |
113 | #[\Override]
114 | public function updateStatus(?string $message = null, ?Status $status = null): self
115 | {
116 | $this->lifecycle->updateTest(
117 | fn (TestResult $testResult) => $this->testUpdater->setStatus($testResult, $message, $status),
118 | $this->adapter->getTestId($this->getCurrentTest()),
119 | );
120 |
121 | return $this;
122 | }
123 |
124 | #[\Override]
125 | public function updateDetectedStatus(
126 | ?string $message = null,
127 | ?Status $status = null,
128 | ?Status $overrideStatus = null,
129 | ): self {
130 | $exception = $this->adapter->getLastException();
131 | if (!isset($exception)) {
132 | return $this->updateStatus($message, $status);
133 | }
134 |
135 | $this->lifecycle->updateTest(
136 | fn (TestResult $testResult) => $this->testUpdater->setDetectedStatus(
137 | $testResult,
138 | $this->statusDetector,
139 | $exception,
140 | $overrideStatus,
141 | ),
142 | $this->adapter->getTestId($this->getCurrentTest()),
143 | );
144 |
145 | return $this;
146 | }
147 |
148 | #[\Override]
149 | public function switchTo(string $test): self
150 | {
151 | $thread = $this->threadDetector->getThread();
152 | $this->lifecycle->switchThread($thread);
153 |
154 | $this->currentTest = $this->buildTestInfo(
155 | $test,
156 | $this->threadDetector->getHost(),
157 | $thread,
158 | );
159 |
160 | return $this;
161 | }
162 |
163 | #[\Override]
164 | public function reset(): self
165 | {
166 | $this->adapter->resetLastException();
167 |
168 | return $this;
169 | }
170 |
171 | private function getCurrentTest(): TestInfo
172 | {
173 | return $this->currentTest ?? throw new RuntimeException("Current test is not set");
174 | }
175 |
176 | private function buildTestInfo(string $test, ?string $host = null, ?string $thread = null): TestInfo
177 | {
178 | /** @var list $matches */
179 | $classAndMethodMatchResult = preg_match(
180 | '#^(\S+)(.*)$#',
181 | $test,
182 | $matches,
183 | );
184 | [$classAndMethod, $dataSetInfo] = 1 === $classAndMethodMatchResult
185 | ? [$matches[1] ?? null, $matches[2] ?? null]
186 | : [$test, null];
187 | $dataLabelMatchResult = isset($dataSetInfo)
188 | ? preg_match(
189 | '/^\s+with\s+data\s+set\s+(?:(#\d+)|"(.*)")$/',
190 | $dataSetInfo,
191 | $matches,
192 | )
193 | : false;
194 | $dataLabel = 1 === $dataLabelMatchResult
195 | ? $matches[2] ?? $matches[1] ?? null
196 | : null;
197 | if ('' === $dataLabel) {
198 | $dataLabel = null;
199 | }
200 |
201 | /** @psalm-suppress PossiblyUndefinedArrayOffset */
202 | [$class, $method] = isset($classAndMethod)
203 | ? array_pad(explode('::', $classAndMethod, 2), 2, null)
204 | : [null, null];
205 |
206 | /** @psalm-suppress MixedArgument */
207 | return new TestInfo(
208 | test: $test,
209 | class: isset($class) && class_exists($class) ? $class : null,
210 | method: $method,
211 | dataLabel: $dataLabel,
212 | host: $host,
213 | thread: $thread,
214 | );
215 | }
216 | }
217 |
--------------------------------------------------------------------------------
/src/Internal/TestLifecycleInterface.php:
--------------------------------------------------------------------------------
1 | testInfo;
25 | }
26 |
27 | public function getUuid(): string
28 | {
29 | return $this->uuid;
30 | }
31 |
32 | public function getRerunOf(): ?string
33 | {
34 | return $this->rerunOf;
35 | }
36 |
37 | public function getRunIndex(): int
38 | {
39 | return $this->runIndex;
40 | }
41 |
42 | public function getTestCaseId(): string
43 | {
44 | return $this->testCaseId;
45 | }
46 |
47 | public function getHistoryId(): string
48 | {
49 | return $this->historyId;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Internal/TestStartInfo.php:
--------------------------------------------------------------------------------
1 | containerId;
18 | }
19 |
20 | public function getTestId(): string
21 | {
22 | return $this->testId;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Internal/TestUpdater.php:
--------------------------------------------------------------------------------
1 | parseAnnotations($info);
37 |
38 | $testResult
39 | ->setName($parser->getDisplayName() ?? $info->getName())
40 | ->setFullName($info->getFullName())
41 | ->setDescriptionHtml($parser->getDescriptionHtml())
42 | ->setDescription($parser->getDescription())
43 | ->addLabels(
44 | ...$this->createSystemLabels($info),
45 | ...$parser->getLabels(),
46 | )
47 | ->addParameters(
48 | ...$this->createSystemParameters($info),
49 | ...$parser->getParameters(),
50 | )
51 | ->addLinks(...$parser->getLinks());
52 | }
53 |
54 | /**
55 | * @param TestInfo $info
56 | * @return AttributeParser
57 | */
58 | private function parseAnnotations(TestInfo $info): AttributeParser
59 | {
60 | $class = $info->getClass();
61 | if (!isset($class)) {
62 | return new AttributeParser([], $this->linkTemplates);
63 | }
64 |
65 | $annotations = [];
66 | $reader = new LegacyAttributeReader(
67 | new DoctrineAnnotationReader(),
68 | new AttributeReader(),
69 | );
70 | try {
71 | $classRef = new ReflectionClass($class);
72 | $annotations = [
73 | ...$annotations,
74 | ...$reader->getClassAnnotations($classRef),
75 | ];
76 | } catch (Throwable $e) {
77 | throw new LogicException("Annotations not loaded", 0, $e);
78 | }
79 |
80 | $method = $info->getMethod();
81 | if (!isset($method)) {
82 | return new AttributeParser($annotations, $this->linkTemplates);
83 | }
84 |
85 | try {
86 | $methodRef = new ReflectionMethod($class, $method);
87 | $annotations = [
88 | ...$annotations,
89 | ...$reader->getMethodAnnotations($methodRef),
90 | ];
91 | } catch (Throwable $e) {
92 | throw new LogicException("Annotations not loaded", 0, $e);
93 | }
94 |
95 | return new AttributeParser($annotations, $this->linkTemplates);
96 | }
97 |
98 | /**
99 | * @return list