I have problem with mocking parent method, this is example:
class PathProvider
{
public function getPath()
{
return isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
}
}
class Uri extends PathProvider
{
public function getParam($param)
{
$path = $this->getPath();
if ($path == $param)
return 'OK';
else
return 'Bad';
}
}
And now i want mock method getPath(), and call method getParam() which recive mocked value.
$mock = $this->getMock('PathProvider');
$mock->expects($this->any())
->method('getPath')
->will($this->returnValue('/panel2.0/user/index/id/5'));
I was write this part, but I don’t know how I must pass this mocked value to testing method.
You just need mock
Uriclass. You can mock only one method (getPath), like that:And then you can test your object as usual: