├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── dependabot.yml ├── release-drafter.yml └── workflows │ ├── build.yml │ ├── draft-release.yml │ └── labels-verify.yml ├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── phpunit.legacy.xml ├── phpunit.php ├── phpunit.xml ├── src └── Yandex │ └── Allure │ └── Adapter │ ├── Allure.php │ ├── AllureException.php │ ├── Annotation │ ├── AllureId.php │ ├── AnnotationManager.php │ ├── AnnotationProvider.php │ ├── Description.php │ ├── Epics.php │ ├── Features.php │ ├── Issues.php │ ├── Label.php │ ├── Labels.php │ ├── Parameter.php │ ├── Parameters.php │ ├── Severity.php │ ├── Stories.php │ ├── TestCaseId.php │ ├── TestType.php │ └── Title.php │ ├── Event │ ├── AddAttachmentEvent.php │ ├── AddParameterEvent.php │ ├── ClearStepStorageEvent.php │ ├── ClearTestCaseStorageEvent.php │ ├── Event.php │ ├── RemoveAttachmentsEvent.php │ ├── StepCanceledEvent.php │ ├── StepEvent.php │ ├── StepFailedEvent.php │ ├── StepFinishedEvent.php │ ├── StepStartedEvent.php │ ├── Storage │ │ ├── StepStorage.php │ │ ├── TestCaseStorage.php │ │ └── TestSuiteStorage.php │ ├── TestCaseBrokenEvent.php │ ├── TestCaseCanceledEvent.php │ ├── TestCaseEvent.php │ ├── TestCaseFailedEvent.php │ ├── TestCaseFinishedEvent.php │ ├── TestCasePendingEvent.php │ ├── TestCaseStartedEvent.php │ ├── TestCaseStatusChangedEvent.php │ ├── TestSuiteEvent.php │ ├── TestSuiteFinishedEvent.php │ └── TestSuiteStartedEvent.php │ ├── Model │ ├── Attachment.php │ ├── ConstantChecker.php │ ├── Description.php │ ├── DescriptionType.php │ ├── Entity.php │ ├── Failure.php │ ├── Label.php │ ├── LabelType.php │ ├── Parameter.php │ ├── ParameterKind.php │ ├── Provider.php │ ├── SeverityLevel.php │ ├── Status.php │ ├── Step.php │ ├── TestCase.php │ └── TestSuite.php │ └── Support │ ├── AttachmentSupport.php │ ├── StepSupport.php │ └── Utils.php └── test └── Yandex └── Allure └── Adapter ├── AllureTest.php ├── Annotation ├── AnnotationManagerTest.php ├── AnnotationProviderTest.php └── Fixtures │ ├── ClassWithAnnotations.php │ ├── ClassWithIgnoreAnnotation.php │ ├── ExampleTestSuite.php │ └── TestAnnotation.php ├── Event ├── AddAttachmentEventTest.php ├── AddParameterEventTest.php ├── RemoveAttachmentsEventTest.php ├── StepCanceledEventTest.php ├── StepFailedEventTest.php ├── StepFinishedEventTest.php ├── StepStartedEventTest.php ├── StepStatusChangedEventTest.php ├── Storage │ ├── Fixtures │ │ └── MockedRootStepStorage.php │ ├── StepStorageTest.php │ ├── TestCaseStorageTest.php │ └── TestSuiteStorageTest.php ├── TestCaseBrokenEventTest.php ├── TestCaseCanceledEventTest.php ├── TestCaseFailedEventTest.php ├── TestCaseFinishedEventTest.php ├── TestCasePendingEventTest.php ├── TestCaseStartedEventTest.php ├── TestCaseStatusChangedEventTest.php ├── TestSuiteFinishedEventTest.php └── TestSuiteStartedEventTest.php ├── Fixtures ├── GenericStepEvent.php ├── GenericTestCaseEvent.php └── GenericTestSuiteEvent.php ├── Model ├── ConstantCheckerTest.php └── Fixtures │ └── TestConstants.php ├── Support ├── AttachmentSupportTest.php ├── MockedLifecycle.php ├── StepSupportTest.php └── UtilsTest.php ├── XMLValidationTest.php └── allure-1.4.0.xsd /.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-drafter.yml: -------------------------------------------------------------------------------- 1 | name-template: '$NEXT_MINOR_VERSION' 2 | tag-template: '$NEXT_MINOR_VERSION' 3 | categories: 4 | - title: '🚀 New Features' 5 | labels: 6 | - 'type:new feature' 7 | - title: '🔬 Improvements' 8 | labels: 9 | - 'type:improvement' 10 | - title: '🐞 Bug Fixes' 11 | labels: 12 | - 'type:bug' 13 | - title: '⬆️ Dependency Updates' 14 | labels: 15 | - 'type:dependencies' 16 | 17 | change-template: '* $TITLE (via #$NUMBER) - @$AUTHOR' 18 | exclude-labels: 19 | - 'type:internal' 20 | template: | 21 | $CHANGES 22 | 23 | ## 👀 Links 24 | 25 | [Commits since $PREVIOUS_TAG](https://github.com/allure-framework/allure-php-api/compare/$PREVIOUS_TAG...master) 26 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - '*' 7 | push: 8 | branches: 9 | - 'master' 10 | - 'hotfix-*' 11 | 12 | jobs: 13 | build71: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v3.3.0 17 | - uses: shivammathur/setup-php@2.23.0 18 | with: 19 | php-version: '7.1.3' 20 | - name: Install 21 | run: composer update 22 | - name: Test 23 | run: composer test-legacy 24 | build72: 25 | runs-on: ubuntu-latest 26 | steps: 27 | - uses: actions/checkout@v3.3.0 28 | - uses: shivammathur/setup-php@2.23.0 29 | with: 30 | php-version: '7.2' 31 | - name: Install 32 | run: composer update 33 | - name: Test 34 | run: composer test-legacy 35 | build73: 36 | runs-on: ubuntu-latest 37 | steps: 38 | - uses: actions/checkout@v3.3.0 39 | - uses: shivammathur/setup-php@2.23.0 40 | with: 41 | php-version: '7.3' 42 | - name: Install 43 | run: composer update 44 | - name: Test 45 | run: composer test 46 | build74: 47 | runs-on: ubuntu-latest 48 | steps: 49 | - uses: actions/checkout@v3.3.0 50 | - uses: shivammathur/setup-php@2.23.0 51 | with: 52 | php-version: '7.4' 53 | - name: Install 54 | run: composer update 55 | - name: Test 56 | run: composer test 57 | build80: 58 | runs-on: ubuntu-latest 59 | steps: 60 | - uses: actions/checkout@v3.3.0 61 | - uses: shivammathur/setup-php@2.23.0 62 | with: 63 | php-version: '8.0' 64 | - name: Install 65 | run: composer update 66 | - name: Test 67 | run: composer test 68 | -------------------------------------------------------------------------------- /.github/workflows/draft-release.yml: -------------------------------------------------------------------------------- 1 | name: Release Draft 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | update_draft_release: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: toolmantim/release-drafter@v5.15.0 13 | env: 14 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 15 | -------------------------------------------------------------------------------- /.github/workflows/labels-verify.yml: -------------------------------------------------------------------------------- 1 | name: "Verify type labels" 2 | 3 | on: 4 | pull_request: 5 | types: [opened, labeled, unlabeled, synchronize] 6 | 7 | jobs: 8 | triage: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: zwaldowski/match-label-action@v2 12 | with: 13 | allowed: 'type:bug,type:new feature,type:improvement,type:dependencies,type:internal,type:invalid' 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .idea 3 | nbproject 4 | vendor/* 5 | composer.phar 6 | /composer.lock 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 2021 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 PHP API (maintenance) 2 | 3 | This project is in Maintenance mode. The new version of PHP API is available https://github.com/allure-framework/allure-php-commons2 . 4 | 5 | [![Build](https://github.com/allure-framework/allure-php-api/actions/workflows/build.yml/badge.svg)](https://github.com/allure-framework/allure-php-api/actions/workflows/build.yml) 6 | 7 | This repository contains PHP API for Allure framework. The main idea is to reuse this API when creating adapters for different test frameworks. 8 | 9 | ## Getting started 10 | In order to use this API you simply need to add the following to **composer.json**: 11 | ```json 12 | { 13 | "require": { 14 | "php": ">=5.4.0", 15 | "allure-framework/allure-php-api": "~1.0.0" 16 | } 17 | } 18 | ``` 19 | Basic usage idiom is to fire an event like the following: 20 | ```php 21 | Allure::lifecycle()->fire(new TestCaseFinishedEvent()); 22 | ``` 23 | 24 | ## Events 25 | The following events are available right now: 26 | * AddAttachmentEvent 27 | * AddParameterEvent 28 | * ClearStepStorageEvent 29 | * ClearTestCaseStorageEvent 30 | * RemoveAttachmentsEvent 31 | * StepCanceledEvent 32 | * StepEvent 33 | * StepFailedEvent 34 | * StepFinishedEvent 35 | * StepStartedEvent 36 | * TestCaseBrokenEvent 37 | * TestCaseCanceledEvent 38 | * TestCaseEvent 39 | * TestCaseFailedEvent 40 | * TestCaseFinishedEvent 41 | * TestCasePendingEvent 42 | * TestCaseStartedEvent 43 | * TestCaseStatusChangedEvent 44 | * TestSuiteEvent 45 | * TestSuiteFinishedEvent 46 | * TestSuiteStartedEvent 47 | 48 | ## Usage examples 49 | See [allure-phpunit](https://github.com/allure-framework/allure-phpunit) project. 50 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "allure-framework/allure-php-api", 3 | "keywords":["PHP", "report", "allure", "api"], 4 | "description": "Allure PHP commons", 5 | "homepage": "https://allurereport.org/", 6 | "license": "Apache-2.0", 7 | "authors": [ 8 | { 9 | "name": "Ivan Krutov", 10 | "email": "vania-pooh@yandex-team.ru", 11 | "role": "Developer" 12 | } 13 | ], 14 | "support": { 15 | "email": "allure@qameta.io", 16 | "source": "https://github.com/allure-framework/allure-php-api" 17 | }, 18 | "require": { 19 | "php": ">=7.1.3", 20 | "jms/serializer": "^1 | ^2 | ^3", 21 | "ramsey/uuid": "^3 | ^4", 22 | "symfony/mime": "^4.3 | ^5", 23 | "doctrine/annotations": "1.*" 24 | }, 25 | "require-dev": { 26 | "phpunit/phpunit": "^7 | ^8 | ^9" 27 | }, 28 | "autoload": { 29 | "psr-0": { 30 | "Yandex": ["src/", "test/"] 31 | } 32 | }, 33 | "scripts": { 34 | "test": "vendor/bin/phpunit", 35 | "test-legacy": "vendor/bin/phpunit --configuration=phpunit.legacy.xml" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /phpunit.legacy.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | test/Yandex/Allure/Adapter/ 11 | 12 | 13 | 14 | 15 | src/ 16 | 17 | 18 | -------------------------------------------------------------------------------- /phpunit.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | test/Yandex/Allure/Adapter/ 11 | 12 | 13 | 14 | 15 | src/ 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Allure.php: -------------------------------------------------------------------------------- 1 | stepStorage = new StepStorage(); 45 | $this->testCaseStorage = new TestCaseStorage(); 46 | $this->testSuiteStorage = new TestSuiteStorage(); 47 | } 48 | 49 | /** 50 | * @return Allure 51 | */ 52 | public static function lifecycle() 53 | { 54 | if (!isset(self::$lifecycle)) { 55 | self::setDefaultLifecycle(); 56 | } 57 | 58 | return self::$lifecycle; 59 | } 60 | 61 | public static function setLifecycle(Allure $lifecycle) 62 | { 63 | self::$lifecycle = $lifecycle; 64 | } 65 | 66 | public static function setDefaultLifecycle() 67 | { 68 | self::$lifecycle = new Allure(); 69 | } 70 | 71 | public function fire(Event $event) 72 | { 73 | if ($event instanceof StepStartedEvent) { 74 | $this->processStepStartedEvent($event); 75 | } elseif ($event instanceof StepFinishedEvent) { 76 | $this->processStepFinishedEvent($event); 77 | } elseif ($event instanceof TestCaseStartedEvent) { 78 | $this->processTestCaseStartedEvent($event); 79 | } elseif ($event instanceof TestCaseFinishedEvent) { 80 | $this->processTestCaseFinishedEvent($event); 81 | } elseif ($event instanceof TestSuiteFinishedEvent) { 82 | $this->processTestSuiteFinishedEvent($event); 83 | } elseif ($event instanceof TestSuiteEvent) { 84 | $this->processTestSuiteEvent($event); 85 | } elseif ($event instanceof ClearStepStorageEvent) { 86 | $this->processClearStepStorageEvent(); 87 | } elseif ($event instanceof ClearTestCaseStorageEvent) { 88 | $this->processClearTestCaseStorageEvent(); 89 | } elseif ($event instanceof TestCaseEvent) { 90 | $this->processTestCaseEvent($event); 91 | } elseif ($event instanceof StepEvent) { 92 | $this->processStepEvent($event); 93 | } else { 94 | throw new AllureException("Unknown event: " . get_class($event)); 95 | } 96 | $this->lastEvent = $event; 97 | } 98 | 99 | protected function processStepStartedEvent(StepStartedEvent $event) 100 | { 101 | $step = new Step(); 102 | $event->process($step); 103 | $this->getStepStorage()->put($step); 104 | } 105 | 106 | protected function processStepFinishedEvent(StepFinishedEvent $event) 107 | { 108 | $step = $this->getStepStorage()->pollLast(); 109 | $event->process($step); 110 | $this->getStepStorage()->getLast()->addStep($step); 111 | } 112 | 113 | protected function processStepEvent(StepEvent $event) 114 | { 115 | $step = $this->getStepStorage()->getLast(); 116 | $event->process($step); 117 | } 118 | 119 | protected function processTestCaseStartedEvent(TestCaseStartedEvent $event) 120 | { 121 | //init root step if needed 122 | $this->getStepStorage()->getLast(); 123 | 124 | $testCase = $this->getTestCaseStorage()->get(); 125 | $event->process($testCase); 126 | $this->getTestSuiteStorage()->get($event->getSuiteUuid())->addTestCase($testCase); 127 | } 128 | 129 | protected function processTestCaseFinishedEvent(TestCaseFinishedEvent $event) 130 | { 131 | $testCase = $this->getTestCaseStorage()->get(); 132 | $event->process($testCase); 133 | $rootStep = $this->getStepStorage()->pollLast(); 134 | foreach ($rootStep->getSteps() as $step) { 135 | $testCase->addStep($step); 136 | } 137 | foreach ($rootStep->getAttachments() as $attachment) { 138 | $testCase->addAttachment($attachment); 139 | } 140 | $this->getTestCaseStorage()->clear(); 141 | } 142 | 143 | protected function processTestCaseEvent(TestCaseEvent $event) 144 | { 145 | $testCase = $this->getTestCaseStorage()->get(); 146 | $event->process($testCase); 147 | } 148 | 149 | protected function processTestSuiteEvent(TestSuiteEvent $event) 150 | { 151 | $uuid = $event->getUuid(); 152 | $testSuite = $this->getTestSuiteStorage()->get($uuid); 153 | $event->process($testSuite); 154 | } 155 | 156 | protected function processTestSuiteFinishedEvent(TestSuiteFinishedEvent $event) 157 | { 158 | $suiteUuid = $event->getUuid(); 159 | $testSuite = $this->getTestSuiteStorage()->get($suiteUuid); 160 | $event->process($testSuite); 161 | $this->getTestSuiteStorage()->remove($suiteUuid); 162 | $this->saveToFile($suiteUuid, $testSuite); 163 | } 164 | 165 | protected function saveToFile($testSuiteUuid, TestSuite $testSuite) 166 | { 167 | if ($testSuite->size() > 0) { 168 | $xml = $testSuite->serialize(); 169 | $fileName = $testSuiteUuid . '-testsuite.xml'; 170 | $filePath = Provider::getOutputDirectory() . DIRECTORY_SEPARATOR . $fileName; 171 | file_put_contents($filePath, $xml); 172 | } 173 | } 174 | 175 | protected function processClearStepStorageEvent() 176 | { 177 | $this->getStepStorage()->clear(); 178 | } 179 | 180 | protected function processClearTestCaseStorageEvent() 181 | { 182 | $this->getTestCaseStorage()->clear(); 183 | } 184 | 185 | /** 186 | * @return \Yandex\Allure\Adapter\Event\Storage\StepStorage 187 | */ 188 | public function getStepStorage() 189 | { 190 | return $this->stepStorage; 191 | } 192 | 193 | /** 194 | * @return \Yandex\Allure\Adapter\Event\Storage\TestCaseStorage 195 | */ 196 | public function getTestCaseStorage() 197 | { 198 | return $this->testCaseStorage; 199 | } 200 | 201 | /** 202 | * @return \Yandex\Allure\Adapter\Event\Storage\TestSuiteStorage 203 | */ 204 | public function getTestSuiteStorage() 205 | { 206 | return $this->testSuiteStorage; 207 | } 208 | 209 | /** 210 | * @return \Yandex\Allure\Adapter\Event\Event 211 | */ 212 | public function getLastEvent() 213 | { 214 | return $this->lastEvent; 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/AllureException.php: -------------------------------------------------------------------------------- 1 | labels = []; 35 | $this->parameters = []; 36 | $this->processAnnotations($annotations); 37 | } 38 | 39 | private function processAnnotations(array $annotations) 40 | { 41 | foreach ($annotations as $annotation) { 42 | if ($annotation instanceof AllureId) { 43 | $this->labels[] = Model\Label::id($annotation->value); 44 | } elseif ($annotation instanceof Title) { 45 | $this->title = $annotation->value; 46 | } elseif ($annotation instanceof Description) { 47 | $this->description = new Model\Description( 48 | $annotation->type, 49 | $annotation->value 50 | ); 51 | } elseif ($annotation instanceof Epics) { 52 | foreach ($annotation->getEpicNames() as $epicName) { 53 | $this->labels[] = Model\Label::epic($epicName); 54 | } 55 | } elseif ($annotation instanceof Features) { 56 | foreach ($annotation->getFeatureNames() as $featureName) { 57 | $this->labels[] = Model\Label::feature($featureName); 58 | } 59 | } elseif ($annotation instanceof Stories) { 60 | foreach ($annotation->getStories() as $issueKey) { 61 | $this->labels[] = Model\Label::story($issueKey); 62 | } 63 | } elseif ($annotation instanceof Issues) { 64 | foreach ($annotation->getIssueKeys() as $issueKey) { 65 | $this->labels[] = Model\Label::issue($issueKey); 66 | } 67 | } elseif ($annotation instanceof TestCaseId) { 68 | foreach ($annotation->getTestCaseIds() as $testCaseId) { 69 | $this->labels[] = Model\Label::testId($testCaseId); 70 | } 71 | } elseif ($annotation instanceof Severity) { 72 | $this->labels[] = Model\Label::severity( 73 | ConstantChecker::validate('Yandex\Allure\Adapter\Model\SeverityLevel', $annotation->level) 74 | ); 75 | } elseif ($annotation instanceof TestType) { 76 | $this->labels[] = Model\Label::testType($annotation->type); 77 | } elseif ($annotation instanceof Parameter) { 78 | $this->parameters[] = new Model\Parameter( 79 | $annotation->name, 80 | $annotation->value, 81 | $annotation->kind 82 | ); 83 | } elseif ($annotation instanceof Parameters) { 84 | foreach ($annotation->parameters as $parameter) { 85 | $this->parameters[] = new Model\Parameter( 86 | $parameter->name, 87 | $parameter->value, 88 | $parameter->kind 89 | ); 90 | } 91 | } elseif ($annotation instanceof Label) { 92 | foreach ($annotation -> values as $value) { 93 | $this->labels[] = Model\Label::label($annotation->name, $value); 94 | } 95 | } elseif ($annotation instanceof Labels) { 96 | foreach ($annotation -> labels as $label) { 97 | foreach ($label -> values as $value) { 98 | $this->labels[] = Model\Label::label($label->name, $value); 99 | } 100 | } 101 | } 102 | } 103 | } 104 | 105 | public function updateTestSuiteEvent(TestSuiteStartedEvent $event) 106 | { 107 | 108 | if ($this->isTitlePresent()) { 109 | $event->setTitle($this->getTitle()); 110 | } 111 | 112 | if ($this->isDescriptionPresent()) { 113 | $event->setDescription($this->getDescription()); 114 | } 115 | 116 | if ($this->areLabelsPresent()) { 117 | $event->setLabels($this->getLabels()); 118 | } 119 | 120 | } 121 | 122 | public function updateTestCaseEvent(TestCaseStartedEvent $event) 123 | { 124 | if ($this->isTitlePresent()) { 125 | $event->setTitle($this->getTitle()); 126 | } 127 | 128 | if ($this->isDescriptionPresent()) { 129 | $event->setDescription($this->getDescription()); 130 | } 131 | 132 | if ($this->areLabelsPresent()) { 133 | $event->setLabels(array_merge($event->getLabels(), $this->getLabels())); 134 | } 135 | 136 | if ($this->areParametersPresent()) { 137 | $event->setParameters($this->getParameters()); 138 | } 139 | 140 | } 141 | 142 | /** 143 | * @return Model\Description 144 | */ 145 | public function getDescription() 146 | { 147 | return $this->description; 148 | } 149 | 150 | /** 151 | * @return array 152 | */ 153 | public function getLabels() 154 | { 155 | return $this->labels; 156 | } 157 | 158 | /** 159 | * @return array 160 | */ 161 | public function getParameters() 162 | { 163 | return $this->parameters; 164 | } 165 | 166 | /** 167 | * @return string 168 | */ 169 | public function getTitle() 170 | { 171 | return $this->title; 172 | } 173 | 174 | public function isTitlePresent() 175 | { 176 | return isset($this->title); 177 | } 178 | 179 | public function isDescriptionPresent() 180 | { 181 | return isset($this->description); 182 | } 183 | 184 | public function areLabelsPresent() 185 | { 186 | return !empty($this->labels); 187 | } 188 | 189 | public function areParametersPresent() 190 | { 191 | return !empty($this->parameters); 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Annotation/AnnotationProvider.php: -------------------------------------------------------------------------------- 1 | getClassAnnotations($ref); 31 | } 32 | 33 | /** 34 | * Returns a list of method annotations 35 | * @param $instance 36 | * @param $methodName 37 | * @return array 38 | */ 39 | public static function getMethodAnnotations($instance, $methodName) 40 | { 41 | $ref = new \ReflectionMethod($instance, $methodName); 42 | 43 | return self::getIndexedReader()->getMethodAnnotations($ref); 44 | } 45 | 46 | /** 47 | * @return IndexedReader 48 | */ 49 | private static function getIndexedReader() 50 | { 51 | if (!isset(self::$indexedReader)) { 52 | self::registerAnnotationNamespaces(); 53 | self::$indexedReader = new IndexedReader(self::getAnnotationReader()); 54 | } 55 | 56 | return self::$indexedReader; 57 | } 58 | 59 | /** 60 | * @return AnnotationReader 61 | */ 62 | private static function getAnnotationReader() 63 | { 64 | if (!isset(self::$annotationReader)) { 65 | self::registerAnnotationNamespaces(); 66 | self::$annotationReader = new AnnotationReader(); 67 | } 68 | 69 | return self::$annotationReader; 70 | } 71 | 72 | public static function registerAnnotationNamespaces() 73 | { 74 | AnnotationRegistry::registerUniqueLoader('class_exists'); 75 | } 76 | 77 | /** 78 | * Allows to ignore framework-specific annotations 79 | * @param array $annotations 80 | */ 81 | public static function addIgnoredAnnotations(array $annotations) 82 | { 83 | foreach ($annotations as $annotation) { 84 | self::getAnnotationReader()->addGlobalIgnoredName($annotation); 85 | } 86 | } 87 | 88 | /** 89 | * Remove the singleton instances. Useful in unit-testing. 90 | */ 91 | public static function tearDown() 92 | { 93 | static::$indexedReader = null; 94 | static::$annotationReader = null; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Annotation/Description.php: -------------------------------------------------------------------------------- 1 | epicNames; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Annotation/Features.php: -------------------------------------------------------------------------------- 1 | featureNames; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Annotation/Issues.php: -------------------------------------------------------------------------------- 1 | issueKeys; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Annotation/Label.php: -------------------------------------------------------------------------------- 1 | 14 | * @Required 15 | */ 16 | public $labels; 17 | } 18 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Annotation/Parameter.php: -------------------------------------------------------------------------------- 1 | 16 | * @Required 17 | */ 18 | public $parameters; 19 | } 20 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Annotation/Severity.php: -------------------------------------------------------------------------------- 1 | stories; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Annotation/TestCaseId.php: -------------------------------------------------------------------------------- 1 | testCaseIds; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Annotation/TestType.php: -------------------------------------------------------------------------------- 1 | filePathOrContents = $filePathOrContents; 27 | $this->caption = $caption; 28 | $this->type = $type; 29 | } 30 | 31 | public function process(Entity $context) 32 | { 33 | if ($context instanceof Step) { 34 | $newFileName = $this->getAttachmentFileName($this->filePathOrContents, $this->type); 35 | $attachment = new Attachment($this->caption, $newFileName, $this->type); 36 | $context->addAttachment($attachment); 37 | } 38 | } 39 | 40 | public function getAttachmentFileName($filePathOrContents, $type) 41 | { 42 | $filePath = $filePathOrContents; 43 | if (!file_exists($filePath) || !is_file($filePath)) { 44 | //Save contents to temporary file 45 | $filePath = tempnam(sys_get_temp_dir(), 'allure-attachment'); 46 | if (!file_put_contents($filePath, $filePathOrContents)) { 47 | throw new AllureException("Failed to save attachment contents to $filePath"); 48 | } 49 | } 50 | 51 | if (!isset($type)) { 52 | $type = $this->guessFileMimeType($filePath); 53 | $this->type = $type; 54 | } 55 | 56 | $fileExtension = $this->guessFileExtension($type); 57 | 58 | $fileSha1 = sha1_file($filePath); 59 | $outputPath = $this->getOutputPath($fileSha1, $fileExtension); 60 | if (!copy($filePath, $outputPath)) { 61 | throw new AllureException("Failed to copy attachment from $filePath to $outputPath."); 62 | } 63 | 64 | return $this->getOutputFileName($fileSha1, $fileExtension); 65 | } 66 | 67 | private function guessFileMimeType($filePath) 68 | { 69 | return MimeTypes::getDefault()->guessMimeType($filePath) ?? DEFAULT_MIME_TYPE; 70 | } 71 | 72 | private function guessFileExtension($mimeType) 73 | { 74 | $extensions = MimeTypes::getDefault()->getExtensions($mimeType); 75 | 76 | return $extensions[0] ?? DEFAULT_FILE_EXTENSION; 77 | } 78 | 79 | public function getOutputFileName($sha1, $extension) 80 | { 81 | return $sha1 . '-attachment.' . $extension; 82 | } 83 | 84 | public function getOutputPath($sha1, $extension) 85 | { 86 | return Provider::getOutputDirectory() . DIRECTORY_SEPARATOR . $this->getOutputFileName($sha1, $extension); 87 | } 88 | 89 | /** 90 | * @return mixed 91 | */ 92 | public function getCaption() 93 | { 94 | return $this->caption; 95 | } 96 | 97 | /** 98 | * @return mixed 99 | */ 100 | public function getFilePathOrContents() 101 | { 102 | return $this->filePathOrContents; 103 | } 104 | 105 | /** 106 | * @return mixed 107 | */ 108 | public function getType() 109 | { 110 | return $this->type; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/AddParameterEvent.php: -------------------------------------------------------------------------------- 1 | name = $name; 19 | $this->value = $value; 20 | $this->kind = $kind; 21 | } 22 | 23 | public function process(Entity $context) 24 | { 25 | if ($context instanceof TestCase) { 26 | $context->addParameter(new Parameter($this->name, $this->value, $this->kind)); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/ClearStepStorageEvent.php: -------------------------------------------------------------------------------- 1 | pattern = $pattern; 16 | } 17 | 18 | public function process(Entity $context) 19 | { 20 | if ($context instanceof Step) { 21 | foreach ($context->getAttachments() as $index => $attachment) { 22 | if ($attachment instanceof Attachment) { 23 | $path = $attachment->getSource(); 24 | if (preg_match($this->pattern, $path)) { 25 | if (file_exists($path) && is_writable($path)) { 26 | unlink($path); 27 | } 28 | $context->removeAttachment($index); 29 | } 30 | } 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/StepCanceledEvent.php: -------------------------------------------------------------------------------- 1 | setStatus(Status::CANCELED); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/StepEvent.php: -------------------------------------------------------------------------------- 1 | setStatus(Status::FAILED); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/StepFinishedEvent.php: -------------------------------------------------------------------------------- 1 | setStop(self::getTimestamp()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/StepStartedEvent.php: -------------------------------------------------------------------------------- 1 | name = $name; 21 | } 22 | 23 | public function process(Entity $context) 24 | { 25 | if ($context instanceof Step) { 26 | $context->setName($this->name); 27 | $context->setStatus(Status::PASSED); 28 | $context->setStart(self::getTimestamp()); 29 | $context->setTitle($this->title); 30 | } 31 | } 32 | 33 | public function withTitle($title) 34 | { 35 | $this->title = $title; 36 | 37 | return $this; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/Storage/StepStorage.php: -------------------------------------------------------------------------------- 1 | storage = new SplStack(); 24 | } 25 | 26 | /** 27 | * @return Step 28 | */ 29 | public function getLast() 30 | { 31 | if ($this->storage->isEmpty()) { 32 | $this->put($this->getRootStep()); 33 | } 34 | 35 | return $this->storage->top(); 36 | } 37 | 38 | /** 39 | * @return Step 40 | */ 41 | public function pollLast() 42 | { 43 | $step = $this->storage->pop(); 44 | if ($this->storage->isEmpty()) { 45 | $this->storage->push($this->getRootStep()); 46 | } 47 | 48 | return $step; 49 | } 50 | 51 | /** 52 | * @param Step $step 53 | */ 54 | public function put(Step $step) 55 | { 56 | $this->storage->push($step); 57 | } 58 | 59 | public function clear() 60 | { 61 | $this->storage = new SplStack(); 62 | $this->put($this->getRootStep()); 63 | } 64 | 65 | public function isEmpty() 66 | { 67 | return ($this->size() === 0) && $this->isRootStep($this->getLast()); 68 | } 69 | 70 | public function size() 71 | { 72 | return $this->storage->count() - 1; 73 | } 74 | 75 | public function isRootStep(Step $step) 76 | { 77 | return $step->getName() === self::ROOT_STEP_NAME; 78 | } 79 | 80 | /** 81 | * @return Step 82 | */ 83 | protected function getRootStep() 84 | { 85 | $step = new Step(); 86 | $step->setName(self::ROOT_STEP_NAME); 87 | $step->setTitle( 88 | "If you're seeing this then there's an error in step processing. " 89 | . "Please send feedback to allure@yandex-team.ru. Thank you." 90 | ); 91 | $step->setStart(self::getTimestamp()); 92 | $step->setStatus(Status::BROKEN); 93 | 94 | return $step; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/Storage/TestCaseStorage.php: -------------------------------------------------------------------------------- 1 | case)) { 20 | $this->case = new TestCase(); 21 | } 22 | 23 | return $this->case; 24 | } 25 | 26 | /** 27 | * @param TestCase $case 28 | */ 29 | public function put(TestCase $case) 30 | { 31 | $this->case = $case; 32 | } 33 | 34 | public function clear() 35 | { 36 | unset($this->case); 37 | } 38 | 39 | public function isEmpty() 40 | { 41 | return !isset($this->case); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/Storage/TestSuiteStorage.php: -------------------------------------------------------------------------------- 1 | clear(); 17 | } 18 | 19 | /** 20 | * @param string $uuid 21 | * @return TestSuite 22 | */ 23 | public function get($uuid) 24 | { 25 | if (!array_key_exists($uuid, $this->storage)) { 26 | $this->storage[$uuid] = new TestSuite(); 27 | } 28 | 29 | return $this->storage[$uuid]; 30 | } 31 | 32 | public function remove($uuid) 33 | { 34 | if (array_key_exists($uuid, $this->storage)) { 35 | unset($this->storage[$uuid]); 36 | } 37 | } 38 | 39 | public function clear() 40 | { 41 | $this->storage = []; 42 | } 43 | 44 | public function isEmpty() 45 | { 46 | return $this->size() === 0; 47 | } 48 | 49 | public function size() 50 | { 51 | return sizeof($this->storage); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/TestCaseBrokenEvent.php: -------------------------------------------------------------------------------- 1 | setStop(self::getTimestamp()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/TestCasePendingEvent.php: -------------------------------------------------------------------------------- 1 | suiteUuid = $suiteUuid; 48 | $this->name = $name; 49 | $this->labels = []; 50 | $this->parameters = []; 51 | } 52 | 53 | public function process(Entity $context) 54 | { 55 | if ($context instanceof TestCase) { 56 | $context->setName($this->getName()); 57 | $context->setStatus(Status::PASSED); 58 | $context->setStart(self::getTimestamp()); 59 | $context->setTitle($this->getTitle()); 60 | $description = $this->getDescription(); 61 | if (isset($description)) { 62 | $context->setDescription($description); 63 | } 64 | foreach ($this->getLabels() as $label) { 65 | $context->addLabel($label); 66 | } 67 | foreach ($this->getParameters() as $parameter) { 68 | $context->addParameter($parameter); 69 | } 70 | } 71 | } 72 | 73 | /** 74 | * @param string $title 75 | * @return $this 76 | */ 77 | public function withTitle($title) 78 | { 79 | $this->setTitle($title); 80 | 81 | return $this; 82 | } 83 | 84 | /** 85 | * @param Description $description 86 | * @return $this 87 | */ 88 | public function withDescription(Description $description) 89 | { 90 | $this->setDescription($description); 91 | 92 | return $this; 93 | } 94 | 95 | /** 96 | * @param array $labels 97 | * @return $this 98 | */ 99 | public function withLabels(array $labels) 100 | { 101 | $this->setLabels($labels); 102 | 103 | return $this; 104 | } 105 | 106 | /** 107 | * @param array $parameters 108 | * @return $this 109 | */ 110 | public function withParameters(array $parameters) 111 | { 112 | $this->setParameters($parameters); 113 | 114 | return $this; 115 | } 116 | 117 | /** 118 | * @return string 119 | */ 120 | public function getSuiteUuid() 121 | { 122 | return $this->suiteUuid; 123 | } 124 | 125 | /** 126 | * @param \Yandex\Allure\Adapter\Model\Description $description 127 | */ 128 | public function setDescription($description) 129 | { 130 | $this->description = $description; 131 | } 132 | 133 | /** 134 | * @param array $labels 135 | */ 136 | public function setLabels(array $labels) 137 | { 138 | $this->labels = $labels; 139 | } 140 | 141 | /** 142 | * @param string $title 143 | */ 144 | public function setTitle($title) 145 | { 146 | $this->title = $title; 147 | } 148 | 149 | /** 150 | * @param array $parameters 151 | */ 152 | public function setParameters($parameters) 153 | { 154 | $this->parameters = $parameters; 155 | } 156 | 157 | /** 158 | * @return \Yandex\Allure\Adapter\Model\Description 159 | */ 160 | public function getDescription() 161 | { 162 | return $this->description; 163 | } 164 | 165 | /** 166 | * @return array 167 | */ 168 | public function getLabels() 169 | { 170 | return $this->labels; 171 | } 172 | 173 | /** 174 | * @return array 175 | */ 176 | public function getParameters() 177 | { 178 | return $this->parameters; 179 | } 180 | 181 | /** 182 | * @return string 183 | */ 184 | public function getTitle() 185 | { 186 | return $this->title; 187 | } 188 | 189 | /** 190 | * @return string 191 | */ 192 | public function getName() 193 | { 194 | return $this->name; 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/TestCaseStatusChangedEvent.php: -------------------------------------------------------------------------------- 1 | setStatus($this->getStatus()); 31 | $exception = $this->exception; 32 | if (isset($exception)) { 33 | $failure = new Failure($this->message); 34 | $failure->setStackTrace($exception->getTraceAsString()); 35 | $context->setFailure($failure); 36 | } 37 | } 38 | } 39 | 40 | /** 41 | * @param string $message 42 | * @return $this 43 | */ 44 | public function withMessage($message) 45 | { 46 | $this->message = $message; 47 | 48 | return $this; 49 | } 50 | 51 | /** 52 | * @param Throwable $exception 53 | * @return $this 54 | */ 55 | public function withException(Throwable $exception) 56 | { 57 | $this->exception = $exception; 58 | 59 | return $this; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/TestSuiteEvent.php: -------------------------------------------------------------------------------- 1 | uuid = $uuid; 21 | } 22 | 23 | public function process(Entity $context) 24 | { 25 | if ($context instanceof TestSuite) { 26 | $context->setStop(self::getTimestamp()); 27 | } 28 | } 29 | 30 | public function getUuid() 31 | { 32 | return $this->uuid; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Event/TestSuiteStartedEvent.php: -------------------------------------------------------------------------------- 1 | name = $name; 42 | $this->labels = []; 43 | } 44 | 45 | public function process(Entity $context) 46 | { 47 | if ($context instanceof TestSuite) { 48 | $context->setName($this->getName()); 49 | $context->setStart(self::getTimestamp()); 50 | $context->setTitle($this->getTitle()); 51 | $description = $this->getDescription(); 52 | if (isset($description)) { 53 | $context->setDescription($this->getDescription()); 54 | } 55 | foreach ($this->getLabels() as $label) { 56 | $context->addLabel($label); 57 | } 58 | } 59 | } 60 | 61 | /** 62 | * @param string $title 63 | * @return $this 64 | */ 65 | public function withTitle($title) 66 | { 67 | $this->setTitle($title); 68 | 69 | return $this; 70 | } 71 | 72 | /** 73 | * @param Description $description 74 | * @return $this 75 | */ 76 | public function withDescription(Description $description) 77 | { 78 | $this->setDescription($description); 79 | 80 | return $this; 81 | } 82 | 83 | /** 84 | * @param array $labels 85 | * @return $this 86 | */ 87 | public function withLabels(array $labels) 88 | { 89 | $this->setLabels($labels); 90 | 91 | return $this; 92 | } 93 | 94 | /** 95 | * @param \Yandex\Allure\Adapter\Model\Description $description 96 | */ 97 | public function setDescription($description) 98 | { 99 | $this->description = $description; 100 | } 101 | 102 | /** 103 | * @param array $labels 104 | */ 105 | public function setLabels($labels) 106 | { 107 | $this->labels = $labels; 108 | } 109 | 110 | /** 111 | * @param string $name 112 | */ 113 | public function setName($name) 114 | { 115 | $this->name = $name; 116 | } 117 | 118 | /** 119 | * @param string $title 120 | */ 121 | public function setTitle($title) 122 | { 123 | $this->title = $title; 124 | } 125 | 126 | /** 127 | * @return \Yandex\Allure\Adapter\Model\Description 128 | */ 129 | public function getDescription() 130 | { 131 | return $this->description; 132 | } 133 | 134 | /** 135 | * @return array 136 | */ 137 | public function getLabels() 138 | { 139 | return $this->labels; 140 | } 141 | 142 | /** 143 | * @return string 144 | */ 145 | public function getName() 146 | { 147 | return $this->name; 148 | } 149 | 150 | /** 151 | * @return string 152 | */ 153 | public function getTitle() 154 | { 155 | return $this->title; 156 | } 157 | 158 | public function getUuid() 159 | { 160 | if (!isset($this->uuid)) { 161 | $this->uuid = self::generateUUID(); 162 | } 163 | 164 | return $this->uuid; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Model/Attachment.php: -------------------------------------------------------------------------------- 1 | source = $source; 38 | $this->title = $title; 39 | $this->type = $type; 40 | } 41 | 42 | /** 43 | * @return string 44 | */ 45 | public function getSource() 46 | { 47 | return $this->source; 48 | } 49 | 50 | /** 51 | * @return string 52 | */ 53 | public function getTitle() 54 | { 55 | return $this->title; 56 | } 57 | 58 | /** 59 | * @return string 60 | */ 61 | public function getType() 62 | { 63 | return $this->type; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Model/ConstantChecker.php: -------------------------------------------------------------------------------- 1 | getConstants() as $constantValue) { 25 | if ($constantValue === $value) { 26 | return $value; 27 | } 28 | } 29 | throw new AllureException( 30 | "Value \"$value\" is not present in class $className. You should use a constant from this class." 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Model/Description.php: -------------------------------------------------------------------------------- 1 | type = ConstantChecker::validate('Yandex\Allure\Adapter\Model\DescriptionType', $type); 32 | $this->value = $value; 33 | } 34 | 35 | /** 36 | * @return string 37 | */ 38 | public function getType() 39 | { 40 | return $this->type; 41 | } 42 | 43 | /** 44 | * @return string 45 | */ 46 | public function getValue() 47 | { 48 | return $this->value; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Model/DescriptionType.php: -------------------------------------------------------------------------------- 1 | message = $message; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function getMessage() 35 | { 36 | return $this->message; 37 | } 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function getStackTrace() 43 | { 44 | return $this->stackTrace; 45 | } 46 | 47 | /** 48 | * @param string $stackTrace 49 | */ 50 | public function setStackTrace($stackTrace) 51 | { 52 | $this->stackTrace = $stackTrace; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Model/Label.php: -------------------------------------------------------------------------------- 1 | name = $name; 33 | $this->value = $value; 34 | } 35 | 36 | /** 37 | * @return string 38 | */ 39 | public function getName() 40 | { 41 | return $this->name; 42 | } 43 | 44 | /** 45 | * @return string 46 | */ 47 | public function getValue() 48 | { 49 | return $this->value; 50 | } 51 | 52 | /** 53 | * @param $id 54 | * @return Label 55 | */ 56 | public static function id($id) 57 | { 58 | return new Label(LabelType::ID, $id); 59 | } 60 | 61 | /** 62 | * @param $epicName 63 | * @return Label 64 | */ 65 | public static function epic($epicName) 66 | { 67 | return new Label(LabelType::EPIC, $epicName); 68 | } 69 | 70 | /** 71 | * @param $featureName 72 | * @return Label 73 | */ 74 | public static function feature($featureName) 75 | { 76 | return new Label(LabelType::FEATURE, $featureName); 77 | } 78 | 79 | /** 80 | * @param $storyName 81 | * @return Label 82 | */ 83 | public static function story($storyName) 84 | { 85 | return new Label(LabelType::STORY, $storyName); 86 | } 87 | 88 | /** 89 | * @param $severityLevel 90 | * @return Label 91 | */ 92 | public static function severity($severityLevel) 93 | { 94 | return new Label(LabelType::SEVERITY, $severityLevel); 95 | } 96 | 97 | /** 98 | * @param $testType 99 | * @return Label 100 | */ 101 | public static function testType($testType) 102 | { 103 | return new Label(LabelType::TEST_TYPE, $testType); 104 | } 105 | 106 | /** 107 | * @param $issueKey 108 | * @return Label 109 | */ 110 | public static function issue($issueKey) 111 | { 112 | return new Label(LabelType::ISSUE, $issueKey); 113 | } 114 | 115 | /** 116 | * @param $testCaseId 117 | * 118 | * @return Label 119 | */ 120 | public static function testId($testCaseId) 121 | { 122 | return new Label(LabelType::TEST_ID, $testCaseId); 123 | } 124 | 125 | /** 126 | * @param $name 127 | * @param $value 128 | * 129 | * @return Label 130 | */ 131 | public static function label($name, $value) 132 | { 133 | return new Label($name, $value); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Model/LabelType.php: -------------------------------------------------------------------------------- 1 | kind = ConstantChecker::validate('Yandex\Allure\Adapter\Model\ParameterKind', $kind); 35 | $this->name = $name; 36 | $this->value = $value; 37 | } 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function getKind() 43 | { 44 | return $this->kind; 45 | } 46 | 47 | /** 48 | * @return string 49 | */ 50 | public function getName() 51 | { 52 | return $this->name; 53 | } 54 | 55 | /** 56 | * @return string 57 | */ 58 | public function getValue() 59 | { 60 | return $this->value; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Model/ParameterKind.php: -------------------------------------------------------------------------------- 1 | ") 44 | * @XmlList(entry = "step") 45 | */ 46 | private $steps; 47 | 48 | /** 49 | * @var array 50 | * @Type("array") 51 | * @XmlList(entry = "attachment") 52 | */ 53 | private $attachments; 54 | 55 | /** 56 | * @var Status 57 | * @Type("string") 58 | * @XmlAttribute 59 | */ 60 | private $status; 61 | 62 | public function __construct() 63 | { 64 | $this->steps = []; 65 | $this->attachments = []; 66 | } 67 | 68 | /** 69 | * @param string $name 70 | */ 71 | public function setName($name) 72 | { 73 | $this->name = $name; 74 | } 75 | 76 | /** 77 | * @param int $start 78 | */ 79 | public function setStart($start) 80 | { 81 | $this->start = $start; 82 | } 83 | 84 | /** 85 | * @param int $stop 86 | */ 87 | public function setStop($stop) 88 | { 89 | $this->stop = $stop; 90 | } 91 | 92 | /** 93 | * @param string $status 94 | */ 95 | public function setStatus($status) 96 | { 97 | $this->status = ConstantChecker::validate('Yandex\Allure\Adapter\Model\Status', $status); 98 | } 99 | 100 | /** 101 | * @return array 102 | */ 103 | public function getAttachments() 104 | { 105 | return $this->attachments; 106 | } 107 | 108 | /** 109 | * @return string 110 | */ 111 | public function getName() 112 | { 113 | return $this->name; 114 | } 115 | 116 | /** 117 | * @return int 118 | */ 119 | public function getStart() 120 | { 121 | return $this->start; 122 | } 123 | 124 | /** 125 | * @return array 126 | */ 127 | public function getSteps() 128 | { 129 | return $this->steps; 130 | } 131 | 132 | /** 133 | * @return int 134 | */ 135 | public function getStop() 136 | { 137 | return $this->stop; 138 | } 139 | 140 | /** 141 | * @return string 142 | */ 143 | public function getTitle() 144 | { 145 | return $this->title; 146 | } 147 | 148 | /** 149 | * @return string 150 | */ 151 | public function getStatus() 152 | { 153 | return $this->status; 154 | } 155 | 156 | /** 157 | * @param string $title 158 | */ 159 | public function setTitle($title) 160 | { 161 | $this->title = $title; 162 | } 163 | 164 | /** 165 | * @param \Yandex\Allure\Adapter\Model\Step $step 166 | */ 167 | public function addStep(Step $step) 168 | { 169 | $this->steps[] = $step; 170 | } 171 | 172 | /** 173 | * @param \Yandex\Allure\Adapter\Model\Attachment $attachment 174 | */ 175 | public function addAttachment(Attachment $attachment) 176 | { 177 | $this->attachments[] = $attachment; 178 | } 179 | 180 | /** 181 | * @param $index 182 | */ 183 | public function removeAttachment($index) 184 | { 185 | if (isset($this->attachments[$index])) { 186 | unset($this->attachments[$index]); 187 | } 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Model/TestCase.php: -------------------------------------------------------------------------------- 1 | ") 68 | * @XmlList(entry = "step") 69 | */ 70 | private $steps; 71 | 72 | /** 73 | * @var array 74 | * @Type("array") 75 | * @XmlList(entry = "attachment") 76 | */ 77 | private $attachments; 78 | 79 | /** 80 | * @Type("array") 81 | * @XmlList(entry = "label") 82 | */ 83 | private $labels; 84 | 85 | /** 86 | * @var array 87 | * @Type("array") 88 | * @XmlList(entry = "parameter") 89 | */ 90 | private $parameters; 91 | 92 | public function __construct() 93 | { 94 | $this->steps = []; 95 | $this->labels = []; 96 | $this->attachments = []; 97 | $this->parameters = []; 98 | } 99 | 100 | /** 101 | * @return array 102 | */ 103 | public function getAttachments() 104 | { 105 | return $this->attachments; 106 | } 107 | 108 | /** 109 | * @return array 110 | */ 111 | public function getLabels() 112 | { 113 | return $this->labels; 114 | } 115 | 116 | /** 117 | * @return string 118 | */ 119 | public function getName() 120 | { 121 | return $this->name; 122 | } 123 | 124 | /** 125 | * @return array 126 | */ 127 | public function getSteps() 128 | { 129 | return $this->steps; 130 | } 131 | 132 | /** 133 | * @return string 134 | */ 135 | public function getTitle() 136 | { 137 | return $this->title; 138 | } 139 | 140 | /** 141 | * @return int 142 | */ 143 | public function getStart() 144 | { 145 | return $this->start; 146 | } 147 | 148 | /** 149 | * @return int 150 | */ 151 | public function getStop() 152 | { 153 | return $this->stop; 154 | } 155 | 156 | /** 157 | * @return string 158 | */ 159 | public function getStatus() 160 | { 161 | return $this->status; 162 | } 163 | 164 | /** 165 | * @return \Yandex\Allure\Adapter\Model\Description 166 | */ 167 | public function getDescription() 168 | { 169 | return $this->description; 170 | } 171 | 172 | /** 173 | * @return \Yandex\Allure\Adapter\Model\Failure 174 | */ 175 | public function getFailure() 176 | { 177 | return $this->failure; 178 | } 179 | 180 | /** 181 | * @return array 182 | */ 183 | public function getParameters() 184 | { 185 | return $this->parameters; 186 | } 187 | 188 | /** 189 | * @param string $name 190 | */ 191 | public function setName($name) 192 | { 193 | $this->name = $name; 194 | } 195 | 196 | /** 197 | * @param int $start 198 | */ 199 | public function setStart($start) 200 | { 201 | $this->start = $start; 202 | } 203 | 204 | /** 205 | * @param int $stop 206 | */ 207 | public function setStop($stop) 208 | { 209 | $this->stop = $stop; 210 | } 211 | 212 | /** 213 | * @param string $status 214 | */ 215 | public function setStatus($status) 216 | { 217 | $this->status = ConstantChecker::validate('Yandex\Allure\Adapter\Model\Status', $status); 218 | } 219 | 220 | /** 221 | * @param \Yandex\Allure\Adapter\Model\Description $description 222 | */ 223 | public function setDescription($description) 224 | { 225 | $this->description = $description; 226 | } 227 | 228 | /** 229 | * @param \Yandex\Allure\Adapter\Model\Failure $failure 230 | */ 231 | public function setFailure($failure) 232 | { 233 | $this->failure = $failure; 234 | } 235 | 236 | /** 237 | * @param string $title 238 | */ 239 | public function setTitle($title) 240 | { 241 | $this->title = $title; 242 | } 243 | 244 | /** 245 | * @param \Yandex\Allure\Adapter\Model\Label $label 246 | */ 247 | public function addLabel(Label $label) 248 | { 249 | $this->labels[] = $label; 250 | } 251 | 252 | /** 253 | * @param \Yandex\Allure\Adapter\Model\Step $step 254 | */ 255 | public function addStep(Step $step) 256 | { 257 | $this->steps[] = $step; 258 | } 259 | 260 | /** 261 | * @param \Yandex\Allure\Adapter\Model\Attachment $attachment 262 | */ 263 | public function addAttachment(Attachment $attachment) 264 | { 265 | $this->attachments[] = $attachment; 266 | } 267 | 268 | /** 269 | * @param \Yandex\Allure\Adapter\Model\Parameter $parameter 270 | */ 271 | public function addParameter(Parameter $parameter) 272 | { 273 | $this->parameters[] = $parameter; 274 | } 275 | } 276 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Model/TestSuite.php: -------------------------------------------------------------------------------- 1 | ") 72 | * @XmlList(entry = "test-case") 73 | * @SerializedName("test-cases") 74 | */ 75 | private $testCases; 76 | 77 | /** 78 | * @var array 79 | * @Type("array") 80 | * @XmlList(entry = "label") 81 | */ 82 | private $labels; 83 | 84 | /** 85 | * @var Serializer 86 | * @Exclude 87 | */ 88 | private $serializer; 89 | 90 | /** 91 | * @var TestCase 92 | * @Type("Yandex\Allure\Adapter\Model\TestCase") 93 | * @Exclude 94 | */ 95 | private $currentTestCase; 96 | 97 | public function __construct() 98 | { 99 | $this->testCases = []; 100 | $this->labels = []; 101 | $this->version = self::DEFAULT_VERSION; 102 | } 103 | 104 | /** 105 | * @return Description 106 | */ 107 | public function getDescription() 108 | { 109 | return $this->description; 110 | } 111 | 112 | /** 113 | * @return array 114 | */ 115 | public function getLabels() 116 | { 117 | return $this->labels; 118 | } 119 | 120 | /** 121 | * @return string 122 | */ 123 | public function getName() 124 | { 125 | return $this->name; 126 | } 127 | 128 | /** 129 | * @return int 130 | */ 131 | public function getStart() 132 | { 133 | return $this->start; 134 | } 135 | 136 | /** 137 | * @return int 138 | */ 139 | public function getStop() 140 | { 141 | return $this->stop; 142 | } 143 | 144 | /** 145 | * @return string 146 | */ 147 | public function getVersion() 148 | { 149 | return $this->version; 150 | } 151 | 152 | /** 153 | * @return int 154 | */ 155 | public function getTitle() 156 | { 157 | return $this->title; 158 | } 159 | 160 | /** 161 | * @param int $start 162 | */ 163 | public function setStart($start) 164 | { 165 | $this->start = $start; 166 | } 167 | 168 | /** 169 | * @param string $name 170 | */ 171 | public function setName($name) 172 | { 173 | $this->name = $name; 174 | } 175 | 176 | /** 177 | * @param string $title 178 | */ 179 | public function setTitle($title) 180 | { 181 | $this->title = $title; 182 | } 183 | 184 | /** 185 | * @param int $stop 186 | */ 187 | public function setStop($stop) 188 | { 189 | $this->stop = $stop; 190 | } 191 | 192 | /** 193 | * @param string $version 194 | */ 195 | public function setVersion($version) 196 | { 197 | $this->version = $version; 198 | } 199 | 200 | /** 201 | * @param \Yandex\Allure\Adapter\Model\Description $description 202 | */ 203 | public function setDescription(Description $description) 204 | { 205 | $this->description = $description; 206 | } 207 | 208 | /** 209 | * @param \Yandex\Allure\Adapter\Model\TestCase $testCase 210 | */ 211 | public function addTestCase(TestCase $testCase) 212 | { 213 | $this->testCases[$testCase->getName()] = $testCase; 214 | } 215 | 216 | /** 217 | * Returns test case by name 218 | * @param string $name 219 | * @return \Yandex\Allure\Adapter\Model\TestCase 220 | */ 221 | public function getTestCase($name) 222 | { 223 | return $this->testCases[$name]; 224 | } 225 | 226 | /** 227 | * Return total count of child elements (test cases or test suites) 228 | * @return int 229 | */ 230 | public function size() 231 | { 232 | return count($this->testCases); 233 | } 234 | 235 | /** 236 | * @param \Yandex\Allure\Adapter\Model\Label $label 237 | */ 238 | public function addLabel(Label $label) 239 | { 240 | $this->labels[] = $label; 241 | } 242 | 243 | /** 244 | * @return string 245 | */ 246 | public function serialize() 247 | { 248 | return $this->getSerializer()->serialize($this, 'xml'); 249 | } 250 | 251 | /** 252 | * @param string $serialized 253 | * @return mixed 254 | */ 255 | public function unserialize($serialized) 256 | { 257 | return $this->getSerializer()->deserialize($serialized, \Yandex\Allure\Adapter\Model\TestSuite::class, 'xml'); 258 | } 259 | 260 | /** 261 | + * @return string 262 | + */ 263 | public function __serialize() 264 | { 265 | return $this->getSerializer()->serialize($this, 'xml'); 266 | } 267 | 268 | /** 269 | + * @param string $serialized 270 | + * @return mixed 271 | + */ 272 | public function __unserialize($serialized) 273 | { 274 | return $this->getSerializer()->deserialize($serialized, \Yandex\Allure\Adapter\Model\TestSuite::class, 'xml'); 275 | } 276 | 277 | /** 278 | * @return Serializer 279 | */ 280 | private function getSerializer() 281 | { 282 | if (!isset($this->serializer)) { 283 | $this->serializer = SerializerBuilder::create()->build(); 284 | } 285 | 286 | return $this->serializer; 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Support/AttachmentSupport.php: -------------------------------------------------------------------------------- 1 | fire(new AddAttachmentEvent($filePathOrContents, $caption, $type)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Support/StepSupport.php: -------------------------------------------------------------------------------- 1 | withTitle($title); 42 | } else { 43 | $event->withTitle($name); 44 | } 45 | Allure::lifecycle()->fire($event); 46 | try { 47 | $logicResult = $logic(); 48 | Allure::lifecycle()->fire(new StepFinishedEvent()); 49 | } catch (Exception $e) { 50 | $stepFailedEvent = new StepFailedEvent(); 51 | Allure::lifecycle()->fire($stepFailedEvent); 52 | Allure::lifecycle()->fire(new StepFinishedEvent()); 53 | throw $e; 54 | } 55 | } else { 56 | throw new AllureException("Step name shouldn't be null and logic should be a callable."); 57 | } 58 | 59 | return $logicResult; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Yandex/Allure/Adapter/Support/Utils.php: -------------------------------------------------------------------------------- 1 | toString(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/AllureTest.php: -------------------------------------------------------------------------------- 1 | getStepStorage()->clear(); 35 | Allure::lifecycle()->getStepStorage()->put(new Step()); 36 | Allure::lifecycle()->fire(new ClearStepStorageEvent()); 37 | $this->assertTrue(Allure::lifecycle()->getStepStorage()->isEmpty()); 38 | } 39 | 40 | public function testTestCaseStorageClear() 41 | { 42 | Allure::lifecycle()->getTestCaseStorage()->clear(); 43 | Allure::lifecycle()->getTestCaseStorage()->put(new TestCase()); 44 | Allure::lifecycle()->fire(new ClearTestCaseStorageEvent()); 45 | $this->assertTrue(Allure::lifecycle()->getTestCaseStorage()->isEmpty()); 46 | } 47 | 48 | public function testStepStartedEvent() 49 | { 50 | Allure::lifecycle()->getStepStorage()->clear(); 51 | $this->assertTrue(Allure::lifecycle()->getStepStorage()->isEmpty()); 52 | Allure::lifecycle()->fire(new StepStartedEvent(self::STEP_NAME)); 53 | $this->assertEquals(1, Allure::lifecycle()->getStepStorage()->size()); 54 | $step = Allure::lifecycle()->getStepStorage()->getLast(); 55 | $this->assertEquals(self::STEP_NAME, $step->getName()); 56 | } 57 | 58 | public function testStepFinishedEvent() 59 | { 60 | $step = new Step(); 61 | $step->setName(self::STEP_NAME); 62 | Allure::lifecycle()->getStepStorage()->put($step); 63 | Allure::lifecycle()->fire(new StepFinishedEvent()); 64 | $step = Allure::lifecycle()->getStepStorage()->getLast(); 65 | $this->assertEquals(self::STEP_NAME, $step->getName()); 66 | } 67 | 68 | public function testGenericStepEvent() 69 | { 70 | $step = new Step(); 71 | Allure::lifecycle()->getStepStorage()->clear(); 72 | Allure::lifecycle()->getStepStorage()->put($step); 73 | Allure::lifecycle()->fire(new GenericStepEvent(self::STEP_NAME)); 74 | $this->assertEquals(self::STEP_NAME, $step->getName()); 75 | } 76 | 77 | public function testTestCaseStarted() 78 | { 79 | Allure::lifecycle()->getTestCaseStorage()->clear(); 80 | Allure::lifecycle()->getTestSuiteStorage()->clear(); 81 | $this->assertTrue(Allure::lifecycle()->getTestCaseStorage()->isEmpty()); 82 | Allure::lifecycle()->fire(new TestCaseStartedEvent(self::TEST_SUITE_UUID, self::TEST_CASE_NAME)); 83 | $testCase = Allure::lifecycle() 84 | ->getTestSuiteStorage() 85 | ->get(self::TEST_SUITE_UUID) 86 | ->getTestCase(self::TEST_CASE_NAME); 87 | $this->assertNotEmpty($testCase); 88 | $this->assertEquals(self::TEST_CASE_NAME, $testCase->getName()); 89 | } 90 | 91 | public function testTestCaseFinishedEvent() 92 | { 93 | Allure::lifecycle()->getStepStorage()->clear(); 94 | Allure::lifecycle()->getStepStorage()->getLast(); //To initialize root step 95 | Allure::lifecycle()->getTestCaseStorage()->clear(); 96 | $step = new Step(); 97 | $step->setName(self::STEP_NAME); 98 | $attachment = new Attachment( 99 | self::STEP_ATTACHMENT_TITLE, 100 | self::STEP_ATTACHMENT_SOURCE, 101 | self::STEP_ATTACHMENT_TYPE 102 | ); 103 | Allure::lifecycle()->getStepStorage()->getLast()->addStep($step); 104 | Allure::lifecycle()->getStepStorage()->getLast()->addAttachment($attachment); 105 | 106 | $testCaseFromStorage = Allure::lifecycle()->getTestCaseStorage()->get(); 107 | 108 | Allure::lifecycle()->fire(new TestCaseFinishedEvent()); 109 | 110 | //Checking that attachments were moved 111 | $attachments = $testCaseFromStorage->getAttachments(); 112 | $this->assertEquals(1, sizeof($attachments)); 113 | $attachment = array_pop($attachments); 114 | $this->assertTrue( 115 | ($attachment instanceof Attachment) && 116 | ($attachment->getTitle() === self::STEP_ATTACHMENT_TITLE) && 117 | ($attachment->getSource() === self::STEP_ATTACHMENT_SOURCE) && 118 | ($attachment->getType() === self::STEP_ATTACHMENT_TYPE) 119 | ); 120 | 121 | //Checking that steps were moved 122 | $steps = $testCaseFromStorage->getSteps(); 123 | $this->assertEquals(1, sizeof($steps)); 124 | $stepFromStorage = array_pop($steps); 125 | $this->assertTrue( 126 | ($stepFromStorage instanceof Step) && 127 | ($stepFromStorage->getName() === self::STEP_NAME) 128 | ); 129 | $this->assertTrue(Allure::lifecycle()->getTestCaseStorage()->isEmpty()); 130 | } 131 | 132 | public function testGenericTestCaseEvent() 133 | { 134 | $testCase = new TestCase(); 135 | Allure::lifecycle()->getTestCaseStorage()->clear(); 136 | Allure::lifecycle()->getTestCaseStorage()->put($testCase); 137 | Allure::lifecycle()->fire(new GenericTestCaseEvent(self::TEST_CASE_NAME)); 138 | $this->assertEquals(self::TEST_CASE_NAME, $testCase->getName()); 139 | } 140 | 141 | public function testGenericTestSuiteEvent() 142 | { 143 | Allure::lifecycle()->getTestSuiteStorage()->clear(); 144 | $event = new GenericTestSuiteEvent(self::TEST_SUITE_NAME); 145 | $testSuite = Allure::lifecycle()->getTestSuiteStorage()->get($event->getUuid()); 146 | Allure::lifecycle()->fire($event); 147 | $this->assertEquals(self::TEST_SUITE_NAME, $testSuite->getName()); 148 | } 149 | 150 | public function testTestSuiteFinishedEvent() 151 | { 152 | Allure::lifecycle()->getTestSuiteStorage()->clear(); 153 | $testSuite = Allure::lifecycle()->getTestSuiteStorage()->get(self::TEST_SUITE_UUID); 154 | $testSuite->addTestCase(new TestCase()); 155 | 156 | $this->assertEquals(1, Allure::lifecycle()->getTestSuiteStorage()->size()); 157 | 158 | $outputDirectory = sys_get_temp_dir(); 159 | AnnotationRegistry::registerAutoloadNamespace( 160 | 'JMS\Serializer\Annotation', 161 | __DIR__ . "/../../../../vendor/jms/serializer/src" 162 | ); 163 | 164 | Provider::setOutputDirectory($outputDirectory); 165 | $xmlFilePath = $outputDirectory . DIRECTORY_SEPARATOR . self::TEST_SUITE_UUID . '-testsuite.xml'; 166 | 167 | Allure::lifecycle()->fire(new TestSuiteFinishedEvent(self::TEST_SUITE_UUID)); 168 | $this->assertTrue(Allure::lifecycle()->getTestSuiteStorage()->isEmpty()); 169 | $this->assertTrue(file_exists($xmlFilePath)); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Annotation/AnnotationManagerTest.php: -------------------------------------------------------------------------------- 1 | updateTestSuiteEvent($event); 23 | 24 | $this->assertEquals('test-suite-title', $event->getTitle()); 25 | $this->assertEquals('test-suite-description', $event->getDescription()->getValue()); 26 | $this->assertEquals(DescriptionType::MARKDOWN, $event->getDescription()->getType()); 27 | $this->assertEquals(8, sizeof($event->getLabels())); 28 | 29 | //Check features presence 30 | $epics = $this->getLabelsByType($event->getLabels(), LabelType::EPIC); 31 | $this->assertEquals(2, sizeof($epics)); 32 | $index = 1; 33 | foreach ($epics as $epic) { 34 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $epic); 35 | $this->assertEquals("test-suite-epic$index", $epic->getValue()); 36 | $index++; 37 | } 38 | 39 | //Check features presence 40 | $features = $this->getLabelsByType($event->getLabels(), LabelType::FEATURE); 41 | $this->assertEquals(2, sizeof($features)); 42 | $index = 1; 43 | foreach ($features as $feature) { 44 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $feature); 45 | $this->assertEquals("test-suite-feature$index", $feature->getValue()); 46 | $index++; 47 | } 48 | 49 | //Check stories presence 50 | $stories = $this->getLabelsByType($event->getLabels(), LabelType::STORY); 51 | $this->assertEquals(2, sizeof($stories)); 52 | $index = 1; 53 | foreach ($stories as $story) { 54 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $story); 55 | $this->assertEquals("test-suite-story$index", $story->getValue()); 56 | $index++; 57 | } 58 | 59 | //Check issues presence 60 | $issues = $this->getLabelsByType($event->getLabels(), LabelType::ISSUE); 61 | $this->assertEquals(2, sizeof($issues)); 62 | $index = 1; 63 | foreach ($issues as $issue) { 64 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $issue); 65 | $this->assertEquals("test-suite-issue$index", $issue->getValue()); 66 | $index++; 67 | } 68 | 69 | } 70 | 71 | public function testUpdateTestCaseStartedEvent(): void 72 | { 73 | $instance = new Fixtures\ExampleTestSuite(); 74 | $testCaseAnnotations = AnnotationProvider::getMethodAnnotations($instance, 'exampleTestCase'); 75 | $annotationManager = new AnnotationManager($testCaseAnnotations); 76 | $event = new TestCaseStartedEvent('some-uid', 'some-name'); 77 | $annotationManager->updateTestCaseEvent($event); 78 | 79 | //Check scalar properties 80 | $this->assertEquals('test-case-title', $event->getTitle()); 81 | $this->assertEquals('test-case-description', $event->getDescription()->getValue()); 82 | $this->assertEquals(DescriptionType::HTML, $event->getDescription()->getType()); 83 | $this->assertEquals(13, sizeof($event->getLabels())); 84 | 85 | //Check id presence 86 | $ids = $this->getLabelsByType($event->getLabels(), LabelType::ID); 87 | $this->assertEquals(1, sizeof($ids)); 88 | $id = array_pop($ids); 89 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $id); 90 | $this->assertSame("123", $id->getValue()); 91 | 92 | //Check epic presence 93 | $epics = $this->getLabelsByType($event->getLabels(), LabelType::EPIC); 94 | $this->assertEquals(2, sizeof($epics)); 95 | $index = 1; 96 | foreach ($epics as $epic) { 97 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $epic); 98 | $this->assertEquals("test-case-epic$index", $epic->getValue()); 99 | $index++; 100 | } 101 | 102 | //Check feature presence 103 | $features = $this->getLabelsByType($event->getLabels(), LabelType::FEATURE); 104 | $this->assertEquals(2, sizeof($features)); 105 | $index = 1; 106 | foreach ($features as $feature) { 107 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $feature); 108 | $this->assertEquals("test-case-feature$index", $feature->getValue()); 109 | $index++; 110 | } 111 | 112 | //Check stories presence 113 | $stories = $this->getLabelsByType($event->getLabels(), LabelType::STORY); 114 | $this->assertEquals(2, sizeof($stories)); 115 | $index = 1; 116 | foreach ($stories as $story) { 117 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $story); 118 | $this->assertEquals("test-case-story$index", $story->getValue()); 119 | $index++; 120 | } 121 | 122 | //Check issues presence 123 | $issues = $this->getLabelsByType($event->getLabels(), LabelType::ISSUE); 124 | $this->assertEquals(2, sizeof($issues)); 125 | $index = 1; 126 | foreach ($issues as $issue) { 127 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $issue); 128 | $this->assertEquals("test-case-issue$index", $issue->getValue()); 129 | $index++; 130 | } 131 | 132 | //Check custom labels presence 133 | $customs = $this->getLabelsByType($event->getLabels(), "custom-name"); 134 | $this->assertEquals(3, sizeof($customs)); 135 | $index = 1; 136 | foreach ($customs as $custom) { 137 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $custom); 138 | $this->assertEquals("custom-value-$index", $custom->getValue()); 139 | $index++; 140 | } 141 | 142 | //Check severity presence 143 | $severities = $this->getLabelsByType($event->getLabels(), LabelType::SEVERITY); 144 | $this->assertEquals(1, sizeof($severities)); 145 | $severity = array_pop($severities); 146 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $severity); 147 | $this->assertSame(SeverityLevel::BLOCKER, $severity->getValue()); 148 | 149 | //Check parameter presence 150 | $parameters = $event->getParameters(); 151 | $this->assertEquals(1, sizeof($parameters)); 152 | $parameter = array_pop($parameters); 153 | 154 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Parameter', $parameter); 155 | $this->assertSame('test-case-param-name', $parameter->getName()); 156 | $this->assertSame('test-case-param-value', $parameter->getValue()); 157 | $this->assertSame(ParameterKind::ARGUMENT, $parameter->getKind()); 158 | } 159 | 160 | private function getLabelsByType(array $labels, string $labelType): array 161 | { 162 | $filteredArray = array_filter( 163 | $labels, 164 | function ($element) use ($labelType) { 165 | return ($element instanceof Label) && ($element->getName() === $labelType); 166 | } 167 | ); 168 | uasort( 169 | $filteredArray, 170 | function (Label $l1, Label $l2) { 171 | $label1Value = $l1->getValue(); 172 | $label2Value = $l2->getValue(); 173 | if ($label1Value === $label2Value) { 174 | return 0; 175 | } 176 | 177 | return ($label1Value < $label2Value) ? -1 : 1; 178 | } 179 | ); 180 | 181 | return $filteredArray; 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Annotation/AnnotationProviderTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(sizeof($annotations) === 1); 30 | $annotation = array_pop($annotations); 31 | $this->assertInstanceOf('Yandex\Allure\Adapter\Annotation\Fixtures\TestAnnotation', $annotation); 32 | $this->assertEquals(self::TYPE_CLASS, $annotation->value); 33 | } 34 | 35 | public function testGetMethodAnnotations(): void 36 | { 37 | $instance = new Fixtures\ClassWithAnnotations(); 38 | $annotations = AnnotationProvider::getMethodAnnotations($instance, self::METHOD_NAME); 39 | $this->assertTrue(sizeof($annotations) === 1); 40 | $annotation = array_pop($annotations); 41 | $this->assertInstanceOf('Yandex\Allure\Adapter\Annotation\Fixtures\TestAnnotation', $annotation); 42 | $this->assertEquals(self::TYPE_METHOD, $annotation->value); 43 | } 44 | 45 | public function testShouldThrowExceptionForNotImportedAnnotations(): void 46 | { 47 | $instance = new Fixtures\ClassWithIgnoreAnnotation(); 48 | $this->expectException(AnnotationException::class); 49 | AnnotationProvider::getClassAnnotations($instance); 50 | } 51 | 52 | public function testShouldIgnoreGivenAnnotations(): void 53 | { 54 | $instance = new Fixtures\ClassWithIgnoreAnnotation(); 55 | AnnotationProvider::addIgnoredAnnotations(['SomeCustomClassAnnotation', 'SomeCustomMethodAnnotation']); 56 | 57 | $this->assertEmpty(AnnotationProvider::getClassAnnotations($instance)); 58 | $this->assertEmpty(AnnotationProvider::getMethodAnnotations($instance, 'methodWithIgnoredAnnotation')); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Annotation/Fixtures/ClassWithAnnotations.php: -------------------------------------------------------------------------------- 1 | getTestContents()); 22 | $sha1Sum = sha1_file($tmpFilename); 23 | 24 | $event = new AddAttachmentEvent($tmpFilename, $attachmentCaption, $attachmentType); 25 | $step = new Step(); 26 | $event->process($step); 27 | 28 | $attachmentFileName = $event->getOutputFileName($sha1Sum, $correctExtension); 29 | $attachmentOutputPath = $event->getOutputPath($sha1Sum, $correctExtension); 30 | $this->checkAttachmentIsCorrect( 31 | $step, 32 | $attachmentOutputPath, 33 | $attachmentFileName, 34 | $attachmentCaption, 35 | $attachmentType 36 | ); 37 | } 38 | 39 | public function testEventWithStringContents(): void 40 | { 41 | $attachmentCaption = self::ATTACHMENT_CAPTION; 42 | $attachmentType = 'text/plain'; 43 | $correctExtension = 'txt'; 44 | $tmpDirectory = sys_get_temp_dir(); 45 | Provider::setOutputDirectory($tmpDirectory); 46 | $contents = $this->getTestContents(); 47 | $sha1Sum = sha1($contents); 48 | 49 | $event = new AddAttachmentEvent($contents, $attachmentCaption); 50 | $step = new Step(); 51 | $event->process($step); 52 | 53 | $attachmentFileName = $event->getOutputFileName($sha1Sum, $correctExtension); 54 | $attachmentOutputPath = $event->getOutputPath($sha1Sum, $correctExtension); 55 | $this->checkAttachmentIsCorrect( 56 | $step, 57 | $attachmentOutputPath, 58 | $attachmentFileName, 59 | $attachmentCaption, 60 | $attachmentType 61 | ); 62 | } 63 | 64 | private function checkAttachmentIsCorrect( 65 | Step $step, 66 | $attachmentOutputPath, 67 | $attachmentFileName, 68 | $attachmentCaption, 69 | $attachmentType 70 | ): void { 71 | $this->assertTrue(file_exists($attachmentOutputPath)); 72 | $attachments = $step->getAttachments(); 73 | $this->assertEquals(1, sizeof($attachments)); 74 | $attachment = array_pop($attachments); 75 | $this->assertInstanceOf('Yandex\Allure\Adapter\Model\Attachment', $attachment); 76 | $this->assertEquals($attachmentFileName, $attachment->getSource()); 77 | $this->assertEquals($attachmentCaption, $attachment->getTitle()); 78 | $this->assertEquals($attachmentType, $attachment->getType()); 79 | } 80 | 81 | private function getTestContents(): string 82 | { 83 | return str_shuffle('test-contents'); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/AddParameterEventTest.php: -------------------------------------------------------------------------------- 1 | process($testCase); 20 | $this->assertEquals(1, sizeof($testCase->getParameters())); 21 | $parameters = $testCase->getParameters(); 22 | $parameter = array_pop($parameters); 23 | $this->assertTrue( 24 | ($parameter instanceof Parameter) && 25 | ($parameter->getName() === $parameterName) && 26 | ($parameter->getValue() === $parameterValue) && 27 | ($parameter->getKind() === $parameterKind) 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/RemoveAttachmentsEventTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(file_exists($matchingFilename)); 22 | 23 | $notMatchingFilename = tempnam($tmpDirectory, 'excluded'); 24 | 25 | $step = new Step(); 26 | $step->addAttachment(new Attachment($attachmentTitle, $matchingFilename, self::ATTACHMENT_TYPE)); 27 | $step->addAttachment(new Attachment($attachmentTitle, $notMatchingFilename, self::ATTACHMENT_TYPE)); 28 | 29 | $this->assertEquals(2, sizeof($step->getAttachments())); 30 | 31 | $event = new RemoveAttachmentsEvent("/$pattern/i"); 32 | $event->process($step); 33 | 34 | $this->assertEquals(1, sizeof($step->getAttachments())); 35 | $this->assertFalse(file_exists($matchingFilename)); 36 | $attachments = $step->getAttachments(); 37 | $attachment = array_pop($attachments); 38 | $this->assertTrue( 39 | ($attachment instanceof Attachment) && 40 | ($attachment->getSource() === $notMatchingFilename) 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/StepCanceledEventTest.php: -------------------------------------------------------------------------------- 1 | process($step); 15 | $this->assertNotEmpty($step->getStop()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/StepStartedEventTest.php: -------------------------------------------------------------------------------- 1 | withTitle($stepTitle); 18 | $event->process($step); 19 | $this->assertEquals(Status::PASSED, $step->getStatus()); 20 | $this->assertEquals($stepTitle, $step->getTitle()); 21 | $this->assertNotEmpty($step->getStart()); 22 | $this->assertEquals($stepName, $step->getName()); 23 | $this->assertEmpty($step->getStop()); 24 | $this->assertEmpty($step->getSteps()); 25 | $this->assertEmpty($step->getAttachments()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/StepStatusChangedEventTest.php: -------------------------------------------------------------------------------- 1 | getStepEvent(); 18 | $event->process($step); 19 | $this->assertEquals($this->getTestedStatus(), $step->getStatus()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/Storage/Fixtures/MockedRootStepStorage.php: -------------------------------------------------------------------------------- 1 | setName('root-step'); 14 | 15 | return $rootStep; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/Storage/StepStorageTest.php: -------------------------------------------------------------------------------- 1 | assertTrue($storage->isRootStep($storage->getLast())); 16 | $this->assertTrue($storage->isRootStep($storage->pollLast())); 17 | $this->assertTrue($storage->isEmpty()); 18 | } 19 | 20 | public function testNonEmptyStorage(): void 21 | { 22 | $storage = new Fixtures\MockedRootStepStorage(); 23 | $step = new Step(); 24 | $step->setName(self::TEST_STEP_NAME); 25 | $storage->put($step); 26 | $this->assertEquals(self::TEST_STEP_NAME, $storage->getLast()->getName()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/Storage/TestCaseStorageTest.php: -------------------------------------------------------------------------------- 1 | get(); 14 | $this->assertEmpty($testCase->getName()); 15 | 16 | $name1 = 'test-name1'; 17 | $testCase->setName($name1); 18 | $this->assertEquals($name1, $storage->get()->getName()); 19 | 20 | $name2 = 'test-name1'; 21 | $testCase = new TestCase(); 22 | $testCase->setName($name2); 23 | $storage->put($testCase); 24 | $this->assertEquals($name2, $storage->get()->getName()); 25 | 26 | $storage->clear(); 27 | $this->assertEmpty($storage->get()->getName()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/Storage/TestSuiteStorageTest.php: -------------------------------------------------------------------------------- 1 | get($uuid); 15 | $this->assertEmpty($testSuite->getName()); 16 | $testSuite->setName($name); 17 | $this->assertEquals($name, $storage->get($uuid)->getName()); 18 | 19 | $storage->remove($uuid); 20 | $this->assertEmpty($storage->get($uuid)->getName()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/TestCaseBrokenEventTest.php: -------------------------------------------------------------------------------- 1 | process($testCase); 15 | $this->assertNotEmpty($testCase->getStop()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/TestCasePendingEventTest.php: -------------------------------------------------------------------------------- 1 | withTitle($testCaseTitle) 33 | ->withDescription(new Description($testCaseDescriptionType, $testCaseDescriptionValue)) 34 | ->withLabels([new Label($testCaseLabelName, $testCaseLabelValue)]) 35 | ->withParameters([new Parameter($testCaseParameterName, $testCaseParameterValue, $testCaseParameterKind)]); 36 | $event->process($testCase); 37 | 38 | $this->assertEquals(Status::PASSED, $testCase->getStatus()); 39 | $this->assertEquals($testCaseTitle, $testCase->getTitle()); 40 | $this->assertNotEmpty($testCase->getStart()); 41 | $this->assertEquals($testCaseName, $testCase->getName()); 42 | $this->assertNotEmpty($testCase->getDescription()); 43 | $this->assertEquals($testCaseDescriptionValue, $testCase->getDescription()->getValue()); 44 | $this->assertEquals($testCaseDescriptionType, $testCase->getDescription()->getType()); 45 | $this->assertEquals(1, sizeof($testCase->getLabels())); 46 | $labels = $testCase->getLabels(); 47 | $label = array_pop($labels); 48 | $this->assertTrue( 49 | ($label instanceof Label) && 50 | ($label->getName() === $testCaseLabelName) && 51 | ($label->getValue() === $testCaseLabelValue) 52 | ); 53 | $this->assertEquals(1, sizeof($testCase->getParameters())); 54 | $parameters = $testCase->getParameters(); 55 | $parameter = array_pop($parameters); 56 | $this->assertTrue( 57 | ($parameter instanceof Parameter) && 58 | ($parameter->getName() === $testCaseParameterName) && 59 | ($parameter->getValue() === $testCaseParameterValue) && 60 | ($parameter->getKind() === $testCaseParameterKind) 61 | ); 62 | $this->assertEmpty($testCase->getStop()); 63 | $this->assertEmpty($testCase->getSteps()); 64 | $this->assertEmpty($testCase->getAttachments()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/TestCaseStatusChangedEventTest.php: -------------------------------------------------------------------------------- 1 | getTestCaseStatusChangedEvent(); 20 | $event->withMessage($testMessage)->withException(new Exception()); 21 | $event->process($testCase); 22 | 23 | $this->assertEquals($this->getTestedStatus(), $testCase->getStatus()); 24 | $this->assertEquals($testMessage, $testCase->getFailure()->getMessage()); 25 | $this->assertNotEmpty($testCase->getFailure()->getStackTrace()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/TestSuiteFinishedEventTest.php: -------------------------------------------------------------------------------- 1 | process($testSuite); 15 | $this->assertNotEmpty($testSuite->getStop()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Event/TestSuiteStartedEventTest.php: -------------------------------------------------------------------------------- 1 | withTitle($testSuiteTitle) 26 | ->withDescription(new Description($testSuiteDescriptionType, $testSuiteDescriptionValue)) 27 | ->withLabels(array(new Label($testSuiteLabelName, $testSuiteLabelValue))); 28 | $event->process($testSuite); 29 | 30 | $this->assertEquals($testSuiteTitle, $testSuite->getTitle()); 31 | $this->assertNotEmpty($testSuite->getStart()); 32 | $this->assertEquals($testSuiteName, $testSuite->getName()); 33 | $this->assertNotEmpty($testSuite->getDescription()); 34 | $this->assertEquals($testSuiteDescriptionValue, $testSuite->getDescription()->getValue()); 35 | $this->assertEquals($testSuiteDescriptionType, $testSuite->getDescription()->getType()); 36 | $this->assertEquals(1, sizeof($testSuite->getLabels())); 37 | $labels = $testSuite->getLabels(); 38 | $label = array_pop($labels); 39 | $this->assertTrue( 40 | ($label instanceof Label) && 41 | ($label->getName() === $testSuiteLabelName) && 42 | ($label->getValue() === $testSuiteLabelValue) 43 | ); 44 | $this->assertEmpty($testSuite->getStop()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Fixtures/GenericStepEvent.php: -------------------------------------------------------------------------------- 1 | name = $name; 16 | } 17 | 18 | public function process(Entity $context) 19 | { 20 | if ($context instanceof Step) { 21 | $context->setName($this->name); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Fixtures/GenericTestCaseEvent.php: -------------------------------------------------------------------------------- 1 | name = $name; 16 | } 17 | 18 | public function process(Entity $context) 19 | { 20 | if ($context instanceof TestCase) { 21 | $context->setName($this->name); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Fixtures/GenericTestSuiteEvent.php: -------------------------------------------------------------------------------- 1 | name = $name; 17 | } 18 | 19 | public function process(Entity $context) 20 | { 21 | if ($context instanceof TestSuite) { 22 | $context->setName($this->name); 23 | } 24 | } 25 | 26 | public function getUuid() 27 | { 28 | return AllureTest::TEST_SUITE_UUID; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Model/ConstantCheckerTest.php: -------------------------------------------------------------------------------- 1 | assertEquals( 16 | TestConstants::TEST_CONSTANT, 17 | ConstantChecker::validate(self::CLASS_NAME, TestConstants::TEST_CONSTANT) 18 | ); 19 | } 20 | 21 | public function testConstantIsMissing(): void 22 | { 23 | $this->expectException(AllureException::class); 24 | ConstantChecker::validate(self::CLASS_NAME, 'missing-value'); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Model/Fixtures/TestConstants.php: -------------------------------------------------------------------------------- 1 | addAttachment($attachmentContents, $attachmentCaption, $attachmentType); 21 | $event = Allure::lifecycle()->getLastEvent(); 22 | $this->assertTrue( 23 | ($event instanceof AddAttachmentEvent) && 24 | ($event->getFilePathOrContents() === $attachmentContents) && 25 | ($event->getCaption() === $attachmentCaption) && 26 | ($event->getType() === $attachmentType) 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Support/MockedLifecycle.php: -------------------------------------------------------------------------------- 1 | reset(); 20 | } 21 | 22 | public function fire(Event $event) 23 | { 24 | $this->events[] = $event; 25 | } 26 | 27 | public function getEvents(): array 28 | { 29 | return $this->events; 30 | } 31 | 32 | public function reset() 33 | { 34 | $this->events = array(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Support/StepSupportTest.php: -------------------------------------------------------------------------------- 1 | mockedLifecycle = new MockedLifecycle(); 28 | parent::__construct(); 29 | } 30 | 31 | protected function setUp(): void 32 | { 33 | parent::setUp(); 34 | $this->mockedLifecycle = new MockedLifecycle(); 35 | $this->getMockedLifecycle()->reset(); 36 | Allure::setLifecycle($this->getMockedLifecycle()); 37 | } 38 | 39 | public function testExecuteStepCorrectly(): void 40 | { 41 | $logicWithNoException = function () { 42 | //We do nothing, hence no error 43 | }; 44 | $this->executeStep(self::STEP_NAME, $logicWithNoException, self::STEP_TITLE); 45 | $events = $this->getMockedLifecycle()->getEvents(); 46 | $this->assertEquals(2, sizeof($events)); 47 | $this->assertTrue($events[0] instanceof StepStartedEvent); 48 | $this->assertTrue($events[1] instanceof StepFinishedEvent); 49 | } 50 | 51 | public function testExecuteFailingStep() 52 | { 53 | $logicWithException = function () { 54 | throw new Exception(); 55 | }; 56 | $this->expectException(Exception::class); 57 | $this->executeStep(self::STEP_NAME, $logicWithException, self::STEP_TITLE); 58 | $events = $this->getMockedLifecycle()->getEvents(); 59 | $this->assertEquals(3, sizeof($events)); 60 | $this->assertTrue($events[0] instanceof StepStartedEvent); 61 | $this->assertTrue($events[1] instanceof StepFailedEvent); 62 | $this->assertTrue($events[2] instanceof StepFinishedEvent); 63 | } 64 | 65 | public function testExecuteStepWithMissingData() 66 | { 67 | $this->expectException(AllureException::class); 68 | $this->executeStep(null, null, null); 69 | } 70 | 71 | protected function tearDown(): void 72 | { 73 | parent::tearDown(); 74 | Allure::setDefaultLifecycle(); 75 | } 76 | 77 | private function getMockedLifecycle(): MockedLifecycle 78 | { 79 | return $this->mockedLifecycle; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/Support/UtilsTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(is_float($timestamp)); 15 | $this->assertGreaterThan(0, $timestamp); 16 | } 17 | 18 | public function testGenerateUUID(): void 19 | { 20 | $uuid1 = self::generateUUID(); 21 | $uuid2 = self::generateUUID(); 22 | $this->assertTrue(is_string($uuid1)); 23 | $this->assertNotEquals($uuid1, $uuid2); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/XMLValidationTest.php: -------------------------------------------------------------------------------- 1 | prepareDirForXML(); 45 | $uuid = $this->generateXML($tmpDir); 46 | 47 | $fileName = $tmpDir . DIRECTORY_SEPARATOR . $uuid . '-testsuite.xml'; 48 | $this->assertTrue(file_exists($fileName)); 49 | $this->validateFileXML($fileName); 50 | } 51 | 52 | private function prepareDirForXML() 53 | { 54 | $tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('allure-xml-test'); 55 | mkdir($tmpDir); 56 | $this->assertTrue( 57 | file_exists($tmpDir) && 58 | is_writable($tmpDir) 59 | ); 60 | 61 | return $tmpDir; 62 | } 63 | 64 | private function generateXML($tmpDir) 65 | { 66 | AnnotationRegistry::registerAutoloadNamespace( 67 | 'JMS\Serializer\Annotation', 68 | __DIR__ . "/../../../../vendor/jms/serializer/src" 69 | ); 70 | Model\Provider::setOutputDirectory($tmpDir); 71 | Allure::setDefaultLifecycle(); 72 | $testSuiteStartedEvent = new TestSuiteStartedEvent(TEST_SUITE_NAME); 73 | $uuid = $testSuiteStartedEvent->getUuid(); 74 | $testSuiteStartedEvent->setTitle(TEST_SUITE_TITLE); 75 | $testSuiteStartedEvent->setDescription(new Description(DescriptionType::HTML, DESCRIPTION)); 76 | $testSuiteStartedEvent->setLabels([ 77 | Label::feature(FEATURE_NAME), 78 | Label::story(STORY_NAME) 79 | ]); 80 | Allure::lifecycle()->fire($testSuiteStartedEvent); 81 | 82 | $testCaseStartedEvent = new TestCaseStartedEvent($uuid, TEST_CASE_NAME); 83 | $testCaseStartedEvent->setDescription(new Description(DescriptionType::MARKDOWN, DESCRIPTION)); 84 | $testCaseStartedEvent->setLabels([ 85 | Label::feature(FEATURE_NAME), 86 | Label::story(STORY_NAME), 87 | Label::severity(SeverityLevel::MINOR) 88 | ]); 89 | $testCaseStartedEvent->setTitle(TEST_CASE_TITLE); 90 | $testCaseStartedEvent->setParameters([ 91 | new Parameter(PARAMETER_NAME, PARAMETER_VALUE, ParameterKind::SYSTEM_PROPERTY) 92 | ]); 93 | Allure::lifecycle()->fire($testCaseStartedEvent); 94 | 95 | $testCaseFailureEvent = new TestCaseFailedEvent(); 96 | $testCaseFailureEvent = $testCaseFailureEvent->withMessage(FAILURE_MESSAGE)->withException(new \Exception()); 97 | Allure::lifecycle()->fire($testCaseFailureEvent); 98 | 99 | $stepStartedEvent = new StepStartedEvent(STEP_NAME); 100 | $stepStartedEvent = $stepStartedEvent->withTitle(STEP_TITLE); 101 | Allure::lifecycle()->fire($stepStartedEvent); 102 | Allure::lifecycle()->fire( 103 | new AddAttachmentEvent(STEP_ATTACHMENT_SOURCE, STEP_ATTACHMENT_TITLE, 'text/plain') 104 | ); 105 | Allure::lifecycle()->fire(new StepFinishedEvent()); 106 | 107 | Allure::lifecycle()->fire(new TestCaseFinishedEvent()); 108 | Allure::lifecycle()->fire(new TestSuiteFinishedEvent($uuid)); 109 | 110 | return $uuid; 111 | } 112 | 113 | private function validateFileXML($fileName) 114 | { 115 | libxml_use_internal_errors(true); //Comment this line to see DOMDocument XML validation errors 116 | $dom = new DOMDocument(); 117 | $dom->load($fileName); 118 | $schemaFilename = __DIR__ . DIRECTORY_SEPARATOR . 'allure-1.4.0.xsd'; 119 | $isSchemaValid = $dom->schemaValidate($schemaFilename); 120 | $this->assertTrue($isSchemaValid, 'XML file should be valid'); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /test/Yandex/Allure/Adapter/allure-1.4.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | --------------------------------------------------------------------------------