Skip to content

Real servers

phil/dev-tools

The integration tests of a package run against real servers when their URL is in the environment, and are skipped otherwise, so that composer test and phil-dev check-packages pass on a machine without them.

vendor/bin/phil-dev services up
eval "$(vendor/bin/phil-dev services env)"
composer test:services
vendor/bin/phil-dev services down

resources/compose.yaml holds the servers, under the project name phil-dev-tools, bound to 127.0.0.1, with their data in tmpfs: they start empty and leave nothing behind.

ServerImagePortVariableValue from services env
MySQL 8mysql:8.413306 (PHIL_DEV_MYSQL_PORT)PHIL_TEST_MYSQL_URLmysql://phil:phil@127.0.0.1:13306/phil_test?serverVersion=8.4
PostgreSQL 17postgres:17-alpine15432 (PHIL_DEV_POSTGRESQL_PORT)PHIL_TEST_POSTGRESQL_URLpostgresql://phil:phil@127.0.0.1:15432/phil_test?serverVersion=17
Gotenberg 9gotenberg/gotenberg:93011 (PHIL_DEV_GOTENBERG_PORT)PHIL_GOTENBERG_URLhttp://127.0.0.1:3011

Port 3999 stays free: a Mercure hub used by tests listens there. A variable already set is kept.

The file also holds frankenphp (dunglas/frankenphp:1-php8.5, port 8090, moved by PHIL_DEV_FRANKENPHP_PORT), under the bench profile: services up leaves it out, and phil-dev bench:worker starts it with the worker script of a package; see Benchmarks.

In a test

$url = ServiceUrl::first('PHIL_EXAMPLE_TEST_DATABASE_URL', 'PHIL_TEST_POSTGRESQL_URL')
    ?? self::markTestSkipped('No PostgreSQL to test against.');

A package that needs a variable of its own — a database of its own, a timestamp authority — names it first, falls back on the shared one, and documents it in its doc/testing.md.

The databases are tested against the containers only. The HTTP services — Gotenberg, a model provider, a geolocation database — are recorded once against the containers or the real service and replayed offline: see HTTP recordings.