【发布时间】:2020-04-26 23:10:27
【问题描述】:
在模拟对象上调用任何未配置的方法时是否可能导致 PHPUnit 失败?
示例;
$foo = $this->createMock(Foo::class);
$foo->expects($this->any())->method('hello')->with('world');
$foo->hello('world');
$foo->bye();
此测试将成功。我希望它失败
Foo::bye() was not expected to be called.
附:以下方法可行,但这意味着我必须在回调中列出所有配置的方法。这不是一个合适的解决方案。
$foo->expects($this->never())
->method($this->callback(fn($method) => $method !== 'hello'));
【问题讨论】:
-
这能回答你的问题吗? PHPUnit Mock Objects never expect by default