Testing against PHP

A port of a PHP package promises PHP's behaviour. We check that promise by running PHP, not by reading its code and reasoning about it.

The method

  1. Cases. The port keeps case files: each one names a call and its exact inputs, and fixes the clock where the result depends on time.
  2. PHP records the expected results. A pinned PHP project runs every case and records what PHP returns, exceptions included. The project fixes the PHP version, its extensions and every Composer package to an exact version. The recorded fixtures are checked in with a header that names those versions. Nobody edits a fixture by hand.
  3. The port must match. The port's tests run the same cases and compare its results with the fixtures: strings byte for byte, numbers to the exact value, and types, key order and errors wherever PHP tells them apart.
  4. The fixtures are regenerated, not patched. When the PHP package releases a new version, the port re-pins it, regenerates the fixtures and checks every difference. If the new version changes PHP's output, following it is a breaking change for the port.

Accounting for every ability

Each port keeps a coverage list with one row per ability of the original package: every public method, helper, config key and its default, route, command, view and event. Each row is one of:

A port's parity level follows from those rows:

LevelMeaning
PartialSome of the abilities a typical app uses are still planned.
CoreEvery ability a typical app uses is covered or diverged.
FullEvery ability is covered or diverged. This is the target for every port.

Diverged rows count as accounted for, not as covered. A release claims only rows that have tests.

Documented differences

Some differences can't be avoided: a newer Unicode table, an input type that PHP accepts and Rust's type system rules out, a platform library at another version. A port lists each one on its "Differences from PHP" page, with the reason and, where it helps, an example. A difference that is written down is one you can plan around.

An example

laravel-rust-format follows Laravel's string, number and date formatting. Its parity page lists the PHP and ICU versions behind each fixture set, the number of cases in each group, and every known difference.