Codeception / AspectMock

The most powerful and flexible mocking framework for PHPUnit / Codeception.
MIT License
790 stars 129 forks source link

How I can delete all final keywords from my class and methods #127

Open yapro opened 7 years ago

yapro commented 7 years ago

I'm talking about: http://php.net/manual/en/language.oop5.final.php

Why I need this: https://phpunit.de/manual/current/en/test-doubles.html Final, private and static methods cannot be stubbed or mocked. They are ignored by PHPUnit's test double functionality and retain their original behavior.

Off course I want to delete "final" only during a test execution.

zuozp8 commented 7 years ago

you can't remove 'final' from method

AspectMock injects some code to every method (modifying the code before parsing instead of playing with inheritance) and allows you to return from methods early with specified result

you can just double with test::double(…) with AspectMock

yapro commented 7 years ago

I know it, but I need delete "final".

zuozp8 commented 7 years ago

you can use AspectMock to modify the fuction that is final and use phpunit mocks for everything else

if you really need to delete 'final' you can look at https://github.com/Codeception/AspectMock/blob/master/src/AspectMock/Kernel.php and https://github.com/Codeception/AspectMock/blob/master/src/AspectMock/Intercept/BeforeMockTransformer.php and implement it yourself

lougreenwood commented 7 years ago

@zuozp8

Do I read this correctly that AspectMock supports mocking 'final'/immutable classes out of the box?

you can't remove 'final' from method AspectMock injects some code to every method (modifying the code before parsing instead of playing with inheritance) and allows you to return from methods early with specified result you can just double with test::double(…) with AspectMock