GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - brainbits/phpstan-rules: brainbits phpstan rules

BranchesTags
Open more actions menu

Latest commit

 

History

46 Commits
46 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.releaserc
.releaserc
 
 
CLAUDE.md
CLAUDE.md
 
 
README.md
README.md
 
 
codecov.yml
codecov.yml
 
 
composer.json
composer.json
 
 
phpcs.xml.dist
phpcs.xml.dist
 
 
phpstan.neon.dist
phpstan.neon.dist
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 
rules.neon
rules.neon
 
 

Repository files navigation

PHPStan Clean Test rules

Build codecov Latest Stable Version License Total Downloads

  • PHPStan
  • PHPStan-PHPUnit extension

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:

  • BrainbitsPhpStan\CoversClassExistsRule
  • BrainbitsPhpStan\CoversClassPresentRule

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.

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 treats a class as a unit test if it extends another class, its namespace contains the string Unit and its name ends with Test. The parent class itself is not checked.

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

About

brainbits phpstan rules

Resources

Readme
Activity
Custom properties

Stars

3 stars

Watchers

3 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.