Skip to content

Commit 1faeaaa

Browse files
authored
Merge pull request #162 from PHPCSStandards/feature/update-for-phpunit-10-11
Tests: allow for running on PHPUnit 10/11
2 parents 96c9676 + dce691a commit 1faeaaa

10 files changed

+104
-25
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/phpcs.xml.dist export-ignore
1212
/phpstan.neon.dist export-ignore
1313
/phpunit.xml.dist export-ignore
14+
/phpunitlte9.xml.dist export-ignore
1415
/phpunit-bootstrap.php export-ignore
1516
/PHPCSDebug/Tests export-ignore
1617
/Tests export-ignore

.github/workflows/quicktest.yml

+15-2
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,22 @@ jobs:
9696
if: ${{ matrix.phpcs_version == 'dev-master' }}
9797
run: composer check-complete
9898

99+
- name: Grab PHPUnit version
100+
id: phpunit_version
101+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
102+
103+
- name: Determine PHPUnit composer script to use
104+
id: phpunit_script
105+
run: |
106+
if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) || startsWith( steps.phpunit_version.outputs.VERSION, '11.' ) }}" == "true" ]; then
107+
echo 'SUFFIX=' >> $GITHUB_OUTPUT
108+
else
109+
echo 'SUFFIX=-lte9' >> $GITHUB_OUTPUT
110+
fi
111+
99112
- name: Run the unit tests for the PHPCSDebug sniff
100-
run: composer test-sniff
113+
run: composer test-sniff${{ steps.phpunit_script.outputs.SUFFIX }}
101114

102115
- name: Run the unit tests for the DevTools
103116
if: ${{ matrix.phpcs_version == 'dev-master' }}
104-
run: composer test-tools
117+
run: composer test-tools${{ steps.phpunit_script.outputs.SUFFIX }}

.github/workflows/test.yml

+15-2
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,22 @@ jobs:
150150
if: matrix.phpcs_version == 'dev-master'
151151
run: composer check-complete
152152

153+
- name: Grab PHPUnit version
154+
id: phpunit_version
155+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
156+
157+
- name: Determine PHPUnit composer script to use
158+
id: phpunit_script
159+
run: |
160+
if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) || startsWith( steps.phpunit_version.outputs.VERSION, '11.' ) }}" == "true" ]; then
161+
echo 'SUFFIX=' >> $GITHUB_OUTPUT
162+
else
163+
echo 'SUFFIX=-lte9' >> $GITHUB_OUTPUT
164+
fi
165+
153166
- name: Run the unit tests for the PHPCSDebug sniff
154-
run: composer test-sniff
167+
run: composer test-sniff${{ steps.phpunit_script.outputs.SUFFIX }}
155168

156169
- name: Run the unit tests for the DevTools
157170
if: ${{ matrix.phpcs_version == 'dev-master' }}
158-
run: composer test-tools
171+
run: composer test-tools${{ steps.phpunit_script.outputs.SUFFIX }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
build/
12
deploy/
23
vendor/
34
composer.lock
45
.phpcs.xml
56
phpcs.xml
67
phpunit.xml
8+
phpunitlte9.xml
79
.phpunit.result.cache
810
phpstan.neon

PHPCSDebug/Tests/Debug/TokenListCssTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ public function testOutput()
113113

114114
EOD;
115115

116-
$this->expectOutputString($expected);
117-
$this->setOutputCallback([$this, 'normalizeLineEndings']);
118-
119116
if (empty(self::$phpcsFile->ruleset->tokenListeners)) {
120117
// PHPCSUtils 1.0.9+.
121118
$sniffFile = \dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'Sniffs';
@@ -127,7 +124,13 @@ public function testOutput()
127124
self::$phpcsFile->ruleset->populateTokenListeners();
128125
}
129126

127+
\ob_start();
130128
self::$phpcsFile->process();
129+
130+
$output = \ob_get_contents();
131+
\ob_end_clean();
132+
133+
$this->assertSame($expected, $this->normalizeLineEndings($output));
131134
}
132135

