Skip to content

2.0 | Make tests compatible with PHPUnit 10 #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
# https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production
# https://blog.madewithlove.be/post/gitattributes/
#
.gitattributes export-ignore
.gitignore export-ignore
appveyor.yml export-ignore
box.json export-ignore
phpcs.xml.dist export-ignore
phpunit.xml.dist export-ignore
/.github/ export-ignore
/doc/ export-ignore
/tests/ export-ignore
.gitattributes export-ignore
.gitignore export-ignore
appveyor.yml export-ignore
box.json export-ignore
phpcs.xml.dist export-ignore
phpunit.xml.dist export-ignore
phpunit10.xml.dist export-ignore
/.github/ export-ignore
/doc/ export-ignore
/tests/ export-ignore

#
# Auto detect text files and perform LF normalization
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,18 @@ jobs:
- name: 'Integration test 2 - linting own code'
run: ./parallel-lint --exclude vendor --exclude tests/fixtures .

- name: 'Run unit tests'
- 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: "Run unit tests (PHPUnit < 10)"
if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
run: composer test

- name: "Run unit tests (PHPUnit < 10)"
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
run: composer test10

- uses: actions/download-artifact@v4
with:
name: parallel-lint-phar
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ composer.lock
phpcs.xml
.phpunit.result.cache
phpunit.xml
phpunit10.xml
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"jakub-onderka/php-parallel-lint": "*"
},
"require-dev": {
"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.1",
"php-parallel-lint/php-console-highlighter": "0.* || ^1.0",
"php-parallel-lint/php-code-style": "^2.0"
},
Expand Down Expand Up @@ -50,10 +50,14 @@
],
"scripts": {
"test": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage",
"coverage": "@php ./vendor/phpunit/phpunit/phpunit"
"test10": "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --no-coverage",
"coverage": "@php ./vendor/phpunit/phpunit/phpunit",
"coverage10": "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist"
},
"scripts-descriptions": {
"test": "Run all tests!",
"coverage": "Run all tests *with code coverage*"
"test": "Run all tests! ( PHPUnit < 10)",
"test10": "Run all tests! ( PHPUnit 10+)",
"coverage": "Run all tests *with code coverage* ( PHPUnit < 10)",
"coverage10": "Run all tests *with code coverage* ( PHPUnit 10+)"
}
}
40 changes: 40 additions & 0 deletions phpunit10.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="true"
bootstrap="./tests/bootstrap.php"
colors="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
failOnWarning="true"
failOnNotice="true"
failOnDeprecation="true"
stopOnFailure="false"
>

<testsuites>
<testsuite name="Unittests">
<directory suffix="Test.php">tests/Unit</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</source>

<coverage includeUncoveredFiles="true" ignoreDeprecatedCodeUnits="true">
<report>
<clover outputFile="build/logs/clover.xml"/>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
</coverage>

</phpunit>
4 changes: 2 additions & 2 deletions tests/Unit/Errors/ParallelLintErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testGetMessage($message, $expected)
*
* @return array
*/
public function dataGetMessage()
public static function dataGetMessage()
{
return array(
'Message: empty string' => array(
Expand Down Expand Up @@ -88,7 +88,7 @@ public function testGetShortFilePath($filePath, $expectedShort)
*
* @return array
*/
public function dataGetFilePath()
public static function dataGetFilePath()
{
$cwd = getcwd();

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Errors/SyntaxErrorGetLineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testGetLine($message, $expected)
*
* @return array
*/
public function dataGetLine()
public static function dataGetLine()
{
return array(
'Message: empty string' => array(
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Errors/SyntaxErrorGetNormalizeMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testMessageNormalizationWithoutTokenTranslation($message, $expec
*
* @return array
*/
public function dataMessageNormalization()
public static function dataMessageNormalization()
{
return array(
'Strip leading and trailing information - fatal error' => array(
Expand Down Expand Up @@ -85,7 +85,7 @@ public function testFilePathHandling($filePath, $fileName)
*
* @return array
*/
public function dataFilePathHandling()
public static function dataFilePathHandling()
{
return array(
'Plain file name' => array(
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Errors/SyntaxErrorTranslateTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testTranslateTokens($message, $expected)
*
* @return array
*/
public function dataTranslateTokens()
public static function dataTranslateTokens()
{
return array(
'No token name in message' => array(
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Outputs/OutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testCheckstyleOutput()
$this->assertInstanceOf('SimpleXMLElement', $parsed);
}

public function getGitLabOutputData()
public static function getGitLabOutputData()
{
return array(
array(
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/SettingsAddPathsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testAddPaths($original, $extra, $expected)
*
* @return array
*/
public function dataAddPaths()
public static function dataAddPaths()
{
return array(
'No paths passed on CLI, no extra paths' => array(
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/SettingsParseArgumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testParseArgumentsInvalidArgument($command, $unsupported)
*
* @return array
*/
public function dataParseArgumentsInvalidArgument()
public static function dataParseArgumentsInvalidArgument()
{
return array(
'Unsupported short argument' => array(
Expand Down Expand Up @@ -79,7 +79,7 @@ public function testParseArguments($command, array $expectedChanged)
*
* @return array
*/
public function dataParseArguments()
public static function dataParseArguments()
{
return array(
'No arguments at all' => array(
Expand Down