Skip to content
Advertisement

PHP Mocking Final Class

I am attempting to mock a php final class but since it is declared final I keep receiving this error:

PHPUnit_Framework_Exception: Class "DoctrineORMQuery" is declared "final" and cannot be mocked.

Is there anyway to get around this final behavior just for my unit tests without introducing any new frameworks?

Advertisement

Answer

Since you mentioned you don’t want to use any other framework, you are only leaving yourself one option: uopz

uopz is a black magic extension of the runkit-and-scary-stuff genre, intended to help with QA infrastructure.

uopz_flags is a function that can modify the flags of functions, methods and classes.

JavaScript

Will yield

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement