You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any phpunit test case that extends \Symfony\Component\Validator\Test\ConstraintValidatorTestCase (symfony/validator 7.4.5), is having the AllowMockObjectsWithoutExpectations attribute added to it, but as per symfony/symfony#62669 and symfony/symfony#62745, since symfony/validator 7.4.3, its replaced all mocks that have no expectations with stubs so generates no warnings.
The fact that there are no phpunit warnings when runninng these tests, makes me think that this this is fixed on the symfony side and rector is flagging this as a false positive. I'm not sure exactly what it is about ConstraintValidatorTestCase that makes rector think that it still needs to add the AllowMockObjectsWithoutExpectations attribute though.
Minimal PHP Code Causing Issue
Install symfony/validator 7.4.5, write any custom test that extends \Symfony\Component\Validator\Test\ConstraintValidatorTestCase, run rector on it with the phpunit rules enabled, and you'll see that AllowMockObjectsWithoutExpectations is added to your test class.
Expected Behaviour
AllowMockObjectsWithoutExpectations attribute should not be added automatically to all tests that extend \Symfony\Component\Validator\Test\ConstraintValidatorTestCase.
Means if your test class extends Symfony\Component\Validator\Test\ConstraintValidatorTestCase it will have the attribute added (its that simple), but AFAIK and as I linked to in the OP, after symfony/validator 6.4.31, 7.3.9, 7.4.3, 8.0.3 we don't need AllowMockObjectsWithoutExpectations attribute any more when extending that class.
You can see that Rector is adding the AllowMockObjectsWithoutExpectations attribute to any class that extends ConstraintValidatorTestCase - this was needed at one point, but since symfony validator 6.4.31, 7.3.9, 7.4.3, 8.0.3 its no longer needed because they fixed in in the parent ConstraintValidatorTestCase class.
@samsonasik i'm not sure there's necessary and i the fact you're asking makes me think I've not got my point across well enough and its not clear what the issue actually is 😬 I'll try again:
We're discussing AllowMockObjectsWhereParentClassRector, it was added in rectorphp/rector-phpunit#641 2 weeks ago (with no additional context as to why in the PR description / linked issue), and its whole purpose is to add #[AllowMockObjectsWithoutExpectations] attribute to all test classes that extend Symfony\Component\Validator\Test\ConstraintValidatorTestCase or Symfony\Component\Form\Test\TypeTestCase.
What I'm trying to say is that AllowMockObjectsWhereParentClassRector doesn't need to exist since symfony 6.4.31, 7.3.9, 7.4.3, 8.0.3 as they've fixed the issue on their side. Any proposed PR fix that should be submitted to resolve this issue would essentially be to revert rectorphp/rector-phpunit#641 to remove it.
Without any more changes, it means that all my tests that extend Symfony\Component\Validator\Test\ConstraintValidatorTestCase automatically get #[AllowMockObjectsWithoutExpectations] attribute added to it, which isn't necessary as I'm running latest symfony 7.4.* which contains the fixes I linked to above.
Does that help explain the issue a little more clearly?
Activity
TomasVotruba commentedon Feb 13, 2026
Thank you for your report!
We'll need an isolated failing demo link from: http://getrector.com/demo,
that way we can reproduce the bug.
samsonasik commentedon Feb 13, 2026
It may already resolved at PR:
Please try latest
"rector/rector": "dev-main", if the issue persists, please provide reproducible code, thank you.philbates35 commentedon Feb 16, 2026
Hi @samsonasik, I did try on
dev-masterbut I was still seeing the same false positives.I dug into it a little deeper, and its actually much simpler than I realised.
The combination of these two:
Means if your test class extends
Symfony\Component\Validator\Test\ConstraintValidatorTestCaseit will have the attribute added (its that simple), but AFAIK and as I linked to in the OP, after symfony/validator 6.4.31, 7.3.9, 7.4.3, 8.0.3 we don't needAllowMockObjectsWithoutExpectationsattribute any more when extending that class.samsonasik commentedon Feb 16, 2026
If this due to combination on multiple rules, could you create failing test PR at
https://github.com/rectorphp/rector-phpunit/tree/main/tests/Issues
thank you.
philbates35 commentedon Feb 17, 2026
Hi @samsonasik, its not due to a combination of multiple rules, the issue that I'm seeing is this:
https://getrector.com/demo/3329b168-6a16-4639-b881-ef8a8678984b
You can see that Rector is adding the
AllowMockObjectsWithoutExpectationsattribute to any class that extendsConstraintValidatorTestCase- this was needed at one point, but since symfony validator 6.4.31, 7.3.9, 7.4.3, 8.0.3 its no longer needed because they fixed in in the parentConstraintValidatorTestCaseclass.samsonasik commentedon Feb 17, 2026
@philbates35 could you add PR fixture on https://github.com/rectorphp/rector-phpunit/tree/main/rules-tests/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector/Fixture ? Thank you.
philbates35 commentedon Feb 17, 2026
@samsonasik i'm not sure there's necessary and i the fact you're asking makes me think I've not got my point across well enough and its not clear what the issue actually is 😬 I'll try again:
We're discussing
AllowMockObjectsWhereParentClassRector, it was added in rectorphp/rector-phpunit#641 2 weeks ago (with no additional context as to why in the PR description / linked issue), and its whole purpose is to add#[AllowMockObjectsWithoutExpectations]attribute to all test classes that extendSymfony\Component\Validator\Test\ConstraintValidatorTestCaseorSymfony\Component\Form\Test\TypeTestCase.There's no bug in the implementation of
AllowMockObjectsWhereParentClassRector, it was indeed working as intended as can be seen here: https://github.com/rectorphp/rector-phpunit/blob/main/rules-tests/PHPUnit120/Rector/Class_/AllowMockObjectsWhereParentClassRector/Fixture/some_class.php.incWhat I'm trying to say is that
AllowMockObjectsWhereParentClassRectordoesn't need to exist since symfony 6.4.31, 7.3.9, 7.4.3, 8.0.3 as they've fixed the issue on their side. Any proposed PR fix that should be submitted to resolve this issue would essentially be to revert rectorphp/rector-phpunit#641 to remove it.Without any more changes, it means that all my tests that extend
Symfony\Component\Validator\Test\ConstraintValidatorTestCaseautomatically get#[AllowMockObjectsWithoutExpectations]attribute added to it, which isn't necessary as I'm running latest symfony 7.4.* which contains the fixes I linked to above.Does that help explain the issue a little more clearly?
github-actions commentedon Apr 19, 2026
This issue has been automatically marked as stale due to inactivity. It will be closed in next 30 days if no further activity occurs.
[PHPUnit12] Drop ConstraintValidatorTestCase from AllowMockObjectsWhe…
github-actions commentedon Nov 1, 2026
This issue has been automatically locked because it has been closed for 150 days. Please open a new issue if you have a similar problem.