Important
Active development lives in rapira-rs/sdk-php under packages/testing/. This repository is automatically synchronized from there on every release.
File issues and pull requests in the main monorepo, not here.
Lets tests exercise a PHP application over a real socket instead of mocking the server: it downloads the rapira binary for a suite and starts a live rapira serve process around your test cases. The core is framework-neutral; a thin Testo adapter is shipped on top of it.
composer require --dev rapira/testingThe rapira binary is downloaded on demand via DLoad the first time a suite that needs it runs.
Attach RunRapiraPlugin to the suite in testo.php. It downloads the rapira binary (once, if missing) and binds the application directory the server runs from.
use Rapira\Sdk\Testing\Testo\RunRapiraPlugin;
use Testo\Application\Config\ApplicationConfig;
use Testo\Application\Config\Plugin\SuitePlugins;
use Testo\Application\Config\SuiteConfig;
return new ApplicationConfig(
src: ['src'],
suites: [
new SuiteConfig(
name: 'Integration',
location: ['tests/Integration'],
plugins: SuitePlugins::with(new RunRapiraPlugin(
binary: __DIR__ . '/runtime/bin/rapira',
workingDirectory: __DIR__ . '/tests/Integration/App',
)),
),
],
);Annotate a test case with #[RunRapira]. Testo starts rapira serve before the case's tests and stops it afterwards.
use Rapira\Sdk\Common\Mode;
use Rapira\Sdk\Testing\Testo\Attribute\RunRapira;
use Testo\Attribute\Test;
#[RunRapira(mode: Mode::Worker, worker: 'worker.php', address: '127.0.0.1:8080')]
final class WorkerTest
{
#[Test]
public function respondsToRequests(): void
{
$response = file_get_contents('http://127.0.0.1:8080/');
// ...assertions on $response
}
}RunRapira options:
| Option | Default | Description |
|---|---|---|
mode |
Mode::Worker |
Run mode passed as --mode (classic, worker, or dispatcher). |
worker |
'worker.php' |
Entrypoint script, absolute or relative to the working directory. |
address |
'127.0.0.1:8080' |
Listen address (host:port, :port, or unix:<path>). |
healthPath |
'/' |
Path polled for readiness; must answer 2xx once the app serves. |
readyTimeout |
5.0 |
Seconds to wait for the server to answer before failing. |