mcustiel/phiremock-server
PHP HTTP mock/stub server inspired by WireMock. Mock requests by method/headers/URL/body/forms, set responses via REST API, support scenarios, priorities, latency simulation, verification counts, proxying, and loading expectations from JSON files.
Http::fake() but offers advanced features (scenarios, priorities, latency simulation).http://api.example.com to Phiremock).Http::get(), Http::post()) or Guzzle (v6/v7). The PSR-18 factory pattern allows customization (e.g., swapping Guzzle for Symfony’s HTTP client).routes/api.php or a service provider)..env overrides for EXTERNAL_SERVICE_URL to point to Phiremock in local/testing environments).Http::post('/__phiremock/expectations', [...])).phiremock-codeception-extension (reduces boilerplate for acceptance tests).Http::fake() for hybrid mocking strategies.require-dev). Must ensure it doesn’t leak into production (e.g., via composer install --no-dev).composer.json require-dev + CI/CD checks (e.g., composer validate).--port on localhost (avoid network hops) and disable debug mode (--debug=false) in production-like environments.POST /__phiremock/reset after tests). Forgetting to reset can cause flaky tests.setUp()/tearDown() hooks (e.g., Pest’s beforeEach/afterEach) to reset Phiremock.storage/app/phiremock/ and reference them via phiremock.file:path/to/image.jpg).local/testing vs. production? (e.g., .env variables, feature flags).# .env.local
EXTERNAL_SERVICE_URL=http://localhost:8086/mocked_api
# docker-compose.yml
services:
phiremock:
image: composer:latest
command: vendor/bin/phiremock --port 8086
volumes:
- .:/app
/executions) be used for test assertions or runtime monitoring? If the latter, consider adding a Laravel listener to log Phiremock stats.openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
./vendor/bin/phiremock --certificate cert.pem --certificate-key key.pem
Http::get() calls to external services with Phiremock endpoints. Works alongside Laravel’s Http::fake() but offers advanced matching (e.g., regex URLs, body content).services:
phiremock:
image: ghcr.io/mcustiel/phiremock-server:latest
config/services.php:
'stripe' => [
'url' => env('STRIPE_URL', 'http://localhost:8086/stripe_mock'),
],
--expectations-dir to load pre-defined JSON files (e.g., config/phiremock/expectations/).phpunit.xml/pest.php:
<env name="STRIPE_URL" value="http://localhost:8086/stripe_mock"/>
phiremock-client to dynamically set expectations in tests:
use Mcustiel\Phiremock\Client\Client;
$client = new Client('http://localhost:8086');
$client->createExpectation([
'on' => ['method' => ['isSameString' => 'POST'], 'url' => ['isEqualTo' => '/payments']],
'then' => ['response' => ['statusCode' => 200, 'body' => '{"success": true}']],
]);
- name: Start Phiremock
run: composer require-dev mcustiel/phiremock-server --dev && ./vendor/bin/phiremock --port 8086 &
phiremock-codeception-extension for acceptance tests.Pusher mocking for WebSocket services.require-dev)..env and config/services.php to route traffic to Phiremock in non-production environments.--expectations-dir or set dynamically via REST API.# Start Phiremock
./vendor/bin/phiremock --expectations-dir ./config/phiremock/expectations --port 8086
# In tests:
$this->post('/__phiremock/expectations', $expectationJson);
How can I help you explore Laravel packages today?