定制 elijahb/phpcs-testability 二次开发

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

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

elijahb/phpcs-testability

Composer 安装命令:

composer require elijahb/phpcs-testability

包简介

PHPCodeSniffer sniffs for unit test code testability check

README 文档

README

Build status

Introduction

This project provides sniffs for some design patterns that improve unit test code testability:

  • Use dependency injection (do not create instances using new)
  • Limit the length for a call chain ($this->property->service->method->troubles)
  • Do not call methods of the same class (this is a sign that your code is too complicated and you should split it in different services)
  • Not use static calls (Service::method())
  • Use only public methods (private methods cannot be really unit tested, and they indicate that you should be thinking about creating a new service)

It also provides two other sniffs, useful for CI environments:

  • Check that a test case exists for every class
  • Check that there is at least one test for every method

How to use

  1. Install PHPCodeSniffer
  2. Install phpcs-testability using Composer
composer require --dev elijahb/phpcs-testability
  1. Add the standard to your custom PHPCodeSniffer ruleset.xml file
<rule ref="./vendor/elijahb/phpcs-testability"/>

Recommendations

You could also use another two sniffs to complement the ones in this projects:

  • Generic.Metrics.NestingLevel (with a nesting level of 2)
  • Generic.Metrics.CyclomaticComplexity (with a complexity level of 3)

Using all this sniffs, ideally inside a CI environment, you will be assured to have maintainable and fully unit tested code.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-01-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固