phpunit

  • PHPUnit 8 wants void on setUp, and it is a fatal error

    8.0 declares void on the template methods, so every override without it is an incompatible signature — which is a fatal error rather than a deprecation warning. It…

  • setUp with a return type, because 7 wants one

    PHPUnit 7 declares void on the template methods, so an override without it is an incompatible signature and a fatal error rather than a warning. It is a…

  • expectException replaced the annotation, quietly

    The @expectedException annotation asserts that the exception happened somewhere in the method, which passes when it is thrown by the setup rather than by the thing under test.…

  • PHPUnit 7 changed the assertion you use most

    7.0 landed in February and deprecated a set of assertions that appear in almost every suite, with removals following in 8 — so the warnings are a deadline…

  • A data provider turns twelve tests into one

    Twelve near-identical test methods differing only in their input is twelve places to update when the method signature changes, and a suite nobody reads. Naming the rows with…

  • Testing what the database actually does

    The repository test passed against a mock and failed against MySQL. A mock asserts what you believe the database does, which is the thing in question.

  • A test that asserts on a query count

    An N+1 does not fail a test — the page renders correctly, just slowly — so the regression ships and is found by a customer three releases later.…

  • Transactions per test are faster than truncation

    Resetting the database between tests by truncating every table costs a statement per table per test, which on forty tables and four hundred tests is sixteen thousand statements.…

  • Mutation testing tells you what coverage does not

    Line coverage says a line executed during the suite. It does not say an assertion would have failed had that line been wrong, which is the question everyone…

  • PHPUnit 6 renamed the classes into a namespace

    Version 6 moved everything under PHPUnitFramework and left aliases for the old names, which are deprecated. Every test file extending PHPUnit_Framework_TestCase needs a line changing. The rename is…