free-elephants / static-http-client
PSR-18 implementation for work with file fixtures
0.0.2
2025-04-22 13:55 UTC
Requires
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
Requires (Dev)
- helmich/phpunit-psr7-assert: ^4.2
- nyholm/psr7: ^1.3
- phpunit/phpunit: ^9.4
Suggests
- nyholm/psr7: *
This package is auto-updated.
Last update: 2025-04-23 16:21:43 UTC
README
PSR-18 implementation for testing. Use static files for mock responses and write requests.
Installation
composer require free-elephants/static-http-client --dev
Usage
See tests for more examples.
public function test() { $stubbedHttpClient = new \FreeElephants\StaticHttpClient\StaticHttpClient( $responseFactory, new \FreeElephants\StaticHttpClient\PathResolver\PathBuilderBasedResolver( new \FreeElephants\StaticHttpClient\PathBuilder\Composite( new \FreeElephants\StaticHttpClient\PathBuilder\BasePath(__DIR__), new \FreeElephants\StaticHttpClient\PathBuilder\HostnameAsDirectory(), new \FreeElephants\StaticHttpClient\PathBuilder\AppendRequestPath(), new \FreeElephants\StaticHttpClient\PathBuilder\DefaultFileExtension('.json'), ) ) ); $response = $stubbedHttpClient->sendRequest(new \Nyholm\Psr7\Request('GET', 'https://example.com/foo')); // resolved as __DIR__ . '/example.com/foo.json' }