PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Testing » PHPUnit2 » Bug #8080

Mocking class with final methods fails

Details

Submitted2006-06-29 21:08 UTC
Fromjustinh at php dot net
Assignedsebastian
StatusClosed
PackagePHPUnit2
PHP Version5.1.4
OSWindows XP
Roadmaps(Not assigned)

Comments

[2006-06-29 21:08 UTC] justinh at php dot net

Description:
------------
The mock object generation method does not honor final methods, instead trying to overload them.

A simple patch would be to add 'if($method->isFinal()) return;' to the beginngin of PHPUnit2_Extensions_MockObject_Mock::generateMethodDefinition().

Test script:
---------------
class HasFinal {
final public function something() {
}
}

class HasFinalTest extends PHPUnit2_Framework_TestCase {
public function testSomething() {
$mock = $this->getMock('HasFinal');
}
}

Expected result:
----------------
[nothing]

Actual result:
--------------
Fatal error: Cannot override final method Zend_Db_Table::setDefaultAdapter() in C:\Program Files\xampp\php\pear\PHPUnit2\Extensions\MockObject\Mock.php(145) : eval()'d code on line 1

[2006-06-30 05:16 UTC] sebastian at php dot net

This bug has been fixed in CVS.

If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).

If this was a problem with the pear.php.net website, the change should be live shortly.

Otherwise, the fix will appear in the package's next release.

Thank you for the report and for helping us make PEAR better.