-
-
Notifications
You must be signed in to change notification settings - Fork 43
Testing
php-fhir has two layers of tests:
-
Generator tests — unit tests for the generator itself (the
src/code). - Generated code tests — PHPUnit tests produced by the generator alongside the FHIR type classes.
Located in tests/ and run with the PHPUnit configs under phpunit/.
# Run the generator's own unit tests (Config, etc.)
vendor/bin/phpunit -c phpunit/Builder.xmlDuring generation the builder writes a full suite of PHPUnit tests into the configured testsPath.
These tests cover:
- Core constants and encoding/client configuration classes.
- Per-version constants, type maps, and individual type serialization round-trips.
The test bootstrap (phpunit/bootstrap.php) performs three steps:
- Requires the Composer autoloader.
- Generates code for the requested test target (unless
PHPFHIR_TEST_SKIP_GENERATE=true). - Requires the generated
Autoloader.phpandTestAutoloader.php.
The test target is selected via the PHPFHIR_TEST_TARGET environment variable.
| File | Target | Description |
|---|---|---|
phpunit/Core.xml |
Core |
Only generates & tests shared core classes (no FHIR versions). |
phpunit/Versions.xml |
Versions |
Generates all configured versions, tests version-level entities. |
phpunit/DSTU1.xml |
DSTU1 |
Generates & tests DSTU1 only. |
phpunit/DSTU2.xml |
DSTU2 |
Generates & tests DSTU2 only. |
phpunit/STU3.xml |
STU3 |
Generates & tests STU3 only. |
phpunit/R4.xml |
R4 |
Generates & tests R4 only. |
phpunit/R4B.xml |
R4B |
Generates & tests R4B only. |
phpunit/R5.xml |
R5 |
Generates & tests R5 only. |
phpunit/Builder.xml |
— | Tests for the generator code itself. |
# Generate + test R4:
PHPFHIR_TEST_TARGET=R4 vendor/bin/phpunit -c phpunit/R4.xml
# Skip regeneration if output already exists:
PHPFHIR_TEST_SKIP_GENERATE=true PHPFHIR_TEST_TARGET=R4 vendor/bin/phpunit -c phpunit/R4.xml# Core (shared) tests
PHPFHIR_TEST_TARGET=Core vendor/bin/phpunit -c phpunit/Core.xml
# All versions
PHPFHIR_TEST_TARGET=Versions vendor/bin/phpunit -c phpunit/Versions.xmlResource types include serialization tests that can optionally run against a live FHIR server. The test server companion project is: dcarbone/php-fhir-test
Set the following environment variable to enable server tests:
export PHPFHIR_TEST_SERVER_ADDR=http://localhost:8080/fhirWhen this variable is unset, server-dependent assertions are skipped.
Some tests download real FHIR example bundles. The download directory can be controlled via:
export PHPFHIR_TEST_RESOURCE_DOWNLOAD_DIR=/path/to/cacheNext: Contributing →