Repository navigation
Development
Daniel Carbone edited this page Nov 6, 2026
·
2 revisions
git clone https://github.com/dcarbone/php-consul-api.git
cd php-consul-api
composer installThe static analysis and refactoring tools each have their own composer.json under tools/, so their dependencies
don't conflict with the library's:
composer install --working-dir tools/rector
composer install --working-dir tools/phpstan
composer install --working-dir tools/psalmTests live under tests/Unit and tests/Integration.
# unit tests only; no Consul needed
./vendor/bin/phpunit -c phpunit.xml --testsuite unit
# everything
./vendor/bin/phpunit -c phpunit.xml
# a single integration suite
./vendor/bin/phpunit -c phpunit.xml --testsuite usage-kv| Suite | Contents |
|---|---|
unit |
tests/Unit |
usage-config |
Config integration |
usage-config-states |
Config end-to-end: address formats, unix socket, token precedence, TLS/mTLS |
usage-request |
Request integration |
usage-acl |
ACL client |
usage-agent |
Agent client |
usage-catalog |
Catalog client |
usage-coordinate |
Coordinate client |
usage-event |
Event client |
usage-kv |
KV client |
usage-operator |
Operator client |
usage-session |
Session client |
usage-random |
additional client coverage (tests/Integration/Random) |
Integration tests start and stop a single consul agent -dev themselves (tests/ConsulManager.php,
tests/run_consul.sh, tests/stop_consul.sh). This means:
- The
consulbinary must be on yourPATH. CI uses the version inCONSUL_VERSIONin.github/workflows/tests.yaml. - Nothing else may be listening on
127.0.0.1:8500. - The agent uses
tests/consul.hcl, with ACLs enabled and management token00000000-0000-0000-0000-000000000001. - Data, the PID file, and logs are written to
tmp/(tmp/consul.logis useful when a test fails). -
usage-config-statesalso generates a CA and certificates withconsul tlsintotmp/tls, and starts the agent with a unix socket (tmp/consul.sock) and an HTTPS listener on127.0.0.1:8501that requires a client certificate.opensslis used to build a hashedCAPathdirectory; theCAPathtest is skipped without it.
composer rector -- --dry-run # check
composer rector # apply
composer phpstan
composer psalmRector (rector.php) handles both refactoring and code style. CI runs all three, plus the
test suite against PHP 8.2, 8.3, 8.4, and 8.5.
-
declare(strict_types=1);in every source file. Test files don't use it. - Use
null|Foorather than?Foo. - Use
selfas the return type of fluent setters. - List fields have variadic setters (
setTags(string ...$Tags)).arrayparameters have a docblock giving the element type. - Each model field has a matching constructor parameter, getter, and setter, all with the same casing as the property.
- Methods that return nothing are declared
: void, including test methods. - Use named arguments where possible.
- Only add docblocks to describe types that can't be expressed natively.
-
uint64fields areBigInteger(see Big Integers). Duration fields areTime\Duration(see Durations and Time). - New models should mirror the Go struct in
hashicorp/consul/api, including field names andomitemptybehaviour. - Model tests should set fields through both the constructor and the setters, and verify them through both the getters and the properties.