phpunit

  • Data providers run before setUp, every time

    A provider that builds its cases from something created in setUp() fails with a null, because every provider in the class runs before any test does — including…

  • Analysing the tests as well as the source

    Test code is usually excluded from static analysis on the grounds that it is not production code, which is where a good proportion of the useful findings are…

  • Test doubles for an interface you do not own

    Mocking a third-party class binds the test to that class’s current signature, so an upgrade changing a method leaves the test passing against a shape that no longer…

  • phpunit.xml groups let CI split the suite

    A suite that takes twenty minutes gets run less often, which is the opposite of what it is for. Groups let the fast tests gate every push and…

  • Argument order decides how readable the failure is

    PHPUnit takes the expected value first and the actual second, and getting them the wrong way round produces a test that passes and fails identically — but reports…

  • A deployment pipeline that runs the tests first

    Deploying by rsync on a Friday afternoon, and what replaced it: lint, test, build, stage, promote — with a rollback that is the same mechanism rather than a…

  • expectException replaced the annotation

    The @expectedException annotation and setExpectedException() are both deprecated in favour of methods, which is more than a rename — the annotation asserted only that the exception was thrown…

  • Fixtures that build objects, not rows

    A fixture written as SQL or as an array of columns encodes the schema into every test, so a column rename breaks two hundred tests that have nothing…

  • PHPUnit data providers turn six tests into one

    Testing the same behaviour across several inputs usually produces six near-identical methods, and when the assertion needs changing it has to change six times. A data provider separates…

  • A mock asserts an interaction; a stub only answers

    PHPUnit builds both with the same method, which is why the distinction gets lost. A stub exists to let the test proceed — it returns a value. A…