简体   繁体   中英

PHPunit and Mockery: method not found

I'm having a problem using PHPunit and Mockery. For some reason, PHPunit says that the method onFoo , I defined in Mockery, does not exist.

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');
}

Does anyone know what's wrong with this code?

I found the solution for the problem! It had nothing to do with my test code, but with the way my EventManager gets the mock object. I created a new instance of the mock object instead of just using the existing one.

Thanks everyone for the help though!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM