restate / testing
Test harness for Restate PHP services: starts Restate in a container and your endpoint, registers it and hands out an ingress client. Install it as a dev dependency.
Requires
- php: ~8.4.0 || ~8.5.0 || ~8.6.0
- ext-filter: *
- ext-json: *
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
- restate/common: v0.1.0
- restate/ingress: v0.1.0
Requires (Dev)
None
Suggests
- ext-pcntl: Lets a test run interrupted with Ctrl-C (SIGINT) or SIGTERM stop the Restate container and the endpoint it started.
- ext-posix: Lets RestateTestEnvironment::killEndpoint() signal the php -S workers directly instead of running kill(1).
- guzzlehttp/guzzle: The default PSR-18 client of Restate\Testing\RestateTestEnvironment::ingressClient().
- guzzlehttp/psr7: The default PSR-17 factories of Restate\Testing\RestateTestEnvironment::ingressClient() (guzzlehttp/guzzle requires it).
- phpunit/phpunit: Required to use the Restate\Testing\PHPUnit\InteractsWithRestate trait (PHPUnit 10 or newer).
Provides
None
Conflicts
None
Replaces
None
README
Restate\Testing\RestateTestEnvironment runs integration tests of your Restate services against a real Restate server: it starts Restate in a container, serves your endpoint script with php -S and the Restate PHP extension loaded (or runs your own endpoint image), registers it, and hands out an ingress client (restate/ingress) connected to it. With PHPUnit, the InteractsWithRestate trait shares one environment per process across test classes and prints the Restate and endpoint logs when a test fails. It also restarts, pauses or kills either side for tests of failure handling.
Note
A community-maintained SDK: not an official Restate SDK, and not supported by Restate.
Installation
composer require --dev restate/testing guzzlehttp/guzzle
Guzzle is the default HTTP client of ingressClient(); pass your own PSR-18 client and PSR-17 factory otherwise.
Usage
use PHPUnit\Framework\TestCase; use Restate\Testing\PHPUnit\InteractsWithRestate; use Restate\Testing\PhpCliServer; final class GreeterTest extends TestCase { use InteractsWithRestate; protected static function restateEndpoint(): PhpCliServer { return PhpCliServer::forScript(__DIR__ . '/../public/restate.php'); // the script that calls Endpoint::serve() } public function testGreets(): void { $greeter = self::restate()->ingressClient()->serviceClient('Greeter'); self::assertSame('Hello Mary', $greeter->request('greet', 'Mary')->call()); } }
Without PHPUnit, RestateTestEnvironment::start(PhpCliServer::forScript(...)) returns the same environment as a plain object.
Requirements
- PHP 8.4, 8.5 or 8.6
- Docker or podman (rootless works), or
restate-serveronPATHwithRestateProcess::default()instead of the default container, which needs no container runtime withphp -S, or a Restate that already runs (ExternalRestate, such as the onedevenv upstarts) - The Restate PHP extension where the endpoint runs (the
php -Schild or your image), not in the test process; the harness does not requirerestate/sdk, your project does - PHPUnit 10 or newer for the trait only
Documentation
See Testing for every option, and the documentation for the rest of the SDK.
This repository is a read-only subtree split of restate-php/restate. Report issues and send pull requests there.
License
MIT; see LICENSE.