PHPUnit assert no method is called
Yes, it's quite simple, try this:
$classA->expects($this->never())->method($this->anything());
You can use method MockBuilder::disableAutoReturnValueGeneration
.
For example, in your test overwrite default TestCase::getMockBuilder
:
/**
* @param string $className
* @return MockBuilder
*/
public function getMockBuilder($className): MockBuilder
{
// this is to make sure, that not-mocked method will not be called
return parent::getMockBuilder($className)
->disableAutoReturnValueGeneration();
}
Advantages:
- all your mocks won't be expected to call anything than mocked methods. No need to bind
->expects(self::never())->method(self::anything())
to all of them - you still can set new mocks. After
->expects(self::never())->method(self::anything())
you can't
Works for PhpUnit v7.5.4 (and probably, later ones).