在我的申请中,我很难设置嘲弄来工作。我需要对一个库类进行部分的嘲弄,这个库类中有一些函数需要在测试其他函数时进行模拟。它似乎没有从嘲弄中提取基本的ShouldRecieve()函数,而是试图挖掘MyClass中的一个实例。我创建了一个例子来说明下面发生的事情。
<?php
class MyClass {
function foo() { return $this->bar; } // to be tested
function bar() { return true; } // to be mocked
}
class MyClass_Test extends TestCase {
function testMyClassFoo() {
$mock = \Mockery::mock('MyClass')->makePartial();
$mock->shouldRecieve('bar')->once()->andReturn(true);
$result = $mock->foo();
$this->assertTrue($result);
}
}
当我尝试运行测试时,我会得到以下错误:
Mockery\Exception\BadMethodCallException: Method Mockery_0_MyClass::shouldRecieve() does not exist on this mock object
我在想,模仿装置一定有什么问题,但一切似乎都在那里。知道为什么会发生这种事吗?
发布于 2022-02-05 12:32:57
我知道你提供了一个例子,但我假设你的错误是真实的。
方法是shouldReceive()。
https://stackoverflow.com/questions/70943087
复制相似问题