Skip to content
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
67 changes: 45 additions & 22 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,28 @@ jobs:
#
# The matrix is set up so as not to duplicate the builds which are run for code coverage.
php: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]
phpcs_version: ["4.x-dev"]
phpcs_version: ["lowest", "stable", "4.x-dev"]

name: "Test: PHP ${{ matrix.php }}"
exclude:
- php: "8.3"
phpcs_version: "lowest"

include:
# Add some builds with variations of the dependency versions.
- php: "8.4"
phpcs_version: "stable"

# Test against dev versions of all dependencies with select PHP versions for early detection of issues.
- php: "7.2"
phpcs_version: "dev-master"
- php: "7.2"
phpcs_version: "4.x-dev"
- php: "7.4"
phpcs_version: "4.x-dev"
- php: "8.2"
phpcs_version: "4.x-dev"

name: "Test: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }}"

steps:
- name: Checkout code
Expand All @@ -90,6 +109,14 @@ jobs:
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
coverage: none

- name: "Composer: set PHPCS version for tests (dev/specific version)"
if: ${{ matrix.phpcs_version != 'lowest' && matrix.phpcs_version != 'stable' }}
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction

- name: "Composer: use lock file when necessary"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer config --unset lock

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

- name: "Composer: set PHPCS version for tests (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer update squizlabs/php_codesniffer --prefer-lowest --no-scripts --no-interaction

- name: Composer info
run: composer info

- 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: Grab PHPCS version
id: phpcs_version
# yamllint disable-line rule:line-length
run: echo "VERSION=$(vendor/bin/phpcs --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> "$GITHUB_OUTPUT"

- name: "DEBUG: Show grabbed PHPUnit version"
run: echo ${{ steps.phpunit_version.outputs.VERSION }}
- name: "DEBUG: Show grabbed PHPCS version"
run: echo ${{ steps.phpcs_version.outputs.VERSION }}

- name: Determine PHPUnit config file to use
id: phpunit_config
shell: bash
run: |
if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '11.' ) }}" == "true" ]; then
echo 'FILE=phpunit.xml' >> "$GITHUB_OUTPUT"
elif [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}" == "true" ]; then
echo 'FILE=phpunit.xml' >> "$GITHUB_OUTPUT"
else
echo 'FILE=phpunit-lte9.xml' >> "$GITHUB_OUTPUT"
fi
- name: Run the unit tests (PHPCS 3.x)
if: ${{ startsWith( steps.phpcs_version.outputs.VERSION, '3.' ) }}
run: composer test-phpcs3

- name: Run the unit tests
run: composer test -- -c ${{ steps.phpunit_config.outputs.FILE }}
env:
PHPCS_VERSION: ${{ matrix.phpcs_version }}
- name: Run the unit tests (PHPCS 4.x)
if: ${{ startsWith( steps.phpcs_version.outputs.VERSION, '4.' ) }}
run: composer test-phpcs4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ composer.lock

# PHPUnit Cache
.phpunit.cache
.phpunit.result.cache

