• Stars
    star
    437
  • Rank 96,445 (Top 2 %)
  • Language
    PHP
  • License
    Other
  • Created over 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

Bypass Finals

Downloads this Month Tests Latest Stable Version License

Introduction

Removes final 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.2.

Usage

Simply call this:

DG\BypassFinals::enable();

You need to enable it before the classes you want to remove the final 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.

You can choose to only bypass finals 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');

Support Project

Do you like BypassFinals?

Donate

More Repositories

1

ftp-deployment

A tool for automated deployment of web applications to an FTP server.
PHP
594
star
2

twitter-php

Small and easy PHP library for sending messages to Twitter and receiving statuses.
PHP
544
star
3

dibi

Dibi - smart database abstraction layer
PHP
483
star
4

rss-php

Small and easy-to-use library for consuming RSS and Atom feeds
PHP
461
star
5

ftp-php

FTP Wrapper Class for PHP 5
PHP
204
star
6

MySQL-dump

MySQL Dump Utility
PHP
201
star
7

texy

Texy is a lightweight markup language with plain text formatting syntax engine.
HTML
153
star
8

composer-cleaner

Victor The Cleaner: removes unnecessary files from vendor directory
PHP
135
star
9

adminer

Customizations for Adminer, the best database management tool written in PHP.
PHP
120
star
10

php54-arrays

Command-line script to convert between array() and PHP 5.4's short syntax []
PHP
47
star
11

composer-backslasher

Composer plugin that speeds up your application by adding backslashes to all PHP internal functions and constants.
PHP
39
star
12

php-extensions-finder

Finds PHP extensions required by code.
PHP
39
star
13

composer-frontline

Composer Frontline: updates all the version constraints in the composer.json file to latest version.
PHP
27
star
14

texy-editor

Live editor for Texy
PHP
24
star
15

web-davidgrudl.com

My homepage
PHP
14
star
16

MySQL-check

Checks a MySQL database for invalid foreign keys, i.e., a keys pointing to missing rows.
PHP
14
star
17

php-console

PHP
5
star
18

dibi-docs

Dibi Documentation
5
star
19

imap

Retrieval, processing, and manipulation of emails within a mailbox via POP3, IMAP and NNTP
PHP
5
star
20

folksonomy

Collaborative tagging for open-source software. Used for content classification at www.code.dance.
1
star
21

dg

1
star
22

texy-docs

Texy Documentation
1
star