From 5a91d87585eca6dcd52624104b582e88fec86262 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Sun, 26 Sep 2021 23:40:02 +0100 Subject: [PATCH] Php8.1 support (#67) * Fix Namespace * Clean up ignores * PHP8.1 support Also adding in github action and removing travis * Wrong command used * Wrong command used * Remove support for speeding up by filtering * PHPCS issue.. * Fix the command * Ignore function comments issue --- .github/workflows/ci.yaml | 33 +++++++++++++++++++++++++++++++++ .travis.yml | 21 --------------------- build.sh | 2 +- composer.json | 2 +- src/Loaders/Clover.php | 12 +++++++----- src/Loaders/PhpCs.php | 6 +++++- tests/PhpunitFilterTest.php | 3 +++ 7 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/ci.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..0adb29c --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,33 @@ +name: CI +on: + push: + pull_request: +jobs: + tests: + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: ['ubuntu-latest', 'windows-latest', 'macOS-latest'] + php-version: ['7.1', '7.2', '7.3', '7.4', '8.0'] + name: PHP ${{ matrix.php-version }} Test on ${{ matrix.operating-system }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Cache dependencies + uses: actions/cache@v1 + with: + path: /tmp/composer-cache + key: dependencies-composer-${{ hashFiles('composer.json') }} + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer:v2 + - name: Install Composer dependencies + run: composer install --prefer-dist --no-interaction --no-suggest + - name: Install phpcs + run: composer global require squizlabs/php_codesniffer + - name: Install phpmd + run: composer global require phpmd/phpmd + - name: Run the build + run: ./build.sh \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4cac4ec..0000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: php -dist: trusty -cache: - directories: - - $HOME/.composer/cache/files - - $HOME/.cache/composer/files -matrix: - include: - - php: 7.0 - - php: 7.1 - - php: 7.2 - env: UPDATE_COVERAGE=1 - - php: 7.3 - - php: 7.4 - fast_finish: true -before_script: - - composer global require squizlabs/php_codesniffer - - composer global require phpmd/phpmd - - sh -c "[ -z $UPDATE_COVERAGE ] && phpenv config-rm xdebug.ini || true" -script: - - PATH=$HOME/.composer/vendor/bin:$PATH ./build.sh diff --git a/build.sh b/build.sh index ec95d0b..2dc41a0 100755 --- a/build.sh +++ b/build.sh @@ -5,7 +5,7 @@ git log origin/master... | grep -q SKIP_BUILD && exit 0 [ -z "$UPDATE_COVERAGE" ] || composer require satooshi/php-coveralls:v1.1.0 -composer install --dev +composer install git diff $(git merge-base origin/master HEAD) > diff.txt phpcs --standard=psr2 src phpcs --standard=psr2 --ignore=bootstrap.php,fixtures/* tests diff --git a/composer.json b/composer.json index c02465b..d39ffb5 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "exussum12/coverage-checker", "description": "Allows checking the code coverage of a single pull request", "require-dev": { - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0" + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" }, "license": "MIT", "authors": [ diff --git a/src/Loaders/Clover.php b/src/Loaders/Clover.php index afd5930..6fd0176 100644 --- a/src/Loaders/Clover.php +++ b/src/Loaders/Clover.php @@ -50,12 +50,12 @@ public function parseLines(): array /** * {@inheritdoc} */ - public function getErrorsOnLine(string $file, int $line) + public function getErrorsOnLine(string $file, int $lineNumber) { - if (!isset($this->coveredLines[$file][$line])) { + if (!isset($this->coveredLines[$file][$lineNumber])) { return null; } - return $this->coveredLines[$file][$line] > 0 ? + return $this->coveredLines[$file][$lineNumber] > 0 ? []: ['No unit test covering this line'] ; @@ -92,11 +92,13 @@ protected function checkForNewFiles(XMLReader $reader, string $currentFile) protected function addLine(XMLReader $reader, string $currentFile) { $covered = $reader->getAttribute('count') > 0; + $line = $this->coveredLines + [$currentFile] + [$reader->getAttribute('num')] ?? 0; $this->coveredLines [$currentFile] - [$reader->getAttribute('num')] - = $covered ?: "No test coverage"; + [$reader->getAttribute('num')] = $line + $covered; } protected function handleStatement(XMLReader $reader, string $currentFile) diff --git a/src/Loaders/PhpCs.php b/src/Loaders/PhpCs.php index 1fabb6b..d33fe51 100644 --- a/src/Loaders/PhpCs.php +++ b/src/Loaders/PhpCs.php @@ -38,6 +38,10 @@ class PhpCs implements FileChecker 'Squiz.Commenting.FunctionComment', ]; + protected $functionIgnoreComments = [ + 'Squiz.Commenting.FunctionComment.ParamCommentFullStop' + ]; + /** * @var array */ @@ -123,7 +127,7 @@ protected function addInvalidLine(string $file, stdClass $message) $error = $this->messageStartsWith($message->source, $this->lookupErrorPrefix); - if ($error) { + if ($error && !in_array($message->source, $this->functionIgnoreComments, true)) { $this->handleLookupError($file, $message, $error); return; } diff --git a/tests/PhpunitFilterTest.php b/tests/PhpunitFilterTest.php index 4f9c152..20c7ee3 100644 --- a/tests/PhpunitFilterTest.php +++ b/tests/PhpunitFilterTest.php @@ -21,6 +21,9 @@ class PhpunitFilterTest extends TestCase */ public function setUpTest() { + if (PHP_VERSION > 7.2) { + $this->markTestSkipped("Not currently supported"); + } $this->coverage = __DIR__ . '/fixtures/php-coverage.php'; $this->diff = new DiffFileLoader(__DIR__ . '/fixtures/change.txt'); $this->matcher = new FileMatchers\EndsWith();