unit-testing - PHPUnit 中的部分模拟现在 setMethods( 已弃用
问题描述
我正在尝试使用 PHP Unit 实现类的部分模拟,其中仅当显式设置存根行为时,存根方法才会被存根,如果没有保留类方法的原始行为;
我知道使用 setMethods( 允许我像在 => 中那样做
/**
* at this point, if I stub the class like this, only the constructor is called
* and all of the stubbed class methods will return null if I don't set them later in my test ...
*/
// $stubbed = $this->getMockBuilder(Stubbed::class)->getMock();
/**
* but... there is a way to keep the original methods
* to be able to stub them only in an explicit manner;
* the problem is, setMethods( seems to be deprecated
*/
$stubbed = $this->getMockBuilder(Stubbed::class)->setMethods(["doSomethingToBeStubbed"])->getMock();
// ... creating some stubbed methods
$stubbed->method("doSomethingToBeStubbed")->willReturn(true);
所以基本上我想知道是否有更好的方法来写这个以避免将来的技术债务(因为弃用通知)
解决方案
推荐阅读
- delete-row - 如何删除 DolphinDB 数据库中的一系列分区
- r - 将 R 代码中的列范围概括为未知的列数
- javascript - 使用 du 命令获取文件夹大小
- c# - 带有 AutoMapper 映射错误网站的 ASP.NET Core 将无法加载
- sql - 左连接与用另一个表更新表的结果不同
- kotlin - recyclerview 显示空白屏幕
- bash - 如何从 bash 脚本创建新过程
- cordova - Meteor - Cordova - 允许来自第三方服务的图像并阻止其他 url
- kubernetes - 如何在 minikube 上安装 kube-dns?
- python - 烧瓶多线程实际上并未为每个请求启动单独的线程