定制 forknetwork/strict-phpunit 二次开发

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

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

forknetwork/strict-phpunit

最新稳定版本:v2.2.0

Composer 安装命令:

composer require forknetwork/strict-phpunit

包简介

A simple PHPUnit extension that disallows unexpected method calls.

README 文档

README

Latest version Downloads Travis build status

A simple PHPUnit extension that disallows unexpected method calls.

For PHPUnit 7.1 and up.

Installation

composer require forknetwork/strict-phpunit ^2.0

How to use

The StrictTestTrait can be used by any class that extends from TestCase of PHPUnit. This trait can be added automatically using the PHP Code Sniffer.

Before

use PHPUnit\Framework\TestCase;

class YourTest extends TestCase
{
    // ...
}

After

use ForkNetwork\StrictPHPUnit\StrictTestTrait;
use PHPUnit\Framework\TestCase;

class YourTest extends TestCase
{
    use StrictTestTrait;
    // ...
}

Overwrite strict mock generation

By default all mocks will be strict, but in some cases that won't work. For example, PHPUnit doesn't handle the destruct method for mocks well. In those cases you might want to enable the value generation again.

Before

private function createFooMock()
{
    return $this->createMock('\Bar\Foo');
}

After

private function createFooMock()
{
    return $this->getMockBuilder('\Bar\Foo')
        ->enableAutoReturnValueGeneration();
        ->getMock();
}

Another option would to remove the trait from the class and manually add ->disableAutoReturnValueGeneration() onto the mocks your want strict.

Optional: PHP code sniffer and fixer

This library comes with a code sniff with auto-fixer. Just include the reference in your phpcs.xml(.dist) file and run the code sniffer as usual.

<rule ref="./vendor/forknetwork/strict-phpunit/src/Standards/ForkNetwork/ruleset.xml"/>

By default it will sniff all classes that extend from TestCase (PHPUnit). You can change which extended class it should sniff by adding this to your configuration.

<rule ref="ForkNetwork.PHPUnit.StrictUnitTest">
    <properties>
        <property name="extendedClasses" type="array" value="TestCase,ExtendedTestCase,AnotherCustomTestCase"/>
    </properties>
</rule>

Please note that this sniff only ensures the trait and use statements are added. It does not sort or pay attention to the rest of your code style.

Known limitations
The current implementation of the sniff doesn't support the following situations:

  • Comma separated use trait statements (e.g. use StrictUnitTrait, FooTrait;)
  • FQCN or partial use trait statements (e.g. use Traits\StrictUnitTest;)
  • Running the sniff unit tests in PHPUnit 8 or higher is not supported.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2019-01-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固