Skip to content

[PHPUnit12] Drop ConstraintValidatorTestCase from AllowMockObjectsWhereParentClassRector triggers#678

Merged
TomasVotruba merged 2 commits into
mainfrom
fix-allow-mock-objects-false-positive
May 30, 2026
Merged

[PHPUnit12] Drop ConstraintValidatorTestCase from AllowMockObjectsWhereParentClassRector triggers#678
TomasVotruba merged 2 commits into
mainfrom
fix-allow-mock-objects-false-positive

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

Summary

Closes rectorphp/rector#9650

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.


Ported from preview PR akankov#1 (by @akankov)

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
@TomasVotruba
Copy link
Copy Markdown
Member Author

Picked from akankov#1

@TomasVotruba TomasVotruba merged commit 6dfea2b into main May 30, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the fix-allow-mock-objects-false-positive branch May 30, 2026 21:10
@TomasVotruba
Copy link
Copy Markdown
Member Author

Thanks 👍

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

#[AllowMockObjectsWithoutExpectations] incorrectly added

2 participants