2017 © Pedro Peláez
 

library phpcs-testability

PHPCodeSniffer sniffs for unit test code testability check

image

elijahb/phpcs-testability

PHPCodeSniffer sniffs for unit test code testability check

  • Monday, January 23, 2017
  • by elijah0
  • Repository
  • 1 Watchers
  • 0 Stars
  • 245 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 7 % Grown

The README.md

PHP CodeSniffer - Sniffs for testable code

Build status, (*1)

Introduction

This project provides sniffs for some design patterns that improve unit test code testability:, (*2)

  • 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:, (*3)

  • 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:, (*4)

  • 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., (*5)

The Versions

23/01 2017

dev-master

9999999-dev https://github.com/elijahb/phpcs-testability

PHPCodeSniffer sniffs for unit test code testability check

  Sources   Download

The Requires

 

The Development Requires

phpunit phpcs sniff php-code-sniffer

22/01 2017

v1.0.0-alpha

1.0.0.0-alpha https://github.com/elijahb/phpcs-testability

PHPCodeSniffer sniffs for unit test code testability check

  Sources   Download

The Development Requires

phpunit phpcs sniff php-code-sniffer