php - 我可以忽略模拟方法中的参数类型检查吗?
问题描述
我正在为依赖于另一个服务类的服务类编写测试。
Foo.php
class Foo {
public function __construct(Bar $bar)
{
$this->bar = $bar;
}
public function fooMethod()
{
$getSomeArrayOrNull = null;
$this->bar->barMethod($getSomeArrayOrNull);
}
}
酒吧.php
class Bar {
public function barMethod(array $array)
{
return null;
}
}
测试.php
class Test extends TestCase {
public function testIt()
{
$bar = Mockery::mock(Bar::class);
$bar->shouldReceive('barMethod')->withAnyArgs()->andReturn(true);
$foo = new Foo();
// this throws an error because invalid argument type in Bar method
$foo->fooMethod();
}
}
我可以以某种方式告诉嘲弄 ingore 类型检查$bar->barMethod()
吗?我正在编写单元测试,我想完全模拟这部分代码。
这是一种不好的代码气味,我是否$getSomeArrayOrNull
也应该模拟该属性?(女巫意味着总是一个数组)
解决方案
推荐阅读
- python - 如何消除python列表中的项目
- c++ - 如何改进我的“字符串”对象比较功能
- alfresco - 我如何在 APS/activiti 中使用子进程
- ios - 如何在 SWIFT3 XCODE 8.2 的 IOS 应用程序中显示 Snackbar 的操作中的特定视图
- spring - 通过 PagingAndSortingRepository 对 Spring Data Rest 中的 @Transient 列进行排序
- android - Single.concat报错继续下一个
- fonts - 如何知道特定字体样式中特定字符的宽度?
- sql - 工会没有给出预期的结果,而操作员呢?
- autocomplete - pycham自动完成没有做它的工作
- php - 设置 PHP 和 SQL 网站