# VScode
.vscode
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Latest Stable Version](https://img.shields.io/github/v/release/yCodeTech/phpcs-standard?label=Stable)](https://packagist.org/packages/ycodetech/phpcs-standard)
![Minimum PHP Version](https://img.shields.io/packagist/dependency-v/yCodeTech/phpcs-standard/php?label=php)
![PHPCS Version](https://img.shields.io/packagist/dependency-v/yCodeTech/phpcs-standard/squizlabs/php_codesniffer?label=PHPCS)
[![Unit Tests](https://github.com/yCodeTech/phpcs-standard/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/yCodeTech/phpcs-standard/actions/workflows/unit-tests.yml)

A custom [PHP_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer/tree/4.x) standard that enforces opinionated type and docblock rules with auto-fixing capabilities.
Expand Down
17 changes: 11 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
],
"require": {
"php": ">=7.2",
"squizlabs/php_codesniffer": "^4.0@dev",
"squizlabs/php_codesniffer": "^3.13||^4.0@dev",
"dealerdirect/phpcodesniffer-composer-installer": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "^8.5||^9.6||^10.5||^11.5",
"phpunit/phpunit": "^8.5||^9.6",
"phpcsstandards/phpcsdevtools": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.4"
},
Expand All @@ -40,18 +40,22 @@
"lint": "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --exclude test_utils",
"cs": "@php ./vendor/bin/phpcs --standard=yCodeTech",
"cbf": "@php ./vendor/bin/phpcbf --standard=yCodeTech",
"test": [
"test-phpcs4": [
"Composer\\Config::disableProcessTimeout",
"@php ./vendor/bin/phpunit --no-coverage"
],
"test-phpcs3": [
"Composer\\Config::disableProcessTimeout",
"@php ./vendor/bin/phpunit --filter yCodeTech --no-coverage ./vendor/squizlabs/php_codesniffer/tests/AllTests.php"
],
"cs-test-file": "@cs ./test_utils/TestFile.php",
"fix-test-file": "@cbf ./test_utils/TestFile.php",
"restore-test-file": "bash ./test_utils/restore_errors.sh",
"cs-tests": "@cs ./yCodeTech/Tests/ --extensions=inc",
"test-all": [
"@cs-test-file",
"@cs-tests",
"@test"
"@test-phpcs4"
],
"list-tokens": "@php ./vendor/bin/phpcs --standard=PHPCSDebug ./test_utils/TestFile.php",
"check-completeness": "@php ./vendor/bin/phpcs-check-feature-completeness ./yCodeTech",
Expand All @@ -61,12 +65,13 @@
"lint": "Run PHP Parallel Lint to check for syntax errors in PHP files.",
"cs": "Run PHPCS to check for coding standards violations.",
"cbf": "Run PHPCBF to fix coding standards violations.",
"test": "Run PHPUnit tests without code coverage.",
"test-phpcs4": "PHPCS 4.x: Run PHPUnit tests without code coverage.",
"test-phpcs3": "PHPCS 3.x: Run PHPUnit tests without code coverage.",
"cs-test-file": "Run PHPCS on the test file.",
"fix-test-file": "Run PHPCBF on the test file.",
"restore-test-file": "Restore the test file to its original state.",
"cs-tests": "Run PHPCS on all sniff unit tests.",
"test-all": "Run @cs-test-file, @cs-tests, and @test in sequence.",
"test-all": "Run @cs-test-file, @cs-tests, and @test-phpcs4 in sequence.",
"list-tokens": "List all tokens used in the test file.",
"check-completeness": "Check the completeness of the PHPCS standard.",
"generate-docs": "Generate markdown documentation for the PHPCS standard."
Expand Down
16 changes: 15 additions & 1 deletion phpunit-bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

if (\defined('PHP_CODESNIFFER_IN_TESTS') === false) {
\define('PHP_CODESNIFFER_IN_TESTS', true);
}

/*
* Load the necessary PHPCS files.
*/
Expand All @@ -25,7 +29,7 @@
&& \file_exists($phpcsDir . '/tests/bootstrap.php')
) {
require_once $phpcsDir . '/autoload.php';
require_once $phpcsDir . '/tests/bootstrap.php'; // PHPUnit 6.x+ support.
require_once $phpcsDir . '/tests/bootstrap.php';
} else {
echo 'Uh oh... can\'t find PHPCS.

Expand All @@ -37,3 +41,13 @@

exit(1);
}

// Alias the PHPCS 3.x test case to the PHPCS 4.x name.
if (class_exists('PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest') === true
&& class_exists('PHP_CodeSniffer\Tests\Standards\AbstractSniffTestCase') === false
) {
class_alias(
'PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest',
'PHP_CodeSniffer\Tests\Standards\AbstractSniffTestCase'
);
}
37 changes: 0 additions & 37 deletions phpunit-lte9.xml

This file was deleted.

61 changes: 20 additions & 41 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,51 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
backupGlobals="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="./phpunit-bootstrap.php"
cacheDirectory=".phpunit.cache"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="false"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnPhpunitDeprecations="false"
failOnWarning="false"
failOnNotice="true"
failOnDeprecation="true"
failOnPhpunitDeprecation="false"
>
beStrictAboutTestsThatDoNotTestAnything="false"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
colors="true"
forceCoversAnnotation="true">

<testsuites>
<testsuite name="yCodeTech_Sniffs">
<directory>./yCodeTech/Tests/</directory>
<testsuite name="yCodeTech">
<directory suffix="UnitTest.php">./yCodeTech/Tests/</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>CBF</group>
</exclude>
</groups>

<source>
<include>
<directory suffix=".php">./yCodeTech/</directory>
</include>
<exclude>
<directory suffix="UnitTest.php">./yCodeTech/Tests/</directory>
</exclude>
</source>

<coverage includeUncoveredFiles="true">
<report>
<clover outputFile="build/logs/clover.xml"/>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
</coverage>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./yCodeTech/Sniffs/</directory>
</whitelist>
</filter>

<php>
<env name="PHP_CODESNIFFER_CBF" value="0"/>
</php>
</phpunit>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>