我没办法通过这个明显的考试。Foo在其构造函数中获取Bar,当调用Foo::m()时,Bar::bar()被调用。
use PHPUnit\Framework\TestCase;
class Bar {
public function bar() {
echo "BAR";
}
}
class Foo {
protected $bar;
public function __construct($bar) {
$this->bar= $bar;
}
public function m() {
$this->bar->bar();
}
}
class FooTest extends TestCase {
public function testM() {
$bar = $this->prophesize(Bar::class);
$bar->bar()->shouldBeCalled();
$foo = new Foo($bar);
$foo->m();
}
}预言无法注册对bar的调用::bar()
Some predictions failed:
Double\Bar\P1:
No calls have been made that match:
Double\Bar\P1->bar()
but expected at least one.发布于 2017-04-26 14:18:03
$bar变量包含一个ObjectProphecy实例,该实例与Bar类无关。调用$bar->reveal()以获得一个测试双,这是Bar的扩展
public function testM()
{
$bar = $this->prophesize(Bar::class);
$bar->bar()->shouldBeCalled();
$foo = new Foo($bar->reveal());
$foo->m();
}https://stackoverflow.com/questions/43635945
复制相似问题