Skip to content

Commit 2a5c3e3

Browse files
authored
Merge branch 'PHPCSStandards:master' into DocXMLSquizClassesClassDeclaration
2 parents 05b23e9 + 038b4a1 commit 2a5c3e3

File tree

462 files changed

+12469
-2008
lines changed

Some content is hidden

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

462 files changed

+12469
-2008
lines changed

.github/CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,14 @@ To run the tests specific to the use of `PHP_CODESNIFFER_CBF === true`:
376376
vendor/bin/phpunit --group CBF --exclude-group nothing
377377
```
378378

379+
#### Other notes about writing tests
380+
381+
* The `Config` class uses a number of static properties and can have a performance impact on the tests too.
382+
To get round both these issues, use the `ConfigDouble` class instead.
383+
Generally speaking, only tests which test the behaviour of the `Config` class itself where it relates to the static properties, should use the real `Config` class for testing.
384+
In such cases, the `PHP_CodeSniffer\Tests\Core\Config\AbstractRealConfigTestCase` should be used as the base test class.
385+
* Tests for the `Runner` class often can't create their own `Config` object in the tests, so run into the same issue.
386+
Those tests should use the `PHP_CodeSniffer\Tests\Core\Runner\AbstractRunnerTestCase` base class, which will ensure the Config is clean.
379387

380388
### Submitting Your Pull Request
381389

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ A clear and concise description of what you expected to happen.
5151

5252
## Versions (please complete the following information)
5353

54-
| | |
55-
|--------------------------|---------------------------------------------------------------------- |
56-
| Operating System | [e.g., Windows 10, MacOS 10.15] |
57-
| PHP version | [e.g., 7.2, 8.1] |
58-
| PHP_CodeSniffer version | [e.g., 3.7.2, master] |
59-
| Standard | [e.g., PSR2, PSR12, Squiz, custom] |
60-
| Install type | [e.g. Composer (global/local), PHAR, git clone, other (please expand)] |
54+
| | |
55+
|-----------------------------|---------------------------------------------------------------------------- |
56+
| Operating System | (e.g., Windows 10, MacOS 10.15) |
57+
| PHP version | (e.g., 7.2, 8.1) |
58+
| PHP_CodeSniffer version | (e.g., 3.7.2, master) |
59+
| Standard | (e.g., PSR2, PSR12, Squiz, custom) |
60+
| Install type | (e.g. Composer (global/local), PHAR, git clone, other (please expand)) |
6161

6262
## Additional context
6363

.github/labeler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ labels:
55
draft: false
66
author-can-merge: false
77

8-
- label: "Core Component: Config & Ruleset & CLI options"
8+
- label: "Core Component: Config & CLI options"
99
draft: false
1010
files:
1111
- "src/Config.php$"
12-
- label: "Core Component: Config & Ruleset & CLI options"
12+
- label: "Core Component: Ruleset"
1313
draft: false
1414
files:
1515
- "src/Ruleset.php$"

.github/workflows/build-phar.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
push:
77
branches:
88
- master
9+
- 4.0
910
paths:
1011
- '.github/workflows/build-phar.yml'
1112
- '.github/workflows/reusable-build-phar.yml'

.github/workflows/label-remove-outdated.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
pull_request_target:
99
types:
1010
- closed
11+
- review_requested
1112

1213
jobs:
1314
on-issue-close:
@@ -27,6 +28,19 @@ jobs:
2728
Status: needs investigation
2829
Status: triage
2930
31+
on-pr-review-request:
32+
runs-on: ubuntu-latest
33+
if: github.repository_owner == 'PHPCSStandards' && github.event.action == 'review_requested'
34+
35+
name: "Clean up labels on PR (re-)review request"
36+
37+
steps:
38+
- uses: mondeja/remove-labels-gh-action@v2
39+
with:
40+
token: ${{ secrets.GITHUB_TOKEN }}
41+
labels: |
42+
Status: awaiting feedback
43+
3044
on-pr-merge:
3145
runs-on: ubuntu-latest
3246
if: github.repository_owner == 'PHPCSStandards' && github.event.pull_request.merged == true
@@ -48,7 +62,8 @@ jobs:
4862
4963
on-pr-close:
5064
runs-on: ubuntu-latest
51-
if: github.repository_owner == 'PHPCSStandards' && github.event_name == 'pull_request_target' && github.event.pull_request.merged == false
65+
# yamllint disable-line rule:line-length
66+
if: github.repository_owner == 'PHPCSStandards' && github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == false
5267

5368
name: Clean up labels on PR close
5469

.github/workflows/quicktest.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: Quicktest
22

33
on:
4-
# Run on pushes to all branches except for `master`.
4+
# Run on pushes to all branches except for `master`/`4.0`.
55
push:
66
branches-ignore:
77
- master
8+
- 4.0
89
paths-ignore:
910
- '**.md'
1011
# Allow manually triggering the workflow.

.github/workflows/test.yml

Lines changed: 120 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: Test
22

33
on:
4-
# Run on pushes to `master` and on all pull requests.
4+
# Run on pushes to `master`/`4.0` and on all pull requests.
55
# Prevent the build from running when there are only irrelevant changes.
66
push:
77
branches:
88
- master
9+
- 4.0
910
tags:
1011
- '**'
1112
paths-ignore:
@@ -44,7 +45,7 @@ jobs:
4445
group: ${{ github.workflow }}-${{ github.job }}-${{ strategy.job-index }}-${{ github.ref }}
4546
cancel-in-progress: true
4647

47-
runs-on: ubuntu-latest
48+
runs-on: ${{ matrix.os }}
4849
needs: build
4950

5051
strategy:
@@ -60,6 +61,11 @@ jobs:
6061
# Installing on Windows with PHP 5.4 runs into all sorts of problems (which are not ours).
6162
- php: '5.4'
6263
os: 'windows-latest'
64+
# By default, the memory limit should be disabled with setup_php, but we're still running
65+
# into memory limit issues when the full test suite is run on PHP 5.6 in Windows.
66+
# As support for PHP < 7.2 will be dropped in PHPCS 4.0 anyhow, let's just skip the build.
67+
- php: '5.6'
68+
os: 'windows-latest'
6369

6470
include:
6571
# Skip test runs on builds which are also run in the coverage job.
@@ -73,16 +79,33 @@ jobs:
7379
- php: '8.4'
7480
skip_tests: true
7581

82+
# The default libxml library on Ubuntu images is a little out of date.
83+
# To safeguard support for the latest libxml we need to update the library on the fly.
84+
# This only needs to be tested with one PHP version for each libxml minor to verify support.
85+
# Testing against multiple PHP versions would not yield a difference in results.
86+
- php: '8.0'
87+
os: 'ubuntu-latest'
88+
libxml_minor: '2.11'
89+
- php: '8.3'
90+
os: 'ubuntu-latest'
91+
libxml_minor: '2.13'
92+
7693
# Extra builds running only the unit tests with different PHP ini settings.
7794
- php: '5.5'
7895
os: 'ubuntu-latest'
7996
custom_ini: true
8097
- php: '7.0'
8198
os: 'ubuntu-latest'
8299
custom_ini: true
100+
- php: '8.0'
101+
os: 'ubuntu-latest'
102+
custom_ini: true
103+
- php: '8.2'
104+
os: 'ubuntu-latest'
105+
custom_ini: true
83106

84107
# yamllint disable-line rule:line-length
85-
name: "PHP: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }} (${{ matrix.os == 'ubuntu-latest' && 'Linux' || 'Win' }})"
108+
name: "PHP: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }}${{ matrix.libxml_minor && format( ' with libxml {0}', matrix.libxml_minor ) || '' }} (${{ matrix.os == 'ubuntu-latest' && 'Linux' || 'Win' }})"
86109

87110
continue-on-error: ${{ matrix.php == '8.5' }}
88111

@@ -93,6 +116,70 @@ jobs:
93116
- name: Checkout code
94117
uses: actions/checkout@v4
95118

119+
- name: "libxml2: find the latest relevant tag"
120+
if: ${{ matrix.libxml_minor }}
121+
id: libxml_version
122+
uses: oprypin/find-latest-tag@v1
123+
with:
124+
repository: GNOME/libxml2
125+
releases-only: false # The libxml2 repository doesn't use GitHub's "release" feature.
126+
prefix: 'v${{ matrix.libxml_minor }}.' # Limit the result to the minor we're interested in.
127+
sort-tags: true # Find the "greatest" version for that minor based on semver.
128+
129+
# To put it simply: we need to remove the 'v' prefix from the version number.
130+
- name: "libxml2: parse the version to a patch version"
131+
if: ${{ matrix.libxml_minor }}
132+
id: libxml_patch_version
133+
shell: bash
134+
env:
135+
TAG: ${{ steps.libxml_version.outputs.tag }}
136+
run: echo "PATCH=$( echo "$TAG" | cut -b 2- )" >> "$GITHUB_OUTPUT"
137+
138+
- name: "libxml2: restore cache"
139+
if: ${{ matrix.libxml_minor }}
140+
id: libxml_cache_restore
141+
uses: actions/cache/restore@v4
142+
with:
143+
path: "libxml2-${{ steps.libxml_patch_version.outputs.PATCH }}"
144+
key: "${{ matrix.os }}-libxml-${{ matrix.libxml_minor }}-${{ steps.libxml_patch_version.outputs.PATCH }}"
145+
146+
# Updating the lists can fail intermittently, typically after Microsoft has released a new package.
147+
# This should not be blocking for this job, so ignore any errors from this step.
148+
# Ref: https://github.com/dotnet/core/issues/4167
149+
- name: "libxml2: Update the available packages list"
150+
if: ${{ matrix.libxml_minor && steps.libxml_cache_restore.outputs.cache-hit != 'true' }}
151+
continue-on-error: true
152+
run: sudo apt-get update
153+
154+
- name: "libxml2: Download and build package (linux only)"
155+
if: ${{ matrix.libxml_minor && steps.libxml_cache_restore.outputs.cache-hit != 'true' }}
156+
env:
157+
PATCH: ${{ steps.libxml_patch_version.outputs.PATCH }}
158+
run: |
159+
sudo apt-get install -y wget build-essential
160+
wget "https://download.gnome.org/sources/libxml2/${{ matrix.libxml_minor }}/libxml2-$PATCH.tar.xz"
161+
tar -xf "libxml2-$PATCH.tar.xz"
162+
cd "libxml2-$PATCH"
163+
./configure --prefix=/usr/local
164+
make
165+
166+
- name: "libxml2: save cache"
167+
if: ${{ matrix.libxml_minor && steps.libxml_cache_restore.outputs.cache-hit != 'true' }}
168+
id: libxml_cache_save
169+
uses: actions/cache/save@v4
170+
with:
171+
path: "libxml2-${{ steps.libxml_patch_version.outputs.PATCH }}"
172+
key: ${{ steps.libxml_cache_restore.outputs.cache-primary-key }}
173+
174+
- name: "libxml2: Install package (linux only)"
175+
if: ${{ matrix.libxml_minor }}
176+
env:
177+
PATCH: ${{ steps.libxml_patch_version.outputs.PATCH }}
178+
run: |
179+
cd "libxml2-$PATCH"
180+
sudo make install
181+
sudo ldconfig
182+
96183
- name: Setup ini config
97184
id: set_ini
98185
shell: bash
@@ -101,7 +188,7 @@ jobs:
101188
# Also turn on error_reporting to ensure all notices are shown.
102189
if [[ ${{ matrix.custom_ini }} == true && "${{ matrix.php }}" == '5.5' ]]; then
103190
echo 'PHP_INI=error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On, asp_tags=On' >> "$GITHUB_OUTPUT"
104-
elif [[ ${{ matrix.custom_ini }} == true && "${{ matrix.php }}" == '7.0' ]]; then
191+
elif [[ ${{ matrix.custom_ini }} == true && "${{ matrix.php }}" != '5.5' ]]; then
105192
echo 'PHP_INI=error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On' >> "$GITHUB_OUTPUT"
106193
else
107194
echo 'PHP_INI=error_reporting=-1, display_errors=On' >> "$GITHUB_OUTPUT"
@@ -113,7 +200,9 @@ jobs:
113200
php-version: ${{ matrix.php }}
114201
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
115202
coverage: none
116-
tools: cs2pr
203+
204+
- name: "DEBUG: show libxml loaded version (php)"
205+
run: php -r 'echo "libxml loaded version = ", LIBXML_LOADED_VERSION, PHP_EOL;'
117206

118207
# This action also handles the caching of the dependencies.
119208
- name: Set up node
@@ -135,37 +224,35 @@ jobs:
135224
- name: Install Composer dependencies
136225
uses: "ramsey/composer-install@v3"
137226
with:
138-
composer-options: ${{ matrix.php == '8.5' && '--ignore-platform-req=php' || '' }}
227+
composer-options: ${{ matrix.php == '8.5' && '--ignore-platform-req=php+' || '' }}
139228
custom-cache-suffix: $(date -u "+%Y-%m")
140229

141-
# Note: The code style check is run multiple times against every PHP version
142-
# as it also acts as an integration test.
143230
- name: 'PHPCS: set the path to PHP'
144231
run: php "bin/phpcs" --config-set php_path php
145232

146233
- name: 'PHPUnit: run the full test suite without code coverage'
147234
if: ${{ matrix.skip_tests != true }}
148235
run: php "vendor/bin/phpunit" tests/AllTests.php --no-coverage
149236

237+
# Do one test run against the complete test suite in CBF mode to ensure all tests can run in CBF mode.
238+
- name: 'PHPUnit: run the full test suite without code coverage in CBF mode (PHP 8.3 only)'
239+
if: ${{ matrix.php == '8.3' }}
240+
run: php "vendor/bin/phpunit" tests/AllTests.php --exclude-group nothing --no-coverage
241+
env:
242+
PHP_CODESNIFFER_CBF: '1'
243+
150244
- name: 'PHPUnit: run select tests in CBF mode'
151-
if: ${{ matrix.skip_tests != true }}
245+
if: ${{ matrix.skip_tests != true && matrix.php != '8.3' }}
152246
run: php "vendor/bin/phpunit" tests/AllTests.php --group CBF --exclude-group nothing --no-coverage
153247
env:
154248
PHP_CODESNIFFER_CBF: '1'
155249

250+
# Note: The code style check is run multiple times against every PHP version
251+
# as it also acts as an integration test.
156252
- name: 'PHPCS: check code style without cache, no parallel'
157-
if: ${{ matrix.custom_ini == false && matrix.php != '7.4' }}
253+
if: ${{ matrix.custom_ini == false }}
158254
run: php "bin/phpcs" --no-cache --parallel=1
159255

160-
- name: 'PHPCS: check code style to show results in PR'
161-
if: ${{ matrix.custom_ini == false && matrix.php == '7.4' }}
162-
id: phpcs
163-
run: php "bin/phpcs" --no-cache --parallel=1 --report-full --report-checkstyle=./phpcs-report.xml
164-
165-
- name: Show PHPCS results in PR
166-
if: ${{ always() && steps.phpcs.outcome == 'failure' && matrix.php == '7.4' }}
167-
run: cs2pr ./phpcs-report.xml
168-
169256
- name: Download the PHPCS phar
170257
if: ${{ matrix.custom_ini == false }}
171258
uses: actions/download-artifact@v4
@@ -216,14 +303,12 @@ jobs:
216303
uses: actions/checkout@v4
217304

218305
- name: Setup ini config
219-
if: ${{ matrix.os != 'windows-latest' }}
306+
if: ${{ matrix.custom_ini == true && matrix.os != 'windows-latest' }}
220307
id: set_ini
221308
shell: bash
222309
run: |
223310
# Set the "short_open_tag" ini to make sure specific conditions are tested.
224-
if [[ ${{ matrix.custom_ini }} == true && "${{ matrix.php }}" == '7.2' ]]; then
225-
echo 'PHP_INI=, date.timezone=Australia/Sydney, short_open_tag=On' >> "$GITHUB_OUTPUT"
226-
fi
311+
echo 'PHP_INI=, date.timezone=Australia/Sydney, short_open_tag=On' >> "$GITHUB_OUTPUT"
227312
228313
- name: Install PHP
229314
uses: shivammathur/setup-php@v2
@@ -275,37 +360,26 @@ jobs:
275360
if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }}
276361
run: php "vendor/bin/phpunit" --coverage-cache ./build/phpunit-cache --warm-coverage-cache
277362

278-
- name: "Run the unit tests with code coverage (PHPUnit < 9.3)"
279-
if: ${{ matrix.os != 'windows-latest' && steps.phpunit_version.outputs.VERSION < '9.3' }}
280-
run: php "vendor/bin/phpunit" tests/AllTests.php
281-
282-
- name: "Run the unit tests with code coverage (PHPUnit 9.3+)"
283-
if: ${{ matrix.os != 'windows-latest' && steps.phpunit_version.outputs.VERSION >= '9.3' }}
284-
run: php "vendor/bin/phpunit" tests/AllTests.php --coverage-cache ./build/phpunit-cache
285-
286-
- name: "Run select tests in CBF mode with code coverage (PHPUnit < 9.3)"
287-
if: ${{ matrix.os != 'windows-latest' && steps.phpunit_version.outputs.VERSION < '9.3' }}
363+
- name: "Run the unit tests with code coverage"
364+
if: ${{ matrix.os != 'windows-latest' }}
288365
run: >
289366
php "vendor/bin/phpunit" tests/AllTests.php
290-
--group CBF --exclude-group nothing --coverage-clover build/logs/clover-cbf.xml
291-
env:
292-
PHP_CODESNIFFER_CBF: '1'
367+
${{ steps.phpunit_version.outputs.VERSION >= '9.3' && '--coverage-cache ./build/phpunit-cache' || '' }}
293368
294-
- name: "Run select tests in CBF mode with code coverage (PHPUnit 9.3+)"
295-
if: ${{ matrix.os != 'windows-latest' && steps.phpunit_version.outputs.VERSION >= '9.3' }}
369+
- name: "Run select tests in CBF mode with code coverage"
370+
if: ${{ matrix.os != 'windows-latest' }}
296371
run: >
297-
php "vendor/bin/phpunit" tests/AllTests.php --coverage-cache ./build/phpunit-cache
372+
php "vendor/bin/phpunit" tests/AllTests.php
373+
${{ steps.phpunit_version.outputs.VERSION >= '9.3' && '--coverage-cache ./build/phpunit-cache' || '' }}
298374
--group CBF --exclude-group nothing --coverage-clover build/logs/clover-cbf.xml
299375
env:
300376
PHP_CODESNIFFER_CBF: '1'
301377

302-
- name: "Run the unit tests which may have different outcomes on Windows with code coverage (PHPUnit < 9.3)"
303-
if: ${{ matrix.os == 'windows-latest' && steps.phpunit_version.outputs.VERSION < '9.3' }}
304-
run: php "vendor/bin/phpunit" tests/AllTests.php --group Windows
305-
306-
- name: "Run the unit tests which may have different outcomes on Windows with code coverage (PHPUnit 9.3+)"
307-
if: ${{ matrix.os == 'windows-latest' && steps.phpunit_version.outputs.VERSION >= '9.3' }}
308-
run: php "vendor/bin/phpunit" tests/AllTests.php --group Windows --coverage-cache ./build/phpunit-cache
378+
- name: "Run the unit tests which may have different outcomes on Windows with code coverage"
379+
if: ${{ matrix.os == 'windows-latest' }}
380+
run: >
381+
php "vendor/bin/phpunit" tests/AllTests.php --group Windows
382+
${{ steps.phpunit_version.outputs.VERSION >= '9.3' && '--coverage-cache ./build/phpunit-cache' || '' }}
309383
310384
- name: "Upload coverage results to Coveralls (normal run)"
311385
if: ${{ success() }}

0 commit comments

Comments
 (0)