承接 brainbits/phpstan-rules 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

brainbits/phpstan-rules

最新稳定版本:4.0.0

Composer 安装命令:

composer require brainbits/phpstan-rules

包简介

PHPStan extension with opinionated strict rules for better code in tests.

README 文档

README

Continuous Integration Coverage Status Codacy Badge Latest Stable Version License

This extension provides highly opinionated and strict rules for test cases for the PHPStan static analysis tool.

Installation

Run

$ composer require --dev brainbits/phpstan-rules

Usage

All of the rules provided by this library are included in rules.neon.

When you are using phpstan/extension-installer, rules.neon will be automatically included.

Otherwise you need to include rules.neon in your phpstan.neon:

# phpstan.neon
includes:
    - vendor/brainbits/phpstan-rules/rules.neon

Rules

This package provides the following rules for use with phpstan/phpstan:

CoversClassExistsRule

This rule checks that classes that are covered by @covers annotation or #[CoversClass] attribute exist.

CoversClassPresentRule

This rule forces you to specify either a @covers annotation or #[CoversClass], #[CoversFunction] or #[CoversNothing] attributes in unit tests (default: PHPUnit\Framework\TestCase).

Why:

  1. It prevents code coverage sums to show higher values than expected.

// tests/ExampleTestCase/Unit/MyInvalidClassTest.php
namespace ExampleTestCase\Unit;

final class MyInvalidClassTest extends \PHPUnit\Framework\TestCase {}

// tests/ExampleTestCase/Unit/MyClassTest.php
namespace ExampleTestCase\Unit;

#[\PHPUnit\Framework\Attributes\CoversClass(MyClass::class)
final class MyClassTest extends \PHPUnit\Framework\TestCase {}

Defaults

  • By default, this rule detects unit tests by checking the namespace (it must contain the string Unit) and the class name ending (it must end with the string Test).

Detecting unit tests namespace

If you want to change the namespace string check described above, you can set your own string to be checked in the unitTestNamespaceContainsString parameter.

# phpstan.neon
parameters:
    brainbits:
        unitTestNamespaceContainsString: CustomTestPath

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-12