Skip to content

Commit

Permalink
readme: added jumbo, improved
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 16, 2024
1 parent 8313b5d commit 5742970
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,55 @@
Bypass Finals
=============
![bypass-finals](https://github.com/dg/bypass-finals/assets/194960/82609c5f-a973-47ff-895e-7cc9aaaf1c91)

[![Downloads this Month](https://img.shields.io/packagist/dm/dg/bypass-finals.svg)](https://packagist.org/packages/dg/bypass-finals)
[![Tests](https://github.com/dg/bypass-finals/workflows/Tests/badge.svg?branch=master)](https://github.com/dg/bypass-finals/actions)
[![Latest Stable Version](https://poser.pugx.org/dg/bypass-finals/v/stable)](https://github.com/dg/bypass-finals/releases)
[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/dg/bypass-finals/blob/master/license.md)

 <!---->

Introduction
------------

Removes `final` and `readonly` keywords from source code on-the-fly and allows mocking of final methods and classes.
It can be used together with any test tool such as PHPUnit, Mockery or [Nette Tester](https://tester.nette.org).
**BypassFinals** effortlessly strips away `final` and `readonly` keywords from your PHP code on-the-fly.
This handy tool makes it possible to mock final methods and classes, seamlessly integrating with popular
testing frameworks like PHPUnit, Mockery, or [Nette Tester](https://tester.nette.org).

 <!---->

Installation
------------

The recommended way to install is through Composer:
The easiest way to install BypassFinals is via Composer. Just run the following command in your project directory:

```
composer require dg/bypass-finals --dev
```

It requires PHP version 7.1 and supports PHP up to 8.3.
It pretty much runs everywhere: PHP 7.1 through 8.3 are all supported!

 <!---->

Usage
-----

Simply call this:
To get BypassFinals up and running, just invoke:

```php
DG\BypassFinals::enable();
```

You need to enable it before the classes you want to remove the keywords from are loaded. So call it as soon as possible,
preferably right after `vendor/autoload.php` is loaded.
Make sure to call this method early, preferably immediately after your `vendor/autoload.php` is loaded,
to ensure all classes are processed before they are used.

Note that final internal PHP classes like `Closure` cannot be mocked.
Note that final internal PHP classes like `Closure` are not mockable.

The removal of `readonly` keywords can be disabled using the parameter:
To avoid removing `readonly` keywords, you can disable this feature by passing a parameter:

```php
DG\BypassFinals::enable(bypassReadOnly: false);
```

You can choose to only bypass keywords in specific files or directories:
To narrow down the application scope of BypassFinals, use a whitelist to specify directories or files:

```php
DG\BypassFinals::setWhitelist([
Expand All @@ -56,23 +59,39 @@ DG\BypassFinals::setWhitelist([

This gives you finer control and can solve issues with certain frameworks and libraries.

You can try to increase performance by using the cache (the directory must exist):
Enhance performance by caching transformed files. Make sure the cache directory already exists:

```php
DG\BypassFinals::setCacheDirectory(__DIR__ . '/cache');
```

To register BypassFinals in PHPUnit 10, simply add the extension to the PHPUnit XML configuration file:
For integration with PHPUnit 10 or newer, simply add BypassFinals as an extension in your PHPUnit XML configuration file:

```xml
<extensions>
<bootstrap class="DG\BypassFinals\PHPUnitExtension"/>
</extensions>
```

 <!---->

Do you like this project?
---------

Check out my other innovative open-source projects that might catch your interest:

<h3>

[Latte](https://latte.nette.org): The only safe and intuitive templating system for PHP<br>
[Tracy](https://tracy.nette.org): An addictive debugging tool to enhance your development workflow<br>
[PhpGenerator](https://doc.nette.org/en/php-generator): A robust library for generating PHP code with modern features<br>
[Nette Framework](https://nette.org): A thoughtfully engineered and popular web framework.<br>

</h3>

 <!---->

Support Project
---------------

Do you like BypassFinals?

[![Donate](https://files.nette.org/icons/donation-1.svg?)](https://nette.org/make-donation?to=bypass-finals)

0 comments on commit 5742970

Please sign in to comment.