定制 robier/tests-ignore-final 二次开发

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

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

robier/tests-ignore-final

Composer 安装命令:

composer require robier/tests-ignore-final

包简介

Mock final classes

README 文档

README

This library allows you to mock classes that have final keyword in their signature. This is accomplished by hooking up into autoload process and changing source code of the class on the fly.

This library was inspired by dg/bypass-finals library. I wanted to have same functionally but with different approach. I hope that this different approach will not have the same problems as dg/bypass-finals have with infection.

Usage

Let's say you have this class that you want to mock:

<?php
# ./FooBar.php
final class FooBar {

}

Only thing what you need to do in your test is this:

<?php

use PHPUnit\Framework\TestCase;
use Robier\Tests\IgnoreFinal;

class FooBarTest extends TestCase
{
    public function testSomething(): void
    {
        IgnoreFinal::composer(FooBar::class);
    }
}

Class IgnoreFinal will find the source code of the class we want to mock, and it will remove all final keywords from source code and load that modified source code instead of real one.

Tests

First run docker/build to build a container and then docker/run composer run test for running all tests.

Contribution

Feel free to contribute!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-24