使用 Mockery 间谍时代码是否实际执行?

Is the code actually executed when using a Mockery spy?

我正在尝试用 Mockery Spy 编写一些测试。但是,当我使用间谍时,似乎并没有执行“被监视”的代码。

使用 Mockery 间谍时代码是否实际执行?

这是我测试的:

// In my test:
$spy = $this->spy(FeedManager::class);

// Controller
resolve(FeedManager::class)->createResponse();

// FeedManger::createResponse()
public static function createResponse(Builder $builder)
{
  dd("here i am"); // this never gets called unless I remove the spy
}

显然,“间谍代码”不应该 运行。从 the docs.

找到这句话

The \Mockery::spy() method call is actually a shorthand for calling \Mockery::mock()->shouldIgnoreMissing(). The shouldIgnoreMissing method is a “behaviour modifier”.