├── .env.default ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── test_reporter_request.md ├── dependabot.yml └── workflows │ └── tests.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── cleanup.php ├── functions.php ├── prepare.php ├── report.php └── test.php /.env.default: -------------------------------------------------------------------------------- 1 | ### 2 | # Configuration environment variables used by the test runner 3 | # 4 | # # Create a copy for your local environment 5 | # $ cp .env.default .env 6 | # 7 | # # Make any necessary changes to the default values 8 | # $ vim .env 9 | # 10 | # # Load your variables into your environment 11 | # $ source .env 12 | ### 13 | 14 | # Path to the directory where files can be prepared before being delivered to the environment. 15 | export WPT_PREPARE_DIR=/tmp/wp-test-runner 16 | 17 | # Path to the directory where the WordPress develop checkout can be placed and tests can be run. 18 | # When running tests in the same environment, set WPT_TEST_DIR to WPT_PREPARE_DIR 19 | export WPT_TEST_DIR=wp-test-runner 20 | 21 | # API key to authenticate with the reporting service in 'username:password' format. 22 | export WPT_REPORT_API_KEY= 23 | 24 | # (Optionally) define an alternate reporting URL 25 | export WPT_REPORT_URL= 26 | 27 | # Credentials for a database that can be written to and reset. 28 | # WARNING!!! This database will be destroyed between tests. Only use safe database credentials. 29 | # Please note that you must escape _or_ refrain from using # as special character in your credentials. 30 | export WPT_DB_NAME= 31 | export WPT_DB_USER= 32 | export WPT_DB_PASSWORD= 33 | export WPT_DB_HOST= 34 | 35 | # (Optionally) set a custom table prefix to permit concurrency against the same database. 36 | export WPT_TABLE_PREFIX=${WPT_TABLE_PREFIX-wptests_} 37 | 38 | # (Optionally) define the PHP executable to be called 39 | export WPT_PHP_EXECUTABLE=${WPT_PHP_EXECUTABLE-php} 40 | 41 | # (Optionally) define the PHPUnit command execution call. 42 | # Use if `php phpunit.phar` can't be called directly for some reason. 43 | export WPT_PHPUNIT_CMD= 44 | 45 | # (Optionally) define the command execution to remove the test directory 46 | # Use if `rm -r` can't be called directly for some reason. 47 | export WPT_RM_TEST_DIR_CMD= 48 | 49 | # SSH connection string (can also be an alias). 50 | # Leave empty if tests are meant to run in the same environment. 51 | export WPT_SSH_CONNECT= 52 | 53 | # Any options to be passed to the SSH connection 54 | # Defaults to '-o StrictHostKeyChecking=no' 55 | export WPT_SSH_OPTIONS= 56 | 57 | # SSH private key, base64 encoded. 58 | export WPT_SSH_PRIVATE_KEY_BASE64= 59 | 60 | # Output logging 61 | # Use 'verbose' to increase verbosity 62 | export WPT_DEBUG= 63 | 64 | # Certificate validation 65 | # Use 1 to validate, and 0 to not validate 66 | export WPT_CERTIFICATE_VALIDATION=1 67 | 68 | # WordPress flavor 69 | # 0 = WordPress (simple version) 70 | # 1 = WordPress Multisite 71 | export WPT_FLAVOR=1 72 | 73 | # Extra tests (groups) 74 | # 0 = none 75 | # 1 = ajax 76 | # 2 = ms-files 77 | # 3 = external-http 78 | export WPT_EXTRATESTS=0 79 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 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 | **Additional context** 27 | Add any other context about the problem here. 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 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. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/test_reporter_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Test Reporter request 3 | about: Requesting your bot user to be added to this WordPress.org site as a “Test 4 | Reporter”. 5 | title: "[Test Reporter] " 6 | labels: test-reporter-request 7 | assignees: '' 8 | 9 | --- 10 | 11 | Requesting your bot user to be added to this WordPress.org site [as a “Test Reporter”](https://make.wordpress.org/hosting/test-results/). 12 | 13 | For more information, please visit the [Getting Started](https://make.wordpress.org/hosting/test-results-getting-started/) Guide or the [Hosting Handbook](https://make.wordpress.org/hosting/handbook/tests/). 14 | 15 | **Preconditions Checklist:** 16 | 17 | * [ ] I've added a Gravatar/logo to the profile. 18 | * [ ] I've added a URL to the profile, to make it clear to users what hosting company is being represented in the results. 19 | * [ ] I've set the email address to something monitored by a human. 20 | * [ ] I've set the email address to one that uses the domain name of the hosting company. 21 | 22 | **Bot Profile Details:** 23 | 24 | * Bot email address: 25 | * Bot WordPress profile: 26 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Configure Dependabot scanning. 2 | version: 2 3 | 4 | updates: 5 | # Check for updates to GitHub Actions. 6 | - package-ecosystem: "github-actions" 7 | directory: "/" 8 | schedule: 9 | interval: "daily" 10 | open-pull-requests-limit: 10 11 | groups: 12 | github-actions: 13 | patterns: 14 | - "*" 15 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: WordPress PHPUnit tests 2 | 3 | on: 4 | # The workflow should be run on a schedule using the 'schedule' event trigger. 5 | # 6 | # For more details on how to configure the schedule event, see https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onschedule. 7 | # 8 | # Below are some options for different schedules. Running the tests every hour is recommended, 9 | # but every 3-6 hours is also helpful. Times are in UTC. 10 | schedule: 11 | # By default, the workflow will run every hour. 12 | - cron: '0 * * * *' 13 | # Every 3 hours. 14 | # - cron: '0 0/3 * * *' 15 | # Every 6 hours. 16 | # - cron: '0 0/6 * * *' 17 | # Every 12 hours. 18 | # - cron: '0 0/12 * * *' 19 | # Once per day at 00:00. 20 | # - cron: '0 0 * * *' 21 | # Every 30 minutes. 22 | # - cron: '0/30 * * * *' 23 | workflow_dispatch: 24 | 25 | # Cancels all previous workflow runs for pull requests that have not completed. 26 | concurrency: 27 | # The concurrency group contains the workflow name and the branch name for pull requests 28 | # or the commit hash for any other events. 29 | group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} 30 | cancel-in-progress: true 31 | 32 | jobs: 33 | # Tests the PHPUnit test runner. 34 | # 35 | # Performs the following steps: 36 | # - Checks out the repository. 37 | # - Installs PHP. 38 | # - Installs NodeJS 14 with caching configured. 39 | # - Prepares the environment for tests. 40 | # - Runs the tests. 41 | # - Reports the results. 42 | # - Cleans up. 43 | test: 44 | name: Run Core PHPUnit tests 45 | runs-on: ubuntu-latest 46 | 47 | # Remove this line if Github Actions is your preferred means of running the tests. 48 | if: ${{ false }} 49 | 50 | env: 51 | # This is only a subset/example of env vars available. See the `.env.default` file for a full list. 52 | WPT_PREPARE_DIR: ${{ secrets.WPT_PREPARE_DIR }} 53 | WPT_TEST_DIR: ${{ secrets.WPT_TEST_DIR }} 54 | WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }} 55 | WPT_PHP_EXECUTABLE: ${{ secrets.WPT_PHP_EXECUTABLE }} 56 | # Database settings 57 | WPT_DB_NAME: ${{ secrets.WPT_DB_NAME }} 58 | WPT_DB_USER: ${{ secrets.WPT_DB_USER }} 59 | WPT_DB_PASSWORD: ${{ secrets.WPT_DB_PASSWORD }} 60 | WPT_DB_HOST: ${{ secrets.WPT_DB_HOST }} 61 | # SSH settings for connecting to the test environment. 62 | WPT_SSH_CONNECT: ${{ secrets.WPT_SSH_CONNECT }} 63 | WPT_SSH_PRIVATE_KEY_BASE64: ${{ secrets.WPT_SSH_PRIVATE_KEY_BASE64 }} 64 | 65 | steps: 66 | - name: Checkout repository 67 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 68 | 69 | - name: Set up PHP 70 | uses: shivammathur/setup-php@cf4cade2721270509d5b1c766ab3549210a39a2a # v2.33.0 71 | with: 72 | php-version: '7.4' 73 | coverage: none 74 | 75 | - name: Install NodeJS 76 | uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 77 | with: 78 | node-version: 20 79 | 80 | - name: Prepare environment 81 | run: php prepare.php 82 | 83 | - name: Run unit tests 84 | run: php test.php 85 | # Prevent the workflow from stopping if there are test failures. 86 | continue-on-error: true 87 | 88 | - name: Report the results 89 | run: php report.php 90 | # Prevent the workflow from stopping if the reporting fails. 91 | continue-on-error: true 92 | 93 | - name: Cleanup 94 | run: php cleanup.php 95 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .env* 3 | vendor/ 4 | package-lock.json 5 | commit.json 6 | ignore.json -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | node_js: 3 | - 20 4 | 5 | before_install: 6 | - npm install -g npm@latest 7 | 8 | install: 9 | - php prepare.php 10 | 11 | script: 12 | - php test.php 13 | 14 | after_script: 15 | - php report.php 16 | - php cleanup.php 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHPUnit Test Runner 2 | 3 | Thanks for running the WordPress PHPUnit test suite on your infrastructure. We appreciate you helping to ensure WordPress’s compatibility for your users. 4 | 5 | If you haven't already, [please first read through the "Getting Started" documentation](https://make.wordpress.org/hosting/handbook/tests/). 6 | 7 | The test suite runner is designed to be used without any file modification. Configuration happens with a series of environment variables (see [.env.default](.env.default) for an annotated overview). 8 | 9 | At a high level, the test suite runner: 10 | 11 | 1. Prepares the test environment for the test suite. 12 | 2. Runs the PHPUnit tests in the test environment. 13 | 3. Reports the PHPUnit test results to WordPress.org 14 | 4. Cleans up the test suite environment. 15 | 16 | ## Setup 17 | 18 | The test suite runner can be used in one of two ways: 19 | 20 | 1. With GitHub Actions, (or Travis, Circle, or another CI service) as the controller that connects to the remote test environment. 21 | 2. With the runner cloned to and run directly within the test environment. 22 | 23 | The test runner is configured through environment variables, documented in [`.env.default`](.env.default). It shouldn't need any code modifications; in fact, please refrain from editing the scripts entirely, as it will make it easier to stay up to date. 24 | 25 | With a direct Git clone, you can: 26 | 27 | ```bash 28 | # Copy the default .env file. 29 | cp .env.default .env 30 | # Edit the .env file to define your variables. 31 | vim .env 32 | # Load your variables into scope. 33 | source .env 34 | ``` 35 | 36 | In a CI service, you can set these environment variables through the service's web console. Importantly, the `WPT_SSH_CONNECT` environment variable determines whether the test suite is run locally or against a remote environment. 37 | 38 | Concurrently run tests in the same environment by appending build ids to the test directory and table prefix: 39 | 40 | ```bash 41 | export WPT_TEST_DIR=wp-test-runner-$TRAVIS_BUILD_NUMBER 42 | export WPT_TABLE_PREFIX=wptests_$TRAVIS_BUILD_NUMBER\_ 43 | ``` 44 | 45 | Connect to a remote environment over SSH by having the CI job provision the SSH key: 46 | 47 | ```bash 48 | # 1. Create a SSH key pair for the controller to use 49 | ssh-keygen -t rsa -b 4096 -C "travis@travis-ci.org" 50 | # 2. base64 encode the private key for use with the environment variable 51 | cat ~/.ssh/id_rsa | base64 --wrap=0 52 | # 3. Append id_rsa.pub to authorized_keys so the CI service can SSH in 53 | cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 54 | ``` 55 | 56 | Use a more complex SSH connection process by creating an SSH alias: 57 | 58 | ```bash 59 | # 1. Add the following to ~/.ssh/config to create a 'wpt' alias 60 | Host wpt 61 | Hostname 123.45.67.89 62 | User wpt 63 | Port 1234 64 | # 2. Use 'wpt' wherever you might normally use a SSH connection string 65 | ssh wpt 66 | ``` 67 | 68 | ## Running 69 | 70 | The test suite runner is run in four steps. This explanation is for the local execution. 71 | 72 | ### Requirements 73 | 74 | To use the Runner, the following is required (testing WordPress 6.5): 75 | 76 | - Server / hosting (infrastructure) with the usual configuration you use 77 | - A database where you can test (tables will be created and destroyed several times) 78 | - PHP 7.0+ (view ) 79 | - MySQL 5.5+ / MariaDB 10.0+ 80 | - NodeJS 20.x / npm 10.x / grunt 81 | - PHP Composer 82 | - Git, RSync, WGet, UnZip 83 | 84 | Test environment: 85 | 86 | - Writable filesystem for the entire test directory (see [#40910](https://core.trac.wordpress.org/ticket/40910)). 87 | - Run with a non-root user, both for security and practical purposes (see [#44233](https://core.trac.wordpress.org/ticket/44233#comment:34)/[#46577](https://core.trac.wordpress.org/ticket/46577)). 88 | 89 | #### Database creation 90 | 91 | _This is an example for MySQL / MariaDB._ 92 | 93 | ```sql 94 | CREATE DATABASE wordpressdatabase CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci; 95 | GRANT ALL ON wordpressdatabase.* TO 'wordpressusername'@'localhost' IDENTIFIED BY 'wordpresspassword'; 96 | GRANT ALL ON wordpressdatabase.* TO 'wordpressusername'@'127.0.0.1' IDENTIFIED BY 'wordpresspassword'; 97 | FLUSH PRIVILEGES; 98 | ``` 99 | 100 | #### NodeJS installation 101 | 102 | _This is an example for Debian / Ubuntu._ 103 | 104 | ```bash 105 | curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - 106 | sudo apt -y install nodejs 107 | sudo npm install -g npm@latest 108 | nodejs --version 109 | npm --version 110 | ``` 111 | 112 | #### PHP Composer 113 | 114 | _This is an example for Debian / Ubuntu._ 115 | 116 | ```bash 117 | curl -sS https://getcomposer.org/installer -o composer-setup.php 118 | php composer-setup.php --install-dir=/usr/local/bin --filename=composer 119 | composer --version 120 | ``` 121 | 122 | #### Git 123 | 124 | _This is an example for Debian / Ubuntu._ 125 | 126 | ```bash 127 | apt -y install git 128 | git --version 129 | ``` 130 | 131 | ### Installing the Test Runner 132 | 133 | First, download the software. This example uses `/home/wptestrunner/` folder, but set the best for this environment. 134 | 135 | ```bash 136 | cd /home/wptestrunner/ 137 | git clone https://github.com/WordPress/phpunit-test-runner.git 138 | cd phpunit-test-runner/ 139 | ``` 140 | 141 | The next step will be to configure the environment. To do this, make a copy of the example file and then configure it. 142 | 143 | ```bash 144 | cp .env.default .env 145 | vim .env 146 | ``` 147 | 148 | The content (in summary form) can be something like this: 149 | 150 | ```bash 151 | ### 152 | # Configuration environment variables used by the test runner 153 | # 154 | # # Create a copy for your local environment 155 | # $ cp .env.default .env 156 | # 157 | # # Make any necessary changes to the default values 158 | # $ vim .env 159 | # 160 | # # Load your variables into your environment 161 | # $ source .env 162 | ### 163 | 164 | # Path to the directory where files can be prepared before being delivered to the environment. 165 | export WPT_PREPARE_DIR=/tmp/wp-test-runner 166 | 167 | # Path to the directory where the WordPress develop checkout can be placed and tests can be run. 168 | # When running tests in the same environment, set WPT_TEST_DIR to WPT_PREPARE_DIR 169 | export WPT_TEST_DIR=/tmp/wp-test-runner 170 | 171 | # API key to authenticate with the reporting service in 'username:password' format. 172 | export WPT_REPORT_API_KEY= 173 | 174 | # (Optionally) define an alternate reporting URL 175 | export WPT_REPORT_URL= 176 | 177 | # Credentials for a database that can be written to and reset. 178 | # WARNING!!! This database will be destroyed between tests. Only use safe database credentials. 179 | # Please note that you must escape _or_ refrain from using # as special character in your credentials. 180 | export WPT_DB_NAME= 181 | export WPT_DB_USER= 182 | export WPT_DB_PASSWORD= 183 | export WPT_DB_HOST= 184 | 185 | # (Optionally) set a custom table prefix to permit concurrency against the same database. 186 | export WPT_TABLE_PREFIX=${WPT_TABLE_PREFIX-wptests_} 187 | 188 | # (Optionally) define the PHP executable to be called 189 | export WPT_PHP_EXECUTABLE=${WPT_PHP_EXECUTABLE-php} 190 | 191 | # (Optionally) define the PHPUnit command execution call. 192 | # Use if `php phpunit.phar` can't be called directly for some reason. 193 | export WPT_PHPUNIT_CMD= 194 | 195 | # (Optionally) define the command execution to remove the test directory 196 | # Use if `rm -r` can't be called directly for some reason. 197 | export WPT_RM_TEST_DIR_CMD= 198 | 199 | # SSH connection string (can also be an alias). 200 | # Leave empty if tests are meant to run in the same environment. 201 | export WPT_SSH_CONNECT= 202 | 203 | # Any options to be passed to the SSH connection 204 | # Defaults to '-o StrictHostKeyChecking=no' 205 | export WPT_SSH_OPTIONS= 206 | 207 | # SSH private key, base64 encoded. 208 | export WPT_SSH_PRIVATE_KEY_BASE64= 209 | 210 | # Output logging 211 | # Use 'verbose' to increase verbosity 212 | export WPT_DEBUG= 213 | 214 | # Certificate validation 215 | # Use 1 to validate, and 0 to not validate 216 | export WPT_CERTIFICATE_VALIDATION=1 217 | 218 | # WordPress flavor 219 | # 0 = WordPress (simple version) 220 | # 1 = WordPress Multisite 221 | export WPT_FLAVOR=1 222 | 223 | # Extra tests (groups) 224 | # 0 = none 225 | # 1 = ajax 226 | # 2 = ms-files 227 | # 3 = external-http 228 | export WPT_EXTRATESTS=0 229 | ``` 230 | 231 | Configure the folder where the WordPress software downloads and the database accesses will be made in order to prepare the tests. 232 | 233 | ### Preparing the environment 234 | 235 | Before performing the first test, let’s update all the components. This process can be run before each test in this environment if wanted to keep it up to date, although it will depend more if it is in a production environment. 236 | 237 | ```bash 238 | cd /home/wptestrunner/phpunit-test-runner/ 239 | git pull 240 | source .env 241 | git checkout master 242 | ``` 243 | 244 | If you want to check a different branch, you can change it doing: 245 | 246 | ```bash 247 | git checkout example-branch 248 | ``` 249 | 250 | ## Preparing the test 251 | 252 | Now there is the environment ready, run the test preparation. 253 | 254 | ```bash 255 | php prepare.php 256 | ``` 257 | 258 | The system will run a long series of installations, configurations and compilations of different elements in order to prepare the test. If warnings and warnings come out you should not worry too much, as it is quite normal. At the end of the process it will warn you if it needs something it doesn’t have. If it works, you should see something like this at the end: 259 | 260 | ``` 261 | Success: Prepared environment. 262 | ``` 263 | 264 | Now that the environment has been prepared, the next step is to run the tests for the first time. 265 | 266 | ### Running the test 267 | 268 | Now that the environment is ready, let’s run the tests. To do this, execute the file that will perform it. 269 | 270 | ```bash 271 | php test.php 272 | ``` 273 | 274 | What do the symbols mean? 275 | 276 | `.` → Each dot means that the test has been passed correctly. 277 | 278 | `S` → It means the test has been skipped. This is usually because these tests are only valid in certain configurations. 279 | 280 | `F` → Means that the test has failed. Information about why this happened is displayed at the end. 281 | 282 | `E` → It means that the test has failed due to a PHP error, which can be an error, warning or notice. 283 | 284 | `I` → Means that the test has been marked as incomplete. 285 | 286 | If you follow these steps, everything should work perfectly and not make any mistakes. In case you get any error, it may be normal due to some missing adjustment or extension of PHP, among others. We recommend that you adjust the configuration until it works correctly. After all, this tool is to help you improve the optimal configuration for WordPress in that infrastructure. 287 | 288 | ### Creating a report 289 | 290 | Even if the test has failed, a report will be made. The first one shows the information about our environment. Among the most important elements are the extensions that are commonly used in WordPress and some utilities that are also generally useful. 291 | 292 | ```bash 293 | cat /tmp/wp-test-runner/tests/phpunit/build/logs/env.json 294 | ``` 295 | 296 | The content of this file is somewhat similar to this: 297 | 298 | ```bash 299 | { 300 | "php_version": "7.4.5", 301 | "php_modules": { 302 | "bcmath": false, 303 | "curl": "7.4.5", 304 | "filter": "7.4.5", 305 | "gd": false, 306 | "libsodium": false, 307 | "mcrypt": false, 308 | "mod_xml": false, 309 | "mysqli": "7.4.5", 310 | "imagick": false, 311 | "pcre": "7.4.5", 312 | "xml": "7.4.5", 313 | "xmlreader": "7.4.5", 314 | "zlib": "7.4.5" 315 | }, 316 | "system_utils": { 317 | "curl": "7.58.0 (x86_64-pc-linux-gnu) libcurl\/7.58.0 OpenSSL\/1.1.1g zlib\/1.2.11 libidn2\/2.3.0 libpsl\/0.19.1 (+libidn2\/2.0.4) nghttp2\/1.30.0 librtmp\/2.3", 318 | "ghostscript": "", 319 | "imagemagick": false, 320 | "openssl": "1.1.1g 21 Apr 2020" 321 | }, 322 | "mysql_version": "mysql Ver 15.1 Distrib 10.4.12-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2", 323 | "os_name": "Linux", 324 | "os_version": "4.15.0-20-generic" 325 | } 326 | ``` 327 | 328 | In addition to this report, a definitive file with all the information of what happened in the tests. This is the one that includes all the tests that are made (more than 10,000) giving information of the time that they take to be executed, problems that have arisen… 329 | 330 | ```bash 331 | cat /tmp/wp-test-runner/tests/phpunit/build/logs/junit.xml 332 | ``` 333 | 334 | At this point we can generate the reports by sending them to WordPress.org, if necessary. Even if you haven’t included the WordPress user (see below for how to create it), you can still run this file. 335 | 336 | ```bash 337 | php report.php 338 | ``` 339 | 340 | ### Cleaning up the environment for other tests 341 | 342 | Having the tests working, all that remains is to delete all the files that have been created so that we can start over. To do this, execute the following command: 343 | 344 | ```bash 345 | php cleanup.php 346 | ``` 347 | 348 | ### Automatic running 349 | 350 | The best way to run this test is to create a cron that runs everything. Having in mind that the tests can overlap, the best way can be using a systemd timer. 351 | 352 | ```bash 353 | cat > /etc/systemd/system/wordpressphpunittestrunner.service << EOF 354 | [Unit] 355 | Description=WordPress PHPUnit Test Runner 356 | [Service] 357 | Type=oneshot 358 | ExecStart=cd /home/wptestrunner/phpunit-test-runner/ && source .env && php prepare.php && php test.php && php report.php && php cleanup.php 359 | User=wptestrunner 360 | Group=wptestrunner 361 | EOF 362 | ``` 363 | 364 | ```bash 365 | cat > /etc/systemd/system/wordpressphpunittestrunner.timer << EOF 366 | [Unit] 367 | Description=WordPress PHPUnit Test Runner 368 | [Timer] 369 | OnCalendar=*-*-* *:*:00 370 | Persistent=true 371 | [Install] 372 | WantedBy=timers.target 373 | EOF 374 | ``` 375 | 376 | ```bash 377 | systemctl daemon-reload 378 | systemctl enable wordpressphpunittestrunner.timer 379 | systemctl start wordpressphpunittestrunner.timer 380 | systemctl status wordpressphpunittestrunner.timer 381 | ``` 382 | 383 | If you want to check how is everything working... 384 | 385 | ```bash 386 | journalctl -u wordpressphpunittestrunner.timer 387 | journalctl -n 120 -u wordpressphpunittestrunner.service 388 | ``` 389 | 390 | ## Contributing 391 | 392 | If you have questions about the process or run into test failures along the way, please [open an issue in the project repository](https://github.com/WordPress/phpunit-test-runner/issues) and we’ll help diagnose/get the documentation updated. Alternatively, you can also pop into the `#hosting` channel on [WordPress.org Slack](https://make.wordpress.org/chat/) for help. 393 | 394 | ## License 395 | 396 | See [LICENSE](LICENSE) for project license. -------------------------------------------------------------------------------- /cleanup.php: -------------------------------------------------------------------------------- 1 | testsuite; 162 | $results = array(); 163 | 164 | $results = array( 165 | 'tests' => (string) $project['tests'], 166 | 'failures' => (string) $project['failures'], 167 | 'errors' => (string) $project['errors'], 168 | 'time' => (string) $project['time'], 169 | ); 170 | 171 | $results['testsuites'] = array(); 172 | 173 | $testsuites = $xml->xpath( '//testsuites//testsuite[ ( count( testcase ) > 0 ) and ( @errors > 0 or @failures > 0 ) ]' ); 174 | foreach ( $testsuites as $testsuite ) { 175 | $result = array( 176 | 'name' => (string) $testsuite['name'], 177 | 'tests' => (string) $testsuite['tests'], 178 | 'failures' => (string) $testsuite['failures'], 179 | 'errors' => (string) $testsuite['errors'] 180 | ); 181 | if ( empty( $result['failures'] ) && empty( $result['errors'] ) ) { 182 | continue; 183 | } 184 | $failures = array(); 185 | foreach ( $testsuite->testcase as $testcase ) { 186 | // Capture both failure and error children. 187 | foreach ( array( 'failure', 'error') as $key ) { 188 | if ( isset( $testcase->{$key} ) ) { 189 | $failures[ (string) $testcase['name'] ] = array( 190 | 'name' => (string) $testcase['name'], 191 | $key => (string) $testcase->{$key}, 192 | ); 193 | } 194 | } 195 | } 196 | if ( $failures ) { 197 | $results['testsuites'][ (string) $testsuite['name'] ] = $result; 198 | $results['testsuites'][ (string) $testsuite['name'] ]['testcases'] = $failures; 199 | } 200 | } 201 | 202 | return json_encode( $results ); 203 | } 204 | 205 | /** 206 | * Submits test results along with associated metadata to a specified reporting API. The function constructs 207 | * a POST request containing the test results, SVN revision, SVN message, environment data, and uses an API key 208 | * for authentication. The reporting API's URL is retrieved from an environment variable; if not found, a default 209 | * URL is used. This function is typically used to automate the reporting of test outcomes to a centralized system 210 | * for analysis, tracking, and historical record-keeping. 211 | * 212 | * @param string $results The test results in a processed format (e.g., JSON) ready for submission to the reporting API. 213 | * @param string $rev The SVN revision associated with the test results. This often corresponds to a specific code 214 | * commit or build identifier. 215 | * @param string $message The SVN commit message associated with the revision, providing context or notes about the changes. 216 | * @param string $env The environment data in JSON format, detailing the conditions under which the tests were run, 217 | * such as operating system, PHP version, etc. 218 | * @param string $api_key The API key for authenticating with the reporting API, ensuring secure and authorized access. 219 | * 220 | * @return array An array containing two elements: the HTTP status code of the response (int) and the body of the response 221 | * (string) from the reporting API. This can be used to verify successful submission or to handle errors. 222 | * 223 | * @uses curl_init(), curl_setopt(), and curl_exec() to perform the HTTP POST request to the reporting API. 224 | * @uses json_encode() to encode the data payload as a JSON string for submission. 225 | * @uses base64_encode() to encode the API key for HTTP Basic Authentication in the Authorization header. 226 | */ 227 | function upload_results( $results, $rev, $message, $env, $api_key ) { 228 | $WPT_REPORT_URL = getenv( 'WPT_REPORT_URL' ); 229 | if ( ! $WPT_REPORT_URL ) { 230 | $WPT_REPORT_URL = 'https://make.wordpress.org/hosting/wp-json/wp-unit-test-api/v1/results'; 231 | } 232 | $process = curl_init( $WPT_REPORT_URL ); 233 | $access_token = base64_encode( $api_key ); 234 | $data = array( 235 | 'results' => $results, 236 | 'commit' => $rev, 237 | 'message' => $message, 238 | 'env' => $env, 239 | ); 240 | $data_string = json_encode( $data ); 241 | 242 | curl_setopt( $process, CURLOPT_TIMEOUT, 30 ); 243 | curl_setopt( $process, CURLOPT_POST, 1 ); 244 | curl_setopt( $process, CURLOPT_CUSTOMREQUEST, 'POST' ); 245 | curl_setopt( $process, CURLOPT_USERAGENT, 'WordPress PHPUnit Test Runner' ); 246 | curl_setopt( $process, CURLOPT_POSTFIELDS, $data_string ); 247 | curl_setopt( $process, CURLOPT_RETURNTRANSFER, true ); 248 | curl_setopt( $process, CURLOPT_HTTPHEADER, array( 249 | "Authorization: Basic $access_token", 250 | 'Content-Type: application/json', 251 | 'Content-Length: ' . strlen( $data_string ) 252 | )); 253 | 254 | $return = curl_exec( $process ); 255 | $status_code = curl_getinfo( $process, CURLINFO_HTTP_CODE ); 256 | curl_close( $process ); 257 | 258 | return array( $status_code, $return ); 259 | } 260 | 261 | /** 262 | * Collects and returns an array of key environment details relevant to the application's context. This includes 263 | * the PHP version, installed PHP modules with their versions, system utilities like curl and OpenSSL versions, 264 | * MySQL version, and operating system details. This function is useful for diagnostic purposes, ensuring 265 | * compatibility, or for reporting system configurations in debugging or error logs. 266 | * 267 | * The function checks for the availability of specific PHP modules and system utilities and captures their versions. 268 | * It uses shell commands to retrieve system information, which requires the PHP environment to have access to these 269 | * commands and appropriate permissions. 270 | * 271 | * @return array An associative array containing detailed environment information. The array includes: 272 | * - 'php_version': The current PHP version. 273 | * - 'php_modules': An associative array of selected PHP modules and their versions. 274 | * - 'system_utils': Versions of certain system utilities such as 'curl', 'imagemagick', 'graphicsmagick', and 'openssl'. 275 | * - 'mysql_version': The version of MySQL installed. 276 | * - 'os_name': The name of the operating system. 277 | * - 'os_version': The version of the operating system. 278 | * 279 | * @uses phpversion() to get the PHP version and module versions. 280 | * @uses shell_exec() to execute system commands for retrieving MySQL version, OS details, and versions of utilities like curl and OpenSSL. 281 | * @uses class_exists() to check for the availability of the Imagick and Gmagick classes for version detection. 282 | */ 283 | function get_env_details() { 284 | 285 | $gd_info = array(); 286 | if( extension_loaded( 'gd' ) ) { 287 | $gd_info = gd_info(); 288 | } 289 | $imagick_info = array(); 290 | if( extension_loaded( 'imagick' ) ) { 291 | $imagick_info = Imagick::queryFormats(); 292 | } 293 | 294 | $env = array( 295 | 'php_version' => phpversion(), 296 | 'php_modules' => array(), 297 | 'gd_info' => $gd_info, 298 | 'imagick_info' => $imagick_info, 299 | 'mysql_version' => trim( shell_exec( 'mysql --version' ) ), 300 | 'system_utils' => array(), 301 | 'os_name' => trim( shell_exec( 'uname -s' ) ), 302 | 'os_version' => trim( shell_exec( 'uname -r' ) ), 303 | ); 304 | unset( $gd_info, $imagick_info ); 305 | 306 | $php_modules = array( 307 | 'bcmath', 308 | 'ctype', 309 | 'curl', 310 | 'date', 311 | 'dom', 312 | 'exif', 313 | 'fileinfo', 314 | 'filter', 315 | 'ftp', 316 | 'gd', 317 | 'gettext', 318 | 'gmagick', 319 | 'hash', 320 | 'iconv', 321 | 'imagick', 322 | 'imap', 323 | 'intl', 324 | 'json', 325 | 'libsodium', 326 | 'libxml', 327 | 'mbstring', 328 | 'mcrypt', 329 | 'mod_xml', 330 | 'mysqli', 331 | 'mysqlnd', 332 | 'openssl', 333 | 'pcre', 334 | 'pdo_mysql', 335 | 'soap', 336 | 'sockets', 337 | 'sodium', 338 | 'xml', 339 | 'xmlreader', 340 | 'zip', 341 | 'zlib', 342 | ); 343 | foreach( $php_modules as $php_module ) { 344 | $env['php_modules'][ $php_module ] = phpversion( $php_module ); 345 | } 346 | 347 | function curl_selected_bits($k) { return in_array($k, array('version', 'ssl_version', 'libz_version')); } 348 | $curl_bits = curl_version(); 349 | $env['system_utils']['curl'] = implode(' ',array_values(array_filter($curl_bits, 'curl_selected_bits',ARRAY_FILTER_USE_KEY) )); 350 | 351 | $WPT_DB_HOST = trim( getenv( 'WPT_DB_HOST' ) ); 352 | if( ! $WPT_DB_HOST ) { 353 | $WPT_DB_HOST = 'localhost'; 354 | } 355 | $WPT_DB_USER = trim( getenv( 'WPT_DB_USER' ) ); 356 | $WPT_DB_PASSWORD = trim( getenv( 'WPT_DB_PASSWORD' ) ); 357 | $WPT_DB_NAME = trim( getenv( 'WPT_DB_NAME' ) ); 358 | 359 | //$mysqli = new mysqli( $WPT_DB_HOST, $WPT_DB_USER, $WPT_DB_PASSWORD, $WPT_DB_NAME ); 360 | //$env['mysql_version'] = $mysqli->query("SELECT VERSION()")->fetch_row()[0]; 361 | //$mysqli->close(); 362 | 363 | if ( class_exists( 'Imagick' ) ) { 364 | $imagick = new Imagick(); 365 | $version = $imagick->getVersion(); 366 | preg_match( '/Magick (\d+\.\d+\.\d+-\d+|\d+\.\d+\.\d+|\d+\.\d+\-\d+|\d+\.\d+)/', $version['versionString'], $version ); 367 | $env['system_utils']['imagemagick'] = $version[1]; 368 | } elseif ( class_exists( 'Gmagick' ) ) { 369 | $gmagick = new Gmagick(); 370 | $version = $gmagick->getversion(); 371 | preg_match( '/Magick (\d+\.\d+\.\d+-\d+|\d+\.\d+\.\d+|\d+\.\d+\-\d+|\d+\.\d+)/', $version['versionString'], $version ); 372 | $env['system_utils']['graphicsmagick'] = $version[1]; 373 | } 374 | 375 | $env['system_utils']['openssl'] = str_replace( 'OpenSSL ', '', trim( shell_exec( 'openssl version' ) ) ); 376 | 377 | return $env; 378 | } 379 | -------------------------------------------------------------------------------- /prepare.php: -------------------------------------------------------------------------------- 1 | phpversion(), 168 | 'php_modules' => array(), 169 | 'gd_info' => \$gd_info, 170 | 'imagick_info' => \$imagick_info, 171 | 'mysql_version' => trim( shell_exec( 'mysql --version' ) ), 172 | 'system_utils' => array(), 173 | 'os_name' => trim( shell_exec( 'uname -s' ) ), 174 | 'os_version' => trim( shell_exec( 'uname -r' ) ), 175 | ); 176 | \$php_modules = array( 177 | 'bcmath', 178 | 'ctype', 179 | 'curl', 180 | 'date', 181 | 'dom', 182 | 'exif', 183 | 'fileinfo', 184 | 'filter', 185 | 'ftp', 186 | 'gd', 187 | 'gettext', 188 | 'gmagick', 189 | 'hash', 190 | 'iconv', 191 | 'imagick', 192 | 'imap', 193 | 'intl', 194 | 'json', 195 | 'libsodium', 196 | 'libxml', 197 | 'mbstring', 198 | 'mcrypt', 199 | 'mod_xml', 200 | 'mysqli', 201 | 'mysqlnd', 202 | 'openssl', 203 | 'pcre', 204 | 'pdo_mysql', 205 | 'soap', 206 | 'sockets', 207 | 'sodium', 208 | 'xml', 209 | 'xmlreader', 210 | 'zip', 211 | 'zlib', 212 | ); 213 | foreach( \$php_modules as \$php_module ) { 214 | \$env['php_modules'][ \$php_module ] = phpversion( \$php_module ); 215 | } 216 | function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_version', 'libz_version')); } 217 | \$curl_bits = curl_version(); 218 | \$env['system_utils']['curl'] = implode(' ',array_values(array_filter(\$curl_bits, 'curl_selected_bits',ARRAY_FILTER_USE_KEY) )); 219 | if ( class_exists( 'Imagick' ) ) { 220 | \$imagick = new Imagick(); 221 | \$version = \$imagick->getVersion(); 222 | preg_match( '/Magick (\d+\.\d+\.\d+-\d+|\d+\.\d+\.\d+|\d+\.\d+\-\d+|\d+\.\d+)/', \$version['versionString'], \$version ); 223 | \$env['system_utils']['imagemagick'] = \$version[1]; 224 | } elseif ( class_exists( 'Gmagick' ) ) { 225 | \$gmagick = new Gmagick(); 226 | \$version = \$gmagick->getversion(); 227 | preg_match( '/Magick (\d+\.\d+\.\d+-\d+|\d+\.\d+\.\d+|\d+\.\d+\-\d+|\d+\.\d+)/', \$version['versionString'], \$version ); 228 | \$env['system_utils']['graphicsmagick'] = \$version[1]; 229 | } 230 | \$env['system_utils']['openssl'] = str_replace( 'OpenSSL ', '', trim( shell_exec( 'openssl version' ) ) ); 231 | //\$mysqli = new mysqli( WPT_DB_HOST, WPT_DB_USER, WPT_DB_PASSWORD, WPT_DB_NAME ); 232 | //\$env['mysql_version'] = \$mysqli->query("SELECT VERSION()")->fetch_row()[0]; 233 | //\$mysqli->close(); 234 | file_put_contents( __DIR__ . '/tests/phpunit/build/logs/env.json', json_encode( \$env, JSON_PRETTY_PRINT ) ); 235 | if ( 'cli' === php_sapi_name() && defined( 'WP_INSTALLING' ) && WP_INSTALLING ) { 236 | echo PHP_EOL; 237 | echo 'PHP version: ' . phpversion() . ' (' . realpath( \$_SERVER['_'] ) . ')' . PHP_EOL; 238 | echo PHP_EOL; 239 | } 240 | EOT; 241 | 242 | // Initialize a string that will be used to identify the database settings section in the configuration file. 243 | $logger_replace_string = '// ** Database settings ** //' . PHP_EOL; 244 | 245 | // Prepend the logger script to the database settings identifier to ensure it gets included in the wp-tests-config.php file. 246 | $system_logger = $logger_replace_string . $system_logger; 247 | 248 | // Define a string that will set the 'WP_PHP_BINARY' constant to the path of the PHP executable. 249 | $php_binary_string = 'define( \'WP_PHP_BINARY\', \''. $WPT_PHP_EXECUTABLE . '\' );'; 250 | 251 | /** 252 | * An associative array mapping configuration file placeholders to environment-specific values. 253 | * This array is used in the subsequent str_replace operation to replace placeholders 254 | * in the wp-tests-config-sample.php file with values from the environment or defaults if none are provided. 255 | */ 256 | $search_replace = array( 257 | 'wptests_' => trim( getenv( 'WPT_TABLE_PREFIX' ) ) ? : 'wptests_', 258 | 'youremptytestdbnamehere' => trim( getenv( 'WPT_DB_NAME' ) ), 259 | 'yourusernamehere' => trim( getenv( 'WPT_DB_USER' ) ), 260 | 'yourpasswordhere' => trim( getenv( 'WPT_DB_PASSWORD' ) ), 261 | 'localhost' => trim( getenv( 'WPT_DB_HOST' ) ), 262 | 'define( \'WP_PHP_BINARY\', \'php\' );' => $php_binary_string, 263 | $logger_replace_string => $system_logger, 264 | ); 265 | 266 | // Replace the placeholders in the wp-tests-config-sample.php file content with actual values. 267 | $contents = str_replace( array_keys( $search_replace ), array_values( $search_replace ), $contents ); 268 | 269 | // Write the modified content to the wp-tests-config.php file, which will be used by the test suite. 270 | file_put_contents( $WPT_PREPARE_DIR . '/wp-tests-config.php', $contents ); 271 | 272 | /** 273 | * Determines the PHP version of the test environment to ensure the correct version of PHPUnit is installed. 274 | * It constructs a command that prints out the PHP version in a format compatible with PHPUnit's version requirements. 275 | */ 276 | $php_version_cmd = $WPT_PHP_EXECUTABLE . " -r \"print PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;\""; 277 | 278 | /** 279 | * If an SSH connection string is provided, the command to determine the PHP version is modified 280 | * to execute remotely over SSH. This is required if the test environment is not the local machine. 281 | */ 282 | if ( ! empty( $WPT_SSH_CONNECT ) ) { 283 | // The PHP version check command is prefixed with the SSH command, including SSH options, 284 | // and the connection string, ensuring the command is executed on the remote machine. 285 | $php_version_cmd = 'ssh ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' ' . escapeshellarg( $php_version_cmd ); 286 | } 287 | 288 | // Initialize return value variable for the exec function call. 289 | $retval = 0; 290 | 291 | /** 292 | * Executes the constructed command to obtain the PHP version of the test environment. 293 | * The output is stored in $env_php_version, and the return value of the command execution is stored in $retval. 294 | */ 295 | $env_php_version = exec( $php_version_cmd, $output, $retval ); 296 | 297 | // Check if the command execution was successful by inspecting the return value. 298 | if ( $retval !== 0 ) { 299 | // If the return value is not zero, an error occurred, and a message is logged. 300 | error_message( 'Could not retrieve the environment PHP Version.' ); 301 | } 302 | 303 | // Log the obtained PHP version for confirmation and debugging purposes. 304 | log_message( 'Environment PHP Version: ' . $env_php_version ); 305 | 306 | /** 307 | * Checks if the detected PHP version is below 7.0. 308 | * The test runner requires PHP version 7.0 or above, and if the environment's PHP version 309 | * is lower, it logs an error message and could terminate the script. 310 | */ 311 | if ( version_compare( $env_php_version, '7.0', '<' ) ) { 312 | // Logs an error message indicating the test runner's incompatibility with PHP versions below 7.0. 313 | error_message( 'The test runner is not compatible with PHP < 7.0.' ); 314 | } 315 | 316 | /** 317 | * Use Composer to manage PHPUnit and its dependencies. 318 | * This allows for better dependency management and compatibility. 319 | */ 320 | 321 | // Check if Composer is installed and available in the PATH. 322 | $composer_cmd = 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . ' && '; 323 | $retval = 0; 324 | $composer_path = escapeshellarg( system( 'which composer', $retval ) ); 325 | 326 | if ( $retval === 0 ) { 327 | 328 | // If Composer is available, prepare the command to use the Composer binary. 329 | $composer_cmd .= $composer_path . ' '; 330 | 331 | } else { 332 | 333 | // If Composer is not available, download the Composer phar file. 334 | log_message( 'Local Composer not found. Downloading latest stable ...' ); 335 | 336 | perform_operations( array( 337 | 'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/composer.phar' ) . ' https://getcomposer.org/composer-stable.phar', 338 | ) ); 339 | 340 | // Update the command to use the downloaded Composer phar file. 341 | $composer_cmd .= 'php composer.phar '; 342 | } 343 | 344 | // Set the PHP version for Composer to ensure compatibility and update dependencies. 345 | perform_operations( array( 346 | $composer_cmd . 'config platform.php ' . escapeshellarg( $env_php_version ), 347 | $composer_cmd . 'update', 348 | ) ); 349 | 350 | /** 351 | * If an SSH connection is configured, use rsync to transfer the prepared files to the remote test environment. 352 | * The -r option for rsync enables recursive copying to handle directory structures. 353 | * Additional rsync options may be included for more verbose output if debugging is enabled. 354 | */ 355 | if ( ! empty( $WPT_SSH_CONNECT ) ) { 356 | // Initialize rsync options with recursive copying. 357 | $rsync_options = '-r'; 358 | 359 | // If debug mode is set to verbose, append 'v' to rsync options for verbose output. 360 | if ( 'verbose' === $WPT_DEBUG ) { 361 | $rsync_options = $rsync_options . 'v'; 362 | } 363 | 364 | // Perform the rsync operation with the configured options and exclude patterns. 365 | // This operation synchronizes the test environment with the prepared files, excluding version control directories 366 | // and other non-essential files for test execution. 367 | perform_operations( array( 368 | 'rsync ' . $rsync_options . ' --exclude=".git/" --exclude="node_modules/" --exclude="composer.phar" -e "ssh ' . $WPT_SSH_OPTIONS . '" ' . escapeshellarg( trailingslashit( $WPT_PREPARE_DIR ) ) . ' ' . escapeshellarg( $WPT_SSH_CONNECT . ':' . $WPT_TEST_DIR ), 369 | ) ); 370 | } 371 | 372 | // Log a success message indicating that the environment has been prepared. 373 | log_message( 'Success: Prepared environment.' ); 374 | -------------------------------------------------------------------------------- /report.php: -------------------------------------------------------------------------------- 1 |