未调用PHP Prophecy存根方法

未调用PHP Prophecy存根方法,php,phpunit,prophecy,Php,Phpunit,Prophecy,我无法通过这个明显的测试。 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

我无法通过这个明显的测试。 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();
    }
}
Prophecy无法注册对Bar::Bar的调用

Some predictions failed:
  Double\Bar\P1:
    No calls have been made that match:
      Double\Bar\P1->bar()
    but expected at least one.
$bar变量包含ObjectProphecy的实例,该实例与bar类无关。调用$bar->REVEL以获得测试双精度,它是bar的扩展:

public function testM()
{
    $bar = $this->prophesize(Bar::class);
    $bar->bar()->shouldBeCalled();
    $foo = new Foo($bar->reveal());
    $foo->m();
}