robier / tests-ignore-final
Mock final classes
Installs: 1 092
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=7.3
Requires (Dev)
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-10-22 00:37:33 UTC
README
This library allows you to mock classes that have final
keyword in their signature. This
is accomplished by hooking up into autoload process and changing source code of the class on
the fly.
This library was inspired by dg/bypass-finals library. I wanted to have same functionally but with different approach. I hope that this different approach will not have the same problems as dg/bypass-finals have with infection.
Usage
Let's say you have this class that you want to mock:
<?php # ./FooBar.php final class FooBar { }
Only thing what you need to do in your test is this:
<?php use PHPUnit\Framework\TestCase; use Robier\Tests\IgnoreFinal; class FooBarTest extends TestCase { public function testSomething(): void { IgnoreFinal::composer(FooBar::class); } }
Class IgnoreFinal
will find the source code of the class we want to mock, and it will remove all final
keywords
from source code and load that modified source code instead of real one.
Tests
First run docker/build
to build a container and then docker/run composer run test
for running all tests.
Contribution
Feel free to contribute!