133136
/**

PHPCSDebug/Tests/Debug/TokenListJsTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ public function testOutput()
133133

134134
EOD;
135135

136-
$this->expectOutputString($expected);
137-
$this->setOutputCallback([$this, 'normalizeLineEndings']);
138-
139136
if (empty(self::$phpcsFile->ruleset->tokenListeners)) {
140137
// PHPCSUtils 1.0.9+.
141138
$sniffFile = \dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'Sniffs';
@@ -147,7 +144,13 @@ public function testOutput()
147144
self::$phpcsFile->ruleset->populateTokenListeners();
148145
}
149146

147+
\ob_start();
150148
self::$phpcsFile->process();
149+
150+
$output = \ob_get_contents();
151+
\ob_end_clean();
152+
153+
$this->assertSame($expected, $this->normalizeLineEndings($output));
151154
}
152155

153156
/**

PHPCSDebug/Tests/Debug/TokenListUnitTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ public function testOutput()
106106

107107
EOD;
108108

109-
$this->expectOutputString($expected);
110-
$this->setOutputCallback([$this, 'normalizeLineEndings']);
111-
112109
if (empty(self::$phpcsFile->ruleset->tokenListeners)) {
113110
// PHPCSUtils 1.0.9+.
114111
$sniffFile = \dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'Sniffs';
@@ -120,7 +117,13 @@ public function testOutput()
120117
self::$phpcsFile->ruleset->populateTokenListeners();
121118
}
122119

120+
\ob_start();
123121
self::$phpcsFile->process();
122+
123+
$output = \ob_get_contents();
124+
\ob_end_clean();
125+
126+
$this->assertSame($expected, $this->normalizeLineEndings($output));
124127
}
125128

126129
/**

composer.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
},
2929
"require-dev" : {
3030
"roave/security-advisories" : "dev-master",
31-
"phpunit/phpunit" : "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
31+
"phpunit/phpunit" : "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.5.32 || ^11.3.3",
3232
"php-parallel-lint/php-parallel-lint": "^1.4.0",
3333
"php-parallel-lint/php-console-highlighter": "^1.0.0",
3434
"phpcsstandards/phpcsdevcs": "^1.1.6",
3535
"phpcsstandards/phpcsutils" : "^1.0",
36-
"yoast/phpunit-polyfills": "^1.1"
36+
"yoast/phpunit-polyfills": "^1.1 || ^2.0 || ^3.0"
3737
},
3838
"config": {
3939
"allow-plugins": {
@@ -73,6 +73,15 @@
7373
"test-tools": [
7474
"@php ./vendor/phpunit/phpunit/phpunit --testsuite DevTools"
7575
],
76+
"test-lte9": [
77+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunitlte9.xml.dist"
78+
],
79+
"test-sniff-lte9": [
80+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunitlte9.xml.dist --testsuite DebugSniff"
81+
],
82+
"test-tools-lte9": [
83+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunitlte9.xml.dist --testsuite DevTools"
84+
],
7685
"check-complete": [
7786
"@php ./bin/phpcs-check-feature-completeness ./PHPCSDebug"
7887
]

phpunit.xml.dist

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
5-
backupGlobals="true"
6-
bootstrap="./phpunit-bootstrap.php"
7-
beStrictAboutTestsThatDoNotTestAnything="false"
8-
convertErrorsToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertDeprecationsToExceptions="true"
12-
colors="true"
13-
forceCoversAnnotation="true">
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
5+
backupGlobals="true"
6+
bootstrap="./phpunit-bootstrap.php"
7+
beStrictAboutTestsThatDoNotTestAnything="false"
8+
cacheDirectory="build/phpunit-cache"
9+
colors="true"
10+
displayDetailsOnTestsThatTriggerErrors="true"
11+
displayDetailsOnTestsThatTriggerWarnings="true"
12+
displayDetailsOnTestsThatTriggerNotices="true"
13+
displayDetailsOnTestsThatTriggerDeprecations="true"
14+
displayDetailsOnIncompleteTests="true"
15+
displayDetailsOnSkippedTests="true"
16+
displayDetailsOnPhpunitDeprecations="false"
17+
failOnWarning="true"
18+
failOnNotice="true"
19+
failOnDeprecation="true"
20+
failOnPhpunitDeprecation="false"
21+
requireCoverageMetadata="true"
22+
>
1423

1524
<testsuites>
1625
<testsuite name="DebugSniff">

phpunitlte9.xml.dist

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
5+
backupGlobals="true"
6+
bootstrap="./phpunit-bootstrap.php"
7+
beStrictAboutTestsThatDoNotTestAnything="false"
8+
convertErrorsToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertDeprecationsToExceptions="true"
12+
colors="true"
13+
forceCoversAnnotation="true">
14+
15+
<testsuites>
16+
<testsuite name="DebugSniff">
17+
<directory suffix="Test.php">./PHPCSDebug/Tests/</directory>
18+
</testsuite>
19+
<testsuite name="DevTools">
20+
<directory suffix="Test.php">./Tests/DocsXsd/</directory>
21+
</testsuite>
22+
</testsuites>
23+
</phpunit>

0 commit comments

Comments
 (0)