Skip to content

Replace PHPUnit with deminy/counit and fix php-cs-fixer CI failure - #130

Open
deminy wants to merge 2 commits into
simps:masterfrom
deminy:master
Open

Replace PHPUnit with deminy/counit and fix php-cs-fixer CI failure#130
deminy wants to merge 2 commits into
simps:masterfrom
deminy:master

Conversation

@deminy

@deminy deminy commented Aug 29, 2026

Copy link
Copy Markdown

Summary

Replaces the project's hand-rolled coroutine-aware PHPUnit runner (tests/co-phpunit) with deminy/counit, and fixes a php-cs-fixer CI failure caused by an unpinned dependency version.

Changes

Replace PHPUnit with deminy/counit for unit tests

  • composer.json: require-dev now pulls deminy/counit: ^0.3 (matches the existing phpunit/phpunit: ~8.0 || ~9.0 usage) instead of phpunit/phpunit directly; the test script now runs ./vendor/bin/counit.
  • phpunit.xml.dist: registers Deminy\Counit\CounitExtension, required for accurate timing/assertion counts and correct handling of failures/skips that happen after a coroutine yield.
  • All test classes now extend Deminy\Counit\TestCase instead of PHPUnit\Framework\TestCase; the four classes overriding setUpBeforeClass()/tearDownAfterClass() call the parent methods, as TestCase requires.
  • Removes tests/co-phpunit, superseded by the package's own vendor/bin/counit binary.

Fix php-cs-fixer CI failure

  • composer.json pinned friendsofphp/php-cs-fixer to an open ^3.0 range with no committed composer.lock, so CI always resolved to whatever was newest on Packagist. That silently drifted the tool from 2021's ~3.x to the current 3.95.x, which broke cs-check two ways: the @Symfony/@PhpCsFixer rule-set aliases absorbed many new fixers over that span (the current code differs from what the latest version wants in 51 of 53 files), and 'increment_style' => [] — valid/no-op on old cs-fixer — is rejected by newer versions ("Configuration must be an array and may not be empty").
  • .php-cs-fixer.php: sets increment_style explicitly to ['style' => 'post'], matching the codebase's existing postfix (++/--) convention, instead of the invalid empty array.
  • src/Tools/UnPackTool.php: fixes the one spot using prefix increment (++$headBytes), inconsistent with the rest of the codebase, which the corrected rule now catches.
  • composer.json: pins friendsofphp/php-cs-fixer to the exact 3.7.0 (verified under PHP 8.1, matching the CI job's runtime, to be a version the current source needs zero changes against) instead of the open ^3.0 range, so this can't silently drift and break again on a future release.

Testing

  • Full suite via ./vendor/bin/counit (49 tests, including the live-broker WebSocket tests): pass.
  • composer analyse (phpstan): no errors.
  • composer cs-check, verified with a from-scratch composer install (no cached vendor/composer.lock) under PHP 8.1 in Docker, matching the CI job's runtime: exits 0, no files need fixing.

deminy and others added 2 commits August 29, 2026 12:33
Switch the test runner from a hand-rolled coroutine wrapper around
PHPUnit (tests/co-phpunit) to deminy/counit, which provides the same
per-test Swoole coroutine execution as a maintained, versioned
dependency with more correct reporting (accurate timing/assertion
counts and late-failure handling via CounitExtension).

- composer.json: require-dev deminy/counit ^0.3 (matches the existing
  phpunit/phpunit ~8.0/~9.0 usage) instead of phpunit/phpunit
  directly; "test" script now runs ./vendor/bin/counit.
- phpunit.xml.dist: register Deminy\Counit\CounitExtension.
- All test classes now extend Deminy\Counit\TestCase instead of
  PHPUnit\Framework\TestCase; the four classes overriding
  setUpBeforeClass()/tearDownAfterClass() call the parent methods, as
  required by TestCase.
- Remove tests/co-phpunit, superseded by vendor/bin/counit.

Verified: full suite (49 tests, incl. live-broker WebSocket tests)
and static analysis (phpstan) both pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017FqMMVcHcgGongoKm1WrfX
composer.json pinned friendsofphp/php-cs-fixer to an open ^3.0 range
with no committed composer.lock, so CI always resolved to whatever
was newest on Packagist. That silently drifted the tool from 2021's
~3.x to the current 3.95.23, which broke cs-check two ways:

- '@symfony'/'@PhpCsFixer' rule-set aliases absorbed many new fixers
  over that span, so the currently-formatted code now differs from
  what the latest version wants in 51 of 53 files.
- 'increment_style' => [] was valid/no-op on old cs-fixer but is
  rejected by newer versions ("Configuration must be an array and
  may not be empty"), which is the crash CI actually hit.

Fix:
- .php-cs-fixer.php: set increment_style explicitly to
  ['style' => 'post'], matching the codebase's existing postfix
  (++/--) convention throughout, instead of the invalid empty array.
- src/Tools/UnPackTool.php: fix the one spot using prefix increment
  (++$headBytes), inconsistent with the rest of the codebase, which
  the corrected rule now catches.
- composer.json: pin friendsofphp/php-cs-fixer to the exact 3.7.0
  (bisected under PHP 8.1 in Docker, matching the CI job's runtime,
  to confirm it's a version the current source needs zero changes
  against) instead of the open ^3.0 range, so this can't silently
  drift and break again on a future cs-fixer release.

Verified with a from-scratch composer install (no cached vendor/
composer.lock) under PHP 8.1 in Docker: cs-check exits 0 with no
files needing fixes, phpstan analyse reports no errors, and the
counit unit suite passes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017FqMMVcHcgGongoKm1WrfX
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant