Is there any tool that reports on the testability of a PHP codebase?

I'm familiarised with what makes the code unit-testable, but I need a way to visualize it so I can easily find which classes can already be tested, and which ones will need some refactoring (and how much of it).

I'm pretty sure there are several tools for the job for other languages, but I can't find anything for PHP.

3 Answers 3


How about the PHP Mess Detector, it generates all kinds of metrics about the code.

Although its focus is not test-ability I think cleaning up the "mess" will lead to much better testable code. Since its a rules based system and open-source you could add more rules that are test-ability specific, maybe its possible to borrow rules from other products.

  • My problem with phpmd is the abstractness of all the metrics it outputs. Also, I looked around about creating my own metrics, but couldn't find anything relevant. Do you have any links you could share? Sep 24, 2014 at 22:15
  • @EdsonMedina, what do you mean by the "abstractness"? Any example would help me understand.
    – dzieciou
    Sep 25, 2014 at 6:58
  • Maybe I'm being unfair, but metrics like code complexity, coupling between objects and such sound interesting but not so useful. It's hard to go through the code and find stuff that is easy to test right now by interpreting those numbers. Maybe there should be a combined metric (testability) and a issue browser for what's making the code hard to test. Am I reinventing the wheel or thinking wrong? Sep 25, 2014 at 8:41
  • Why are you looking for stuff that is easy to test? Isn't it wiser to focus on parts that are complex and high risk. If you write tests now, its easier to refactor later. Sep 25, 2014 at 9:19
  • I'm training a team into unit-testing. They have to start somewhere! But either way, having a tool telling me what issues I must fix to make the code testable would be killer. Sep 26, 2014 at 16:41

Take a look at SonarQube. It has some good code complexity metrics. Since code complexity generally translates to test-ability, it will give you a good idea which areas of the code need refactoring.

It also gives you some metrics on unit-test coverage. I find the historical aspect of this metric to be helpful. As code is added and/or refactored, I like to see the overall percentage of unit test coverage to increase or at least stay the same. If the overall test coverage is decreasing, I know there is too much coding going on without unit testing.

  • Doesn't SonarQube use the ouput of PHPMD? Sep 24, 2014 at 22:13
  • I can't say for certain because I'm not that familiar with the inner workings of SonarQube, but based on the fact that SonarQube supports plug-ins for several different programming languages, I'm guessing no.
    – semaj
    Sep 25, 2014 at 15:59

Since there was no tool to do what I needed, I wrote one.


  • 2
    Hi there, great package, thank you so much for it, I've been using it for training my team, in recent installations I noticed the message from composer: Package edsonmedina/php_testability is abandoned, you should avoid using it. No replacement was suggested. Why is that?
    – Anfelipe
    Aug 2, 2018 at 22:39
  • @Anfelipe I haven't manintained it in years. Sorry. Aug 3, 2018 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.