Skip to content

Commit

Permalink
Merge pull request #162 from PHPCSStandards/feature/update-for-phpuni…
Browse files Browse the repository at this point in the history
…t-10-11

Tests: allow for running on PHPUnit 10/11
  • Loading branch information
jrfnl authored Sep 10, 2024
2 parents 96c9676 + dce691a commit 1faeaaa
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/phpcs.xml.dist export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/phpunitlte9.xml.dist export-ignore
/phpunit-bootstrap.php export-ignore
/PHPCSDebug/Tests export-ignore
/Tests export-ignore
Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/quicktest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,22 @@ jobs:
if: ${{ matrix.phpcs_version == 'dev-master' }}
run: composer check-complete

- name: Grab PHPUnit version
id: phpunit_version
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT

- name: Determine PHPUnit composer script to use
id: phpunit_script
run: |
if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) || startsWith( steps.phpunit_version.outputs.VERSION, '11.' ) }}" == "true" ]; then
echo 'SUFFIX=' >> $GITHUB_OUTPUT
else
echo 'SUFFIX=-lte9' >> $GITHUB_OUTPUT
fi
- name: Run the unit tests for the PHPCSDebug sniff
run: composer test-sniff
run: composer test-sniff${{ steps.phpunit_script.outputs.SUFFIX }}

- name: Run the unit tests for the DevTools
if: ${{ matrix.phpcs_version == 'dev-master' }}
run: composer test-tools
run: composer test-tools${{ steps.phpunit_script.outputs.SUFFIX }}
17 changes: 15 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,22 @@ jobs:
if: matrix.phpcs_version == 'dev-master'
run: composer check-complete

- name: Grab PHPUnit version
id: phpunit_version
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT

- name: Determine PHPUnit composer script to use
id: phpunit_script
run: |
if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) || startsWith( steps.phpunit_version.outputs.VERSION, '11.' ) }}" == "true" ]; then
echo 'SUFFIX=' >> $GITHUB_OUTPUT
else
echo 'SUFFIX=-lte9' >> $GITHUB_OUTPUT
fi
- name: Run the unit tests for the PHPCSDebug sniff
run: composer test-sniff
run: composer test-sniff${{ steps.phpunit_script.outputs.SUFFIX }}

- name: Run the unit tests for the DevTools
if: ${{ matrix.phpcs_version == 'dev-master' }}
run: composer test-tools
run: composer test-tools${{ steps.phpunit_script.outputs.SUFFIX }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
build/
deploy/
vendor/
composer.lock
.phpcs.xml
phpcs.xml
phpunit.xml
phpunitlte9.xml
.phpunit.result.cache
phpstan.neon
9 changes: 6 additions & 3 deletions PHPCSDebug/Tests/Debug/TokenListCssTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ public function testOutput()

EOD;

$this->expectOutputString($expected);
$this->setOutputCallback([$this, 'normalizeLineEndings']);

if (empty(self::$phpcsFile->ruleset->tokenListeners)) {
// PHPCSUtils 1.0.9+.
$sniffFile = \dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'Sniffs';
Expand All @@ -127,7 +124,13 @@ public function testOutput()
self::$phpcsFile->ruleset->populateTokenListeners();
}

\ob_start();
self::$phpcsFile->process();

$output = \ob_get_contents();
\ob_end_clean();

$this->assertSame($expected, $this->normalizeLineEndings($output));
}

/**
Expand Down
9 changes: 6 additions & 3 deletions PHPCSDebug/Tests/Debug/TokenListJsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ public function testOutput()

EOD;

$this->expectOutputString($expected);
$this->setOutputCallback([$this, 'normalizeLineEndings']);

if (empty(self::$phpcsFile->ruleset->tokenListeners)) {
// PHPCSUtils 1.0.9+.
$sniffFile = \dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'Sniffs';
Expand All @@ -147,7 +144,13 @@ public function testOutput()
self::$phpcsFile->ruleset->populateTokenListeners();
}

\ob_start();
self::$phpcsFile->process();

$output = \ob_get_contents();
\ob_end_clean();

$this->assertSame($expected, $this->normalizeLineEndings($output));
}

/**
Expand Down
9 changes: 6 additions & 3 deletions PHPCSDebug/Tests/Debug/TokenListUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ public function testOutput()

EOD;

$this->expectOutputString($expected);
$this->setOutputCallback([$this, 'normalizeLineEndings']);

if (empty(self::$phpcsFile->ruleset->tokenListeners)) {
// PHPCSUtils 1.0.9+.
$sniffFile = \dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'Sniffs';
Expand All @@ -120,7 +117,13 @@ public function testOutput()
self::$phpcsFile->ruleset->populateTokenListeners();
}

\ob_start();
self::$phpcsFile->process();

$output = \ob_get_contents();
\ob_end_clean();

$this->assertSame($expected, $this->normalizeLineEndings($output));
}

/**
Expand Down
13 changes: 11 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
},
"require-dev" : {
"roave/security-advisories" : "dev-master",
"phpunit/phpunit" : "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit" : "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.5.32 || ^11.3.3",
"php-parallel-lint/php-parallel-lint": "^1.4.0",
"php-parallel-lint/php-console-highlighter": "^1.0.0",
"phpcsstandards/phpcsdevcs": "^1.1.6",
"phpcsstandards/phpcsutils" : "^1.0",
"yoast/phpunit-polyfills": "^1.1"
"yoast/phpunit-polyfills": "^1.1 || ^2.0 || ^3.0"
},
"config": {
"allow-plugins": {
Expand Down Expand Up @@ -73,6 +73,15 @@
"test-tools": [
"@php ./vendor/phpunit/phpunit/phpunit --testsuite DevTools"
],
"test-lte9": [
"@php ./vendor/phpunit/phpunit/phpunit -c phpunitlte9.xml.dist"
],
"test-sniff-lte9": [
"@php ./vendor/phpunit/phpunit/phpunit -c phpunitlte9.xml.dist --testsuite DebugSniff"
],
"test-tools-lte9": [
"@php ./vendor/phpunit/phpunit/phpunit -c phpunitlte9.xml.dist --testsuite DevTools"
],
"check-complete": [
"@php ./bin/phpcs-check-feature-completeness ./PHPCSDebug"
]
Expand Down
29 changes: 19 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
backupGlobals="true"
bootstrap="./phpunit-bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="false"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
colors="true"
forceCoversAnnotation="true">
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="true"
bootstrap="./phpunit-bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="false"
cacheDirectory="build/phpunit-cache"
colors="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnPhpunitDeprecations="false"
failOnWarning="true"
failOnNotice="true"
failOnDeprecation="true"
failOnPhpunitDeprecation="false"
requireCoverageMetadata="true"
>

<testsuites>
<testsuite name="DebugSniff">
Expand Down
23 changes: 23 additions & 0 deletions phpunitlte9.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
backupGlobals="true"
bootstrap="./phpunit-bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="false"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
colors="true"
forceCoversAnnotation="true">

<testsuites>
<testsuite name="DebugSniff">
<directory suffix="Test.php">./PHPCSDebug/Tests/</directory>
</testsuite>
<testsuite name="DevTools">
<directory suffix="Test.php">./Tests/DocsXsd/</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit 1faeaaa

Please sign in to comment.