dg/bypass-finals
dg/bypass-finals is a PHP library that removes the final keyword at runtime so you can mock final classes and methods in tests. It works with PHPUnit and other mocking tools, making legacy or third-party code easier to test without changing source.
BypassFinals now understands modern PHP: final disappears not only from classes and methods, but also from properties and property hooks introduced in PHP 8.4. Caching got safer and smarter, path matching finally behaves on Windows, and PHPUnit users can configure path masks straight from phpunit.xml.
final is now removed from properties and property hooks (PHP 8.4+), not just from classes and methods. The rule is inverted: final survives only before constants, where it's a genuine feature rather than a mockability barrier.allowPaths and denyPaths – restrict which files get rewritten without touching a single line of PHP. Semicolon-separated masks, right there in phpunit.xml:
<parameter name="allowPaths" value="*/src/*;*/lib/*"/>
<parameter name="denyPaths" value="*/generated/*"/>
debugInfo() now shows the full picture – allowed and denied path rules plus the cache directory, so you can see at a glance why a file wasn't modified.final readonly int $x no longer produces invalid code. With both bypasses enabled it used to emit a bare int $x; a property must keep at least one modifier, so the first removed one now becomes public.C:/Src/ and c:/src/ are the same directory – as they always should have been.rename(), so a process killed mid-write can no longer leave a truncated file behind and poison every subsequent run. [#80]vendor/autoload.php loads, so nothing slips through unmodified (#74, #58)proc_open() when given a ['file', ...] descriptor spec – the native wrapper no longer chokes on file-based descriptors (#43)stream_eof() now waits for an actual empty read before reporting end-of-stream, preventing truncated reads (#75, #50)is_dir() check in stream_open(), fixing stale filesystem state on cache writes (#69, #67)debugInfo() output so bypass tokens are reported correctly (#68)NativeWrapper::stream_seek() now detects whether the underlying stream is actually seekable instead of blindly seeking (#63)final keyword survive untouched (#64)T_READONLY constant polyfill for PHP < 8.1, keeping older runtimes happy (51736af)vendor/autoload.php loads, so nothing slips through unmodified (#74, #58)proc_open() when given a ['file', ...] descriptor spec – the native wrapper no longer chokes on file-based descriptors (#43)stream_eof() now waits for an actual empty read before reporting end-of-stream, preventing truncated reads (#75, #50)is_dir() check in stream_open(), fixing stale filesystem state on cache writes (#69, #67)debugInfo() output so bypass tokens are reported correctly (#68)NativeWrapper::stream_seek() now detects whether the underlying stream is actually seekable instead of blindly seeking (#63)final keyword survive untouched (#64)T_READONLY constant polyfill for PHP < 8.1, keeping older runtimes happy (51736af)DG\BypassFinals::enable(bypassReadOnly: false);
fixed some bugs #28, #25
setWhitelist() method to allow controlling which files get replaced. (#7)final as non-keyword [Closes #4]How can I help you explore Laravel packages today?