Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
  1. Home
  2. Blog
  3. What to Test When You Cannot Test Everything
PHP Development

What to Test When You Cannot Test Everything

Practical testing for business PHP applications: why coverage is the wrong target, testing calculations and money paths first, and handling legacy code.

Updated 2 min readBy SpiderHunts Technologies

Free estimateNo obligation

Get a free estimate

Tell us what you need. A senior engineer reads every enquiry.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →

Quick answer — TL;DR

Test the calculations, the money paths and the things that would be expensive to get wrong. Complete coverage is not the goal; confidence in the parts that matter is.

Coverage is the wrong target

Chasing a coverage percentage produces tests of trivial code and leaves the complicated parts untested, because they are harder to write tests for.

The useful question is not how much is tested but whether you could change the code confidently.

What to test first

  1. Calculations — pricing, tax, commission, anything with arithmetic
  2. Money paths — payment, refunds, invoicing
  3. Authorisation — who can see and do what
  4. Integrations — what happens when the other system fails
  5. Anything that has broken before
The last one is the most useful heuristic. A bug that has occurred once will occur again unless a test prevents it.

Different tests for different jobs

TypeUse for
Unit testsCalculations and business rules
Integration testsDatabase interactions and queries
Feature testsComplete user journeys
Contract testsExternal API expectations

A small number of feature tests covering the main journeys catches more real problems than a large number of unit tests on trivial methods.

Make them run automatically

Tests that require someone to remember to run them stop being run within a month. They should run on every push, automatically, with a visible result.

That is a day of setup and it is what turns a test suite from a nice idea into a working safety net.

Testing legacy code

  • Start with characterisation tests — capture current behaviour
  • Test at the highest level you can, since units may be untestable
  • Add tests when you touch a piece of code, not as a separate project
  • Accept partial coverage; it is better than none

FAQ

Frequently asked questions

The questions readers ask us after this guide.

Still have a question?

Ask us directly — a senior engineer will get back to you.

Ask about your project

How much testing is enough?

Enough that you can change the code without fear. That is usually far less than complete coverage and far more than nothing.

Does testing slow development?

Initially. It speeds it up considerably once the application is large enough that manual verification is impractical.

Can we add tests to a legacy application?

Yes, incrementally. Characterisation tests around what you are about to change is the practical approach.

Should tests use a real database?

For integration tests, yes — a test database. Mocking the database tests your mocks rather than your queries.

Keep reading

More on PHP Development

PHP Development

Why PHP Is Still a Sensible Choice

Is PHP still a good choice for business applications? Where modern, typed PHP fits, where another language is better, and the hosting and hiring arguments.

PHP Development

Improving Old Code Without a Rewrite

Modernising a legacy PHP application without a rewrite: move to a supported PHP version, add tests around what matters, then strangle rather than replace.

Start here

Afraid to change your own application?

That fear is what tests remove. Start with the calculations and the money paths.

  1. You tell us what you needTwo minutes on the form, or a message on WhatsApp.
  2. A senior engineer reviews itAnd comes back with questions, a realistic range and an honest view on fit.
  3. Free 30-minute scoping callWe talk through scope, options and a realistic estimate — with no obligation.
Free estimateNo obligation

Talk to someone who builds this

Send a short brief and we will come back with an honest view and a realistic range.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →