Mockery\Exception\NoMatchingExpectationException:找不到 Mockery_1_::make 的匹配处理程序

问题描述 投票:0回答:1

我编写了此测试,返回以下错误:

Mockery\Exception\NoMatchingExpectationException:没有匹配的处理程序 找到了 Mockery_1_My_Class::make(array('valid_until'=>'2020-03-04',)).任何一个 该方法是意外的或其参数与预期不匹配 此方法的参数列表

现在我的测试中有这段代码:

$rateValidator->shouldReceive('make')->once()
            ->withArgs([$attributes])->andReturn(mockery::self());

$rateValidator->shouldReceive('addContext')
            ->withArgs(['update_rate_validity'])->andReturn(mockery::self());

这是此测试正在测试的代码:

$attributes = [
    'valid_until' => $command->validUntilDate
];

$validator = $this->rateValidator->make($attributes)->addContext('update_rate_validity');

我在这里做错了什么?对我来说,唯一的问题可能是方法

arguments
正在接收的
$attributes
(
make
),但我不知道那可能是什么?

php unit-testing laravel-5 phpunit
1个回答
1
投票

您需要确定作为模拟发送的数据。您发送的数据类型和被调用函数期望的数据类型必须相同。

例如:

您的函数需要如下数据:

[
    'test' => 'test',
]

您必须通过mock向函数发送相同的数据:

$validator->shouldReceive('theFunction')->with(['test' => 'test'])->andReturn('xx');
© www.soinside.com 2019 - 2024. All rights reserved.