Conversation
- 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
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.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket GH-470
Changes
AddClassandAddClassTestfor PHP 8.4 typing and PHPUnit 11 attributes (#[DataProvider],#[Group],#[CoversClass]instead of PHPDoc annotations).phpunit_examplemodule docs/info.yml for Drupal 11, drop the unuseddrupal:nodedependency.phpunit.xmlschema for PHPUnit 11 and fix the coverage source paths.finalmodifier onAddClass— it's a teaching example meant to be read and adapted, andfinalwas inconsistent with the rest of the custom codebase.int|floatfortestAddWithDataProvider(),mixedfortestAddWithBadDataProvider()).wunderio/code-qualityat 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 runpasses 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.