Skip to content

CI/QA: start recording code coverage #144

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 4 commits into from
Dec 9, 2023
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
5 changes: 2 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ To help you with this, a number of convenience scripts are available:
* `composer cs` will check for code style violations.
* `composer cbf` will run the autofixers for code style violations.
* `composer test` will run the unit tests.
* `composer coverage` will run the unit tests with code coverage.
Note: you may want to use a custom `phpunit.xml` overload config file to tell PHPUnit where to place an HTML report.
Alternative run it like so: `composer coverage -- --coverage-html /path/to/report-dir/` to specify the location for the HTML report on the command line.
* `composer coverage` will run the unit tests with code coverage and show a text summary.
* `composer coverage-local` will run the unit tests with code coverage and generate an HTML coverage report, which will be placed in a `build/coverage-html` subdirectory.
* `composer build` will build the phpcs.phar and phpcbf.phar files.

N.B.: You can ignore any skipped tests as these are for external tools.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/quicktest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: php bin/phpcs --config-set php_path php

- name: 'PHPUnit: run the tests'
run: vendor/bin/phpunit tests/AllTests.php
run: vendor/bin/phpunit tests/AllTests.php --no-coverage

# Note: The code style check is run as an integration test.
- name: 'PHPCS: check code style without cache, no parallel'
Expand Down
103 changes: 100 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ jobs:
custom_ini: [false]

include:
# Builds running the basic tests with different PHP ini settings.
# Skip test runs on builds which are also run for in the coverage job.
# Note: the tests on PHP 7.2 will still be run as the coverage build is uses custom_ini for that version.
- php: '5.4'
skip_tests: true
- php: '8.3'
skip_tests: true

# Extra builds running only the unit tests with different PHP ini settings.
- php: '5.5'
custom_ini: true
- php: '7.0'
Expand Down Expand Up @@ -137,8 +144,9 @@ jobs:
- name: 'PHPCS: set the path to PHP'
run: php bin/phpcs --config-set php_path php

- name: 'PHPUnit: run the tests'
run: vendor/bin/phpunit tests/AllTests.php
- name: 'PHPUnit: run the tests without code coverage'
if: ${{ matrix.skip_tests != true }}
run: vendor/bin/phpunit tests/AllTests.php --no-coverage

- name: 'PHPCS: check code style without cache, no parallel'
if: ${{ matrix.custom_ini == false && matrix.php != '7.4' }}
Expand All @@ -163,3 +171,92 @@ jobs:
- name: 'PHPCS: check code style using the Phar file'
if: ${{ matrix.custom_ini == false }}
run: php phpcs.phar

coverage:
runs-on: ubuntu-latest

strategy:
matrix:
include:
- php: '5.4'
custom_ini: false
- php: '7.2'
custom_ini: true
- php: '8.3'
custom_ini: false

name: "Coverage: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }}"

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup ini config
id: set_ini
run: |
# Set the "short_open_tag" ini to make sure specific conditions are tested.
# Also turn on error_reporting to ensure all notices are shown.
if [[ ${{ matrix.custom_ini }} == true && "${{ startsWith( matrix.php, '5.' ) }}" == true ]]; then
echo 'PHP_INI=error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On, asp_tags=On' >> $GITHUB_OUTPUT
elif [[ ${{ matrix.custom_ini }} == true && "${{ startsWith( matrix.php, '7.' ) }}" == true ]]; then
echo 'PHP_INI=error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On' >> $GITHUB_OUTPUT
else
echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT
fi

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
coverage: xdebug

# This action also handles the caching of the dependencies.
- name: Set up node
if: ${{ matrix.custom_ini == false }}
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install external tools used in tests
if: ${{ matrix.custom_ini == false }}
run: >
npm install -g --fund false
csslint
eslint
jshint

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: 'PHPCS: set the path to PHP'
run: php bin/phpcs --config-set php_path php

- name: 'PHPUnit: run the tests with code coverage'
run: vendor/bin/phpunit tests/AllTests.php

- name: Upload coverage results to Coveralls
if: ${{ success() }}
uses: coverallsapp/github-action@v2
with:
format: clover
file: build/logs/clover.xml
flag-name: php-${{ matrix.php }}-custom-ini-${{ matrix.custom_ini }}
parallel: true

coveralls-finish:
needs: coverage
if: always() && needs.coverage.result == 'success'

runs-on: ubuntu-latest

steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/phpcs.xml
/phpunit.xml
.phpunit.result.cache
/build/
.idea/*
/vendor/
composer.lock
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PHP_CodeSniffer
[![Latest Stable Version](http://poser.pugx.org/phpcsstandards/php_codesniffer/v)](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases)
[![Validate](https://github.com/PHPCSStandards/PHP_CodeSniffer/actions/workflows/validate.yml/badge.svg?branch=master)](https://github.com/PHPCSStandards/PHP_CodeSniffer/actions/workflows/validate.yml)
[![Test](https://github.com/PHPCSStandards/PHP_CodeSniffer/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/PHPCSStandards/PHP_CodeSniffer/actions/workflows/test.yml)
[![Coverage Status](https://coveralls.io/repos/github/PHPCSStandards/PHP_CodeSniffer/badge.svg?branch=master)](https://coveralls.io/github/PHPCSStandards/PHP_CodeSniffer?branch=master)
[![License](http://poser.pugx.org/phpcsstandards/php_codesniffer/license)](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt)

![Minimum PHP Version](https://img.shields.io/packagist/php-v/squizlabs/php_codesniffer.svg?maxAge=3600)
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"Composer\\Config::disableProcessTimeout",
"@php ./vendor/phpunit/phpunit/phpunit tests/AllTests.php -d max_execution_time=0"
],
"coverage-local": [
"Composer\\Config::disableProcessTimeout",
"@php ./vendor/phpunit/phpunit/phpunit tests/AllTests.php --coverage-html ./build/coverage-html -d max_execution_time=0"
],
"build": [
"Composer\\Config::disableProcessTimeout",
"@php -d phar.readonly=0 -f ./scripts/build-phar.php"
Expand All @@ -76,6 +80,7 @@
"cbf": "Fix code style violations.",
"test": "Run the unit tests without code coverage.",
"coverage": "Run the unit tests with code coverage.",
"coverage-local": "Run the unit tests with code coverage and generate an HTML report in a 'build' directory.",
"build": "Create PHAR files for PHPCS and PHPCBF.",
"check-all": "Run all checks (phpcs, tests)."
}
Expand Down
16 changes: 16 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
forceCoversAnnotation="true"
>
<testsuites>
<testsuite name="PHP_CodeSniffer Test Suite">
<file>tests/AllTests.php</file>
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">./src</directory>
<file>./autoload.php</file>
<exclude>
<directory suffix="UnitTest.php">./src/Standards</directory>
</exclude>
</whitelist>
</filter>

<logging>
<log type="coverage-text" target="php://stdout" showOnlySummary="true"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
5 changes: 5 additions & 0 deletions src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the ArrayIndent sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\Arrays\ArrayIndentSniff
*/
class ArrayIndentUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the DisallowLongArraySyntax sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\Arrays\DisallowLongArraySyntaxSniff
*/
class DisallowLongArraySyntaxUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the DisallowShortArraySyntax sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\Arrays\DisallowShortArraySyntaxSniff
*/
class DisallowShortArraySyntaxUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the DuplicateClassName sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\Classes\DuplicateClassNameSniff
*/
class DuplicateClassNameUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the OpeningBraceSameLine sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\Classes\OpeningBraceSameLineSniff
*/
class OpeningBraceSameLineUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the AssignmentInCondition sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\AssignmentInConditionSniff
*/
class AssignmentInConditionUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Unit test class for the EmptyStatement sniff.
* Unit test class for the EmptyPHPStatement sniff.
*
* @author Juliette Reinders Folmer <[email protected]>
* @copyright 2017 Juliette Reinders Folmer. All rights reserved.
Expand All @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the EmptyPHPStatement sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\EmptyPHPStatementSniff
*/
class EmptyPHPStatementUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the EmptyStatement sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\EmptyStatementSniff
*/
class EmptyStatementUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the ForLoopShouldBeWhileLoop sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\ForLoopShouldBeWhileLoopSniff
*/
class ForLoopShouldBeWhileLoopUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the ForLoopWithTestFunctionCall sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\ForLoopWithTestFunctionCallSniff
*/
class ForLoopWithTestFunctionCallUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the JumbledIncrementer sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\JumbledIncrementerSniff
*/
class JumbledIncrementerUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the UnconditionalIfStatement sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\UnconditionalIfStatementSniff
*/
class UnconditionalIfStatementUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the UnnecessaryFinalModifier sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\UnnecessaryFinalModifierSniff
*/
class UnnecessaryFinalModifierUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the UnusedFunctionParameter sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\UnusedFunctionParameterSniff
*/
class UnusedFunctionParameterUnitTest extends AbstractSniffUnitTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
* Unit test class for the UselessOverridingMethod sniff.
*
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\UselessOverridingMethodSniff
*/
class UselessOverridingMethodUnitTest extends AbstractSniffUnitTest
{

Expand Down
Loading