From b70cb3f3d896674142915217429109d4db93f7d6 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Wed, 20 Aug 2025 22:15:18 +0100 Subject: [PATCH 01/10] revert: commit 442a6a9 - "build: completely drop phpcs version 3.x." This reverts commit 442a6a9. --- .github/workflows/unit-tests.yml | 33 +++++++++++++++++++++++++++++++- composer.json | 2 +- phpunit-bootstrap.php | 10 ++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 0967ca4..01d41f3 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -64,7 +64,26 @@ 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"] + + 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 }}" @@ -90,6 +109,14 @@ jobs: ini-values: ${{ steps.set_ini.outputs.PHP_INI }} coverage: none + - name: "Composer: set PHPCS version for tests (dev)" + if: ${{ contains( matrix.phpcs_version, 'dev') }} + 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,6 +125,10 @@ 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 diff --git a/composer.json b/composer.json index 82556ea..623c1ae 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ], "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": { diff --git a/phpunit-bootstrap.php b/phpunit-bootstrap.php index b2ee6d4..84b181f 100644 --- a/phpunit-bootstrap.php +++ b/phpunit-bootstrap.php @@ -37,3 +37,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' + ); +} From b02cc11543c1882a77f12fc449437d0c95e9bd60 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Wed, 20 Aug 2025 22:39:04 +0100 Subject: [PATCH 02/10] ci(Unit Tests): add `phpcs3` branch to enable running on this branch. --- .github/workflows/unit-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 01d41f3..82e8980 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -5,6 +5,7 @@ on: push: branches: - master + - phpcs3 paths-ignore: - "**.md" - "**.xml" From 80de85f57a2060bb22c5489d9778b99fbe5b151f Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Wed, 20 Aug 2025 23:06:15 +0100 Subject: [PATCH 03/10] ci(Unit Tests): change workflow to be inline with phpcsExtra standard. By coping PHPCSExtra standard's workflow, it might fix some issues and allow the CI to work. Also removed phpunit 10 and 11 support, and changed the composer scripts. --- .github/workflows/unit-tests.yml | 38 +++++++++++++------------------- composer.json | 8 +++++-- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 82e8980..c2defb4 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -86,7 +86,7 @@ jobs: - php: "8.2" phpcs_version: "4.x-dev" - name: "Test: PHP ${{ matrix.php }}" + name: "Test: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }}" steps: - name: Checkout code @@ -110,8 +110,8 @@ jobs: ini-values: ${{ steps.set_ini.outputs.PHP_INI }} coverage: none - - name: "Composer: set PHPCS version for tests (dev)" - if: ${{ contains( matrix.phpcs_version, 'dev') }} + - 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" @@ -133,26 +133,18 @@ jobs: - 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/composer.json b/composer.json index 623c1ae..e306a14 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "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", From a19c7ea431410d85fffa921194cf725e3939cb82 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Wed, 20 Aug 2025 23:07:06 +0100 Subject: [PATCH 04/10] tests: change phpunit config and bootstrap file. --- phpunit-bootstrap.php | 6 ++++- phpunit.xml | 61 ++++++++++++++----------------------------- 2 files changed, 25 insertions(+), 42 deletions(-) diff --git a/phpunit-bootstrap.php b/phpunit-bootstrap.php index 84b181f..c8a5d2e 100644 --- a/phpunit-bootstrap.php +++ b/phpunit-bootstrap.php @@ -1,5 +1,9 @@ + 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 From 2d3e8bef8aea07bdf84e3e678c0515cf856792d2 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Wed, 20 Aug 2025 23:10:55 +0100 Subject: [PATCH 05/10] ci(Unit Tests): fix workflow not being ran on the phpcs3 branch. --- .github/workflows/unit-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index c2defb4..bbd8bed 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -21,7 +21,7 @@ concurrency: jobs: lint: - if: ${{ github.ref == 'refs/heads/master' }} + if: ${{ github.ref == 'refs/heads/master' }} || ${{ github.ref == 'refs/heads/phpcs3' }} runs-on: ubuntu-latest strategy: @@ -53,7 +53,7 @@ jobs: #### TEST STAGE #### test: - if: ${{ github.ref == 'refs/heads/master' }} + if: ${{ github.ref == 'refs/heads/master' }} || ${{ github.ref == 'refs/heads/phpcs3' }} runs-on: ubuntu-latest strategy: From aa2bcc682f966178c8898b4fd5ce1c54d64a916f Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 21 Aug 2025 01:16:37 +0100 Subject: [PATCH 06/10] docs(readme): added badge for phpcs version requirements --- README.md | 1 + 1 file changed, 1 insertion(+) 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. From b1ab992fd7503a9d05c746f263a01db50c9db059 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 21 Aug 2025 01:19:05 +0100 Subject: [PATCH 07/10] remove: now unnecessary `phpunit-lte9.xml` --- phpunit-lte9.xml | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 phpunit-lte9.xml diff --git a/phpunit-lte9.xml b/phpunit-lte9.xml deleted file mode 100644 index 1f52636..0000000 --- a/phpunit-lte9.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - ./yCodeTech/Tests/ - - - - - - CBF - - - - - - ./yCodeTech/ - - - - - - - - \ No newline at end of file From 230f809675647a61cb2bc3763147525fb2948224 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 21 Aug 2025 01:21:03 +0100 Subject: [PATCH 08/10] chore: add new phpunit cache file to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From cd1b425a7273549513d34a4b3051291b2e7e02f6 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 21 Aug 2025 01:24:32 +0100 Subject: [PATCH 09/10] build: update composer script descriptions and old `test` script names. --- composer.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index e306a14..03e529f 100644 --- a/composer.json +++ b/composer.json @@ -55,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", @@ -65,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." From d1c4ec3344ec487f8d7a591e45674eb108db7736 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 21 Aug 2025 06:14:03 +0100 Subject: [PATCH 10/10] revert: commits 2d3e8be and b02cc11 - enable running on phpcs3 branch. Initially, the phpcs3 branch was going to be a standalone release for phpcs version 3.x only. Now that the tests for both 3.x and 4.x work, we can merge into 1 release. So the phpcs3 branch is no longer needed. This reverts commits 2d3e8be and b02cc11. --- .github/workflows/unit-tests.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index bbd8bed..2ba7d9c 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -5,7 +5,6 @@ on: push: branches: - master - - phpcs3 paths-ignore: - "**.md" - "**.xml" @@ -21,7 +20,7 @@ concurrency: jobs: lint: - if: ${{ github.ref == 'refs/heads/master' }} || ${{ github.ref == 'refs/heads/phpcs3' }} + if: ${{ github.ref == 'refs/heads/master' }} runs-on: ubuntu-latest strategy: @@ -53,7 +52,7 @@ jobs: #### TEST STAGE #### test: - if: ${{ github.ref == 'refs/heads/master' }} || ${{ github.ref == 'refs/heads/phpcs3' }} + if: ${{ github.ref == 'refs/heads/master' }} runs-on: ubuntu-latest strategy: