-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Form] do not use PHPUnit mock objects without configured expectations #62759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 6.4
Are you sure you want to change the base?
Conversation
xabbuh
commented
Dec 12, 2025
| Q | A |
|---|---|
| Branch? | 6.4 |
| Bug fix? | yes |
| New feature? | no |
| Deprecations? | no |
| Issues | part of #62669 |
| License | MIT |
| $metadata = $this->getMockBuilder(ClassMetadata::class)->setConstructorArgs([''])->onlyMethods(['addPropertyConstraint'])->getMock(); | ||
| $this->validator->expects($this->any())->method('getMetadataFor')->willReturn($metadata); | ||
| $this->validator->expects($this->any())->method('validate')->willReturn(new ConstraintViolationList()); | ||
| $this->validator = (new ValidatorBuilder())->getValidator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the validator is protected, someone could add expections $this->validator->method(...) when using the trait.
So is this change considered as a BC break ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't consider this a BC break as the type of the property is ValidatorInterface. In other places where we communicated the type to be MockObject I kept it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would keeping the mock be problematic? Symfony is widely used enough for someone to be affected by this ;)
| parent::setUp(); | ||
|
|
||
| $this->dispatcher = $this->createMock(EventDispatcherInterface::class); | ||
| $this->dispatcher = new EventDispatcher(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, the dispatcher is protected so someone could have added expectation on the dispatcher in his tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here