diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 0967ca4..2ba7d9c 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -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 @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index 667a0d7..6751b23 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ composer.lock # PHPUnit Cache .phpunit.cache +.phpunit.result.cache # VScode .vscode diff --git a/README.md b/README.md index 76fae06..9b5efcd 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/composer.json b/composer.json index 82556ea..03e529f 100644 --- a/composer.json +++ b/composer.json @@ -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" }, @@ -40,10 +40,14 @@ "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", @@ -51,7 +55,7 @@ "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", @@ -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." diff --git a/phpunit-bootstrap.php b/phpunit-bootstrap.php index b2ee6d4..c8a5d2e 100644 --- a/phpunit-bootstrap.php +++ b/phpunit-bootstrap.php @@ -1,5 +1,9 @@ - - - - ./yCodeTech/Tests/ - - - - - - CBF - - - - - - ./yCodeTech/ - - - - - - - - \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index a97f5e3..fd38bf2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,51 +1,30 @@ + beStrictAboutTestsThatDoNotTestAnything="false" + convertErrorsToExceptions="true" + convertWarningsToExceptions="true" + convertNoticesToExceptions="true" + convertDeprecationsToExceptions="true" + colors="true" + forceCoversAnnotation="true"> + - - ./yCodeTech/Tests/ + + ./yCodeTech/Tests/ - - - CBF - - - - - - ./yCodeTech/ - - - ./yCodeTech/Tests/ - - - - - - - - - + + + ./yCodeTech/Sniffs/ + + - - - - + + + + \ No newline at end of file