PHPackages                             elijahb/phpcs-testability - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. elijahb/phpcs-testability

ActiveLibrary[Testing &amp; Quality](/categories/testing)

elijahb/phpcs-testability
=========================

PHPCodeSniffer sniffs for unit test code testability check

v1.0.0-alpha(9y ago)0281PHP

Since Jan 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/elijahb/phpcs-testability)[ Packagist](https://packagist.org/packages/elijahb/phpcs-testability)[ Docs](https://github.com/elijahb/phpcs-testability)[ RSS](/packages/elijahb-phpcs-testability/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

PHP CodeSniffer - Sniffs for testable code
==========================================

[](#php-codesniffer---sniffs-for-testable-code)

[![Build status](https://camo.githubusercontent.com/82514aa1157dd84b352cb4acdf7d194a722e51a2d29d1bc115b705a9199ede53/68747470733a2f2f7472617669732d63692e6f72672f656c696a6168622f70687063732d746573746162696c6974792e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/82514aa1157dd84b352cb4acdf7d194a722e51a2d29d1bc115b705a9199ede53/68747470733a2f2f7472617669732d63692e6f72672f656c696a6168622f70687063732d746573746162696c6974792e7376673f6272616e63683d6d6173746572)

Introduction
------------

[](#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-&gt;property-&gt;service-&gt;method-&gt;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
----------

[](#how-to-use)

1. Install [PHPCodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
2. Install phpcs-testability using Composer

```
composer require --dev elijahb/phpcs-testability

```

3. Add the standard to your custom PHPCodeSniffer ruleset.xml file

```

```

Recommendations
---------------

[](#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.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3447d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17621442?v=4)[elijah0](/maintainers/elijah0)[@Elijah0](https://github.com/Elijah0)

---

Tags

phpcsphpunitsniffphp-code-sniffer

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/elijahb-phpcs-testability/health.svg)

```
[![Health](https://phpackages.com/badges/elijahb-phpcs-testability/health.svg)](https://phpackages.com/packages/elijahb-phpcs-testability)
```

###  Alternatives

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k940.0M151.2k](/packages/phpunit-phpunit)[brianium/paratest

Parallel testing for PHP

2.5k129.9M931](/packages/brianium-paratest)[wp-coding-standards/wpcs

PHP\_CodeSniffer rules (sniffs) to enforce WordPress coding conventions

2.8k47.8M2.1k](/packages/wp-coding-standards-wpcs)[slevomat/coding-standard

Slevomat Coding Standard for PHP\_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.

1.5k134.0M2.1k](/packages/slevomat-coding-standard)[dealerdirect/phpcodesniffer-composer-installer

PHP\_CodeSniffer Standards Composer Installer Plugin

601175.5M2.3k](/packages/dealerdirect-phpcodesniffer-composer-installer)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69619.8M615](/packages/spatie-phpunit-snapshot-assertions)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
