簡體   English   中英

PHPunit和Mockery:未找到方法

[英]PHPunit and Mockery: method not found

我在使用PHPunit和Mockery時遇到問題。 由於某種原因,PHPunit說我在Mockery中定義的onFoo方法不存在。

public function testReturnsTheCorrectValueWithClass()
{
    $listener = \Mockery::mock('FooListener');
    $listener->shouldReceive('onFoo')
             ->once()
             ->andReturn('foo');

    $this->eventManager->attach('foo.class', array($listener, 'onFoo'));

    $this->assertTrue($this->eventManager->dispatch('foo.class') === 'foo');
}

有人知道這段代碼有什么問題嗎?

我找到了解決問題的方法! 它與測試代碼無關,但與EventManager獲取模擬對象的方式無關。 我創建了模擬對象的新實例,而不僅僅是使用現有實例。

謝謝大家的幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM