GithubHelp home page GithubHelp logo

pawelabrams / bypass-finals Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dg/bypass-finals

0.0 0.0 0.0 55 KB

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 or Mockery.

License: Other

PHP 100.00%

bypass-finals's Introduction

Bypass Finals

Downloads this Month Tests Latest Stable Version License

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.

Installation

The recommended way to install is through Composer:

composer require dg/bypass-finals --dev

It requires PHP version 7.1 and supports PHP up to 8.3.

Usage

Simply call this:

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.

Note that final internal PHP classes like Closure cannot be mocked.

The removal of readonly keywords can be disabled using the parameter:

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

You can choose to only bypass keywords in specific files or directories:

DG\BypassFinals::setWhitelist([
    '*/Nette/*',
]);

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):

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

To register BypassFinals in PHPUnit 10, simply add the extension to the PHPUnit XML configuration file:

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

Support Project

Do you like BypassFinals?

Donate

bypass-finals's People

Contributors

afilina avatar ammarpad avatar bzikarsky avatar dg avatar dmitryuk avatar fancsali avatar milo avatar nightlinus avatar nyholm avatar phcorp avatar sanmai avatar szepeviktor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.