定制 idimsh/better-bypass-finals 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

idimsh/better-bypass-finals

Composer 安装命令:

composer require --dev idimsh/better-bypass-finals

包简介

Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

README 文档

README

Downloads this Month Build Status License

#Introduction (idimsh) This is a redistribution of the famous package bypass-finals with minor modifications that includes:

  • making it inheritance ready, allowing subclasses of the main class to continue working.
  • code style uses spaces instead of tabs.
  • tests are not using Nette Tester, but PHPUnit

The original license remains untouched, and they are BSD and GNU both.
The reason for creating this package is an un answered pull request.

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 idimsh/better-bypass-finals --dev

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

Usage

Simply call this:

\idimsh\BypassFinals::enable();

or

\idimsh\BypassFinalsCatcher::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 in loaded.

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

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

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

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

There is also a PHP Unit listener available for usage inside phpunit.xml file, like:

<phpunit bootstrap="vendor/autoload.php">
    <listeners>
        <listener class="idimsh\BypassFinal\Listener\BypassFinalListener"/>
    </listeners>
</phpunit>

The Catcher version

The extension of the main class with the name: \idimsh\BypassFinalsCatcher Will catch syntax errors and echo the file name to STDERR. This is useful for tests that span thousand files, the default behaviour was a silent fatal parse error that does not report the file name.

There is also a listener that uses the catcher.

<phpunit bootstrap="vendor/autoload.php">
    <listeners>
        <listener class="idimsh\BypassFinal\Listener\BypassFinalCatcherListener"/>
    </listeners>
</phpunit>

统计信息

  • 总下载量: 2.87k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-10-04