PhpUnit mocking: function undefined

Viewed 1635

I am writing some tests for my view helper. This is the first time I would like to do something with mocking objects. I'm using the default PHPUnit mocking Framework.

I have written a function which prepares my mock object:

private function getTestStub(){
    $mockResult = array();
    $mock =  $this->getMock('My\Entity\Product');
    $mock->expects($this->once())
                ->method('getId')
                ->will($this->returnValue(1));
    $mock->expects($this->once())
        ->method('getName')
        ->will($this->returnValue('jan'));
    $mock->expects($this->once())
        ->method('getWoonplaats')
        ->will($this->returnValue('Amsterdam'));
    $mockResult[] = $mock;
    return $mockResult;
}

Now when using this stub for my tests I get the following Error:

Fatal error: Call to undefined method Mock_Product_129abca6::getId()

What Am I doing wrong here?

1 Answers
Related