php - PHPUnit mock parent method -
i have problem mocking parent method, example:
class pathprovider { public function getpath() { homecoming isset($_server['request_uri']) ? $_server['request_uri'] : '/'; } } class uri extends pathprovider { public function getparam($param) { $path = $this->getpath(); if ($path == $param) homecoming 'ok'; else homecoming 'bad'; } }
and want mock method getpath(), , phone call method getparam() recive mocked value.
$mock = $this->getmock('pathprovider'); $mock->expects($this->any()) ->method('getpath') ->will($this->returnvalue('/panel2.0/user/index/id/5'));
i write part, don't know how must pass mocked value testing method.
you need mock uri
class. can mock 1 method (getpath
), that:
$sut = $this->getmock('appropriate\namespace\uri', array('getpath')); $sut->expects($this->any()) ->method('getpath') ->will($this->returnvalue('/panel2.0/user/index/id/5'));
and can test object usual:
$this->assertequals($expectedparam, $sut->getparam('someparam'));
php unit-testing mocking phpunit
No comments:
Post a Comment