rapira / testing
Testing utilities for Rapira: provisions the server binary and runs a live server around your tests
Fund package maintenance!
Requires
- php: >=8.4
- internal/dload: ^1.14
- internal/path: ^1.3
- psr/log: ^2.0 || ^3.0
- testo/testo: ^0.10.42
Requires (Dev)
- rapira/contract: dev-master
README
rapira/testing
Important
🪞 This is a read-only mirror.
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.
About
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.
Install
composer require --dev rapira/testing
The rapira binary is downloaded on demand via DLoad the first time a suite that needs it runs.
Usage with Testo
1. Provision the binary for a suite
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', )), ), ], );
2. Run the server around a test case
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. |