-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Essentially, using
with()withoutexpects()is currently treated as ifexpects($this->any())were used, meaning the above is equivalent to this:$dependency = $this->createMock(MyInterface::class); $dependency->expects($this->any())->method('myMethod')->with('payload')->willReturn('my result');Let me quote what I wrote in #6461:
The
any()matcher indicates that a method may be called "zero or more times". When combined withexpects(), this creates a fundamental contradiction: you're creating a mock object (designed to verify communication) but configuring it with an expectation that essentially says "I don't care if this communication happens at all".I think that using
with()withoutexpects()should be deprecated in PHPUnit 13 and support for this anti-pattern should be removed in PHPUnit 14. This aligns with the deprecation of theany()matcher and its scheduled removal.
Originally posted by @sebastianbergmann in #6504