我可以忽略模拟方法中的参数类型检查吗?

时间:2018-11-04 17:55:59

标签: php unit-testing mockery

我正在为依赖于另一个服务类的服务类编写测试。

Foo.php

class Foo {

 public function __construct(Bar $bar)
 {
  $this->bar = $bar;
 }

 public function fooMethod()
 {
  $getSomeArrayOrNull = null;
  $this->bar->barMethod($getSomeArrayOrNull);
 }

}

Bar.php

class Bar {


 public function barMethod(array $array)
 {
   return null;
 }

}

Test.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();
 }
}

我能以某种方式告诉嘲笑在$bar->barMethod()中进行类型检查吗? 我正在编写单元测试,我想完全模拟这部分代码。

这是一种不好的代码味道吗,我还应该只模拟$getSomeArrayOrNull属性吗? (女巫指的是数组)

0 个答案:

没有答案
相关问题