Skip to content

Tests: switch to PHPUnit #110

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 6 commits into from
Mar 17, 2022
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
17 changes: 9 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
# 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
/.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
/.github/ export-ignore
/doc/ export-ignore
/tests/ export-ignore

#
# Auto detect text files and perform LF normalization
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,23 @@ jobs:
run: composer remove --dev php-parallel-lint/php-code-style --no-update --no-interaction

- name: Install Composer dependencies
if: ${{ matrix.php != '8.2' }}
uses: ramsey/composer-install@v2

- name: "Install Composer dependencies (PHP 8.2, ignore PHP reqs)"
if: ${{ matrix.php == '8.2' }}
uses: ramsey/composer-install@v2
with:
composer-options: --ignore-platform-req=php

- name: 'Integration test 1 - linting own code, no colors'
continue-on-error: true
run: ./parallel-lint --exclude vendor --exclude tests/fixtures --no-colors .

- name: 'Integration test 2 - linting own code'
run: ./parallel-lint --exclude vendor --exclude tests/fixtures .

- name: 'Run unit tests PHP <= 5.5'
if: ${{ matrix.php < 5.6 }}
run: composer testphp5

- name: 'Run unit tests PHP >= 5.6'
if: ${{ matrix.php >= 5.6 }}
- name: 'Run unit tests'
run: composer test

- uses: actions/download-artifact@v3
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/build
/vendor
composer.lock
.phpcs.xml
phpcs.xml
.phpunit.result.cache
phpunit.xml
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"jakub-onderka/php-parallel-lint": "*"
},
"require-dev": {
"nette/tester": "^1.3 || ^2.0",
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"php-parallel-lint/php-console-highlighter": "0.* || ^1.0",
"php-parallel-lint/php-code-style": "^2.0"
},
Expand All @@ -45,10 +45,11 @@
"parallel-lint"
],
"scripts": {
"test": "@php vendor/bin/tester -C -p php tests",
"testphp5": "@php vendor/bin/tester -c tests/php5.3-5.5.ini -p php tests"
"test": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage",
"coverage": "@php ./vendor/phpunit/phpunit/phpunit"
},
"scripts-descriptions": {
"test": "Run all tests!"
"test": "Run all tests!",
"coverage": "Run all tests *with code coverage*"
}
}
8 changes: 2 additions & 6 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<!-- Scan all files. -->
<file>.</file>

<!-- Exclude dependencies, test fixtures. -->
<!-- Exclude dependencies, test fixtures and auto-generated files. -->
<exclude-pattern>*/build/*</exclude-pattern>
<exclude-pattern>*/tests/fixtures/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

Expand Down Expand Up @@ -83,9 +84,4 @@
<exclude-pattern>/src/(Application|ParallelLint|Settings|Outputs/TextOutput)\.php$</exclude-pattern>
</rule>

<!-- To be addressed in test refactor. -->
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
</rule>

</ruleset>
34 changes: 34 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.2/phpunit.xsd"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="true"
bootstrap="./tests/bootstrap.php"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
verbose="true"
>

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

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-text" target="php://stdout" showOnlySummary="true"/>
</logging>

</phpunit>
144 changes: 0 additions & 144 deletions tests/ParallelLintLintTest.php

This file was deleted.

34 changes: 0 additions & 34 deletions tests/SyntaxErrorNormalizeMessageTest.php

This file was deleted.

23 changes: 23 additions & 0 deletions tests/Unit/Errors/SyntaxErrorGetNormalizeMessageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace PHP_Parallel_Lint\PhpParallelLint\Tests\Unit\Errors;

use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;
use PHP_Parallel_Lint\PhpParallelLint\Tests\UnitTestCase;

class SyntaxErrorGetNormalizeMessageTest extends UnitTestCase
{
public function testInWordInErrorMessage()
{
$message = 'Fatal error: \'break\' not in the \'loop\' or \'switch\' context in test.php on line 2';
$error = new SyntaxError('test.php', $message);
$this->assertSame('\'break\' not in the \'loop\' or \'switch\' context', $error->getNormalizedMessage());
}

public function testInWordInErrorMessageAndInFileName()
{
$message = 'Fatal error: \'break\' not in the \'loop\' or \'switch\' context in test in file.php on line 2';
$error = new SyntaxError('test in file.php', $message);
$this->assertSame('\'break\' not in the \'loop\' or \'switch\' context', $error->getNormalizedMessage());
}
}
Loading