Skip to content

[Preview] [PHPUnit12] Drop ConstraintValidatorTestCase from AllowMockObjectsWhereParentClassRector triggers#1

Open
akankov wants to merge 2 commits into
mainfrom
fix-allow-mock-objects-false-positive
Open

[Preview] [PHPUnit12] Drop ConstraintValidatorTestCase from AllowMockObjectsWhereParentClassRector triggers#1
akankov wants to merge 2 commits into
mainfrom
fix-allow-mock-objects-false-positive

Conversation

@akankov
Copy link
Copy Markdown
Owner

@akankov akankov commented May 14, 2026

Fork-internal preview PR. Used to review the diff, description rendering, and CI behaviour before opening the real PR against rectorphp/rector-phpunit. Not for merge.


Summary

Closes rectorphp/rector#9650 (once moved to the upstream PR)

The rule wrongly adds #[AllowMockObjectsWithoutExpectations] to subclasses of ConstraintValidatorTestCase. The underlying need was removed upstream by symfony/symfony#62745 (shipped in symfony/validator 6.4.31 / 7.3.9 / 7.4.3 / 8.0.3).

Changes

  • Remove SYMFONY_CONSTRAINT_VALIDATOR_TEST_CASE from PARENT_CLASSES
  • Update rule's code sample to TypeTestCase (the remaining trigger)
  • Remove the now-orphaned enum constant
  • Convert existing some_class.php.inc to TypeTestCase and add a stub so it autoloads (the TypeTestCase path was previously never end-to-end tested)
  • Add a transitive skip fixture for real-world inheritance chains

Tests

  • skip_constraint_validator_test_case.php.inc — direct subclass, no attribute added
  • skip_constraint_validator_test_case_via_intermediate.php.inc — transitive subclass via abstract base, no attribute added
  • some_class.php.inc (updated) — TypeTestCase direct subclass, attribute correctly added

Alternatives

Open to either if preferred: version-aware detection via Composer\InstalledVersions::getVersion('symfony/validator'), or a configurable parent-exclusion list.

akankov added 2 commits May 14, 2026 21:04
…reParentClassRector triggers

The Symfony fix in symfony/symfony#62745 (shipped in symfony/validator
6.4.31 / 7.3.9 / 7.4.3 / 8.0.3) removed the underlying need for the
attribute on this lineage. Rule now fires only on TypeTestCase.

Includes: code sample updated to TypeTestCase, orphaned enum constant
removed, existing fixture converted to TypeTestCase, stub added so the
converted fixture autoloads, and a transitive-inheritance skip fixture.

Closes rectorphp/rector#9650
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.

#[AllowMockObjectsWithoutExpectations] incorrectly added

1 participant