Skip to content

GH-470: Modernize phpunit_example module for Drupal 11 and PHPUnit 11#474

Open
tormi wants to merge 7 commits into
mainfrom
GH-470
Open

GH-470: Modernize phpunit_example module for Drupal 11 and PHPUnit 11#474
tormi wants to merge 7 commits into
mainfrom
GH-470

Conversation

@tormi

@tormi tormi commented Jul 9, 2026

Copy link
Copy Markdown
Member

Ticket GH-470

Changes

  • Modernize AddClass and AddClassTest for PHP 8.4 typing and PHPUnit 11 attributes (#[DataProvider], #[Group], #[CoversClass] instead of PHPDoc annotations).
  • Update phpunit_example module docs/info.yml for Drupal 11, drop the unused drupal:node dependency.
  • Migrate phpunit.xml schema for PHPUnit 11 and fix the coverage source paths.
  • Drop the unexplained final modifier on AddClass — it's a teaching example meant to be read and adapted, and final was inconsistent with the rest of the custom codebase.
  • Add missing type declarations to the two data-provider-driven test methods (int|float for testAddWithDataProvider(), mixed for testAddWithBadDataProvider()).
  • Point wunderio/code-quality at its PHPStan 2 upgrade branch (dev-GH-126, wunderio/code-quality#127) to fix a PHPStan 1.12 false positive on repeated #[Group(...)] attributes. Temporary until that package cuts a tagged release (wunderio/code-quality#126).

Testing

  • ddev grumphp run passes all 8 tasks (php_compatibility, check_file_permissions, php_check_syntax, phpcs, php_stan, yaml_lint, json_lint, phpunit).
  • ddev exec vendor/bin/phpunit --configuration phpunit.xml --testsuite unit --filter AddClassTest — 27 tests, 27 assertions, all passing.

@tormi tormi changed the title GH-470: Update branch changes GH-470: Modernize phpunit_example module for Drupal 11 and PHPUnit 11 Jul 9, 2026
tormi added 5 commits July 16, 2026 16:27
- Add declare(strict_types=1) and mark the class final
- Type-hint add()'s parameters as mixed (rather than int|float) so
  non-numeric input still reaches the existing validity check and
  throws \InvalidArgumentException instead of a \TypeError
- Declare the int|float return type explicitly
- Replace annotation-based metadata (@dataProvider, @group) with
  PHPUnit 11 attributes (#[DataProvider], #[Group], #[CoversClass]),
  placed before each method's docblock to satisfy WunderInlineComment
- Add declare(strict_types=1) and void return types on test methods
- Remove stale references to \PHPUnit_Framework_TestCase and
  setExpectedException(); update comments to describe the
  expectException() method actually used by the test
- Fix assertEquals() argument order (expected, actual) in testAdd()
Replace the outdated 'Drupal 8 unit testing' wording in the module
file's doc block with 'Drupal 11 unit testing' to match the
project's current core version requirement.
phpunit_example doesn't use Node API in its code, so the drupal:node
dependency in phpunit_example.info.yml was unnecessary coupling.
- Migrate the configuration to the PHPUnit 11.5 schema (drop the
  deprecated 9.3 <coverage> block, HtmlOutputPrinter printerClass, and
  DrupalListener listener; add the required cacheDirectory attribute),
  removing the 'validates against a deprecated schema' warning
- Point the <source> include/exclude at web/modules/custom and
  web/themes/custom instead of web/core/*, so code coverage reports
  reflect this project's custom code rather than Drupal core
tormi added 2 commits July 16, 2026 23:26
AddClass is a teaching example meant to be read and adapted, so
remove the unexplained final modifier, which was also inconsistent
with the rest of the custom codebase.

Also add missing type declarations to the two data-provider-driven
test methods: int|float for testAddWithDataProvider() (its data
provider only supplies numeric values), and mixed for
testAddWithBadDataProvider() (its data provider deliberately
supplies non-numeric types).
Requires wunderio/code-quality:dev-GH-126 (wunderio/code-quality#127),
which bumps mglaman/phpstan-drupal and phpstan/phpstan-deprecation-rules
to their PHPStan-2-compatible releases. This resolves a false positive
where PHPStan 1.12 rejected repeated #[Group(...)] attributes on a
class even though PHPUnit\Framework\Attributes\Group is declared
Attribute::IS_REPEATABLE.

phpstan/phpstan and phpstan/phpstan-phpunit don't need to be pinned
directly here; they resolve to their 2.x releases already via
mglaman/phpstan-drupal's and drupal/core-dev's own constraints.

Temporary until wunderio/code-quality cuts a tagged release including
this upgrade (tracked in wunderio/code-quality#126), at which point
this should switch back to a version constraint.
@tormi
tormi requested review from MarttiR and hkirsman July 16, 2026 20:31
@tormi

tormi commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

This needs wunderio/code-quality#127 to be released 1st so that we can link to proper version instead of dev. cc: @hkirsman

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