guzzlehttp/test-server is a testing helper for PHP HTTP clients. It starts a
local Node.js HTTP server, lets your tests queue responses, and records the
requests your client sends.
Most Guzzle client tests should use Guzzle's MockHandler and History Middleware instead of a real server. Use this package for handler tests and integration tests that need a predictable HTTP endpoint. It is not intended to be a general-purpose web server or a production dependency.
composer require --dev guzzlehttp/test-server
The server requires Node.js ^20.19 || ^22.13 || >=24 available as node.
| Version | Status | PHP Version |
|---|---|---|
| 1.0 | Latest | >=7.4,<8.6 |
| 0.7 | Maintenance | >=7.2.5,<8.6 |
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Server\Server;
$client = new Client();
Server::start();
register_shutdown_function(static function (): void {
Server::stop();
});
Server::enqueue([
new Response(201),
]);
$response = $client->request('GET', Server::$url);
echo $response->getStatusCode();
// 201
$requests = Server::received();
echo $requests[0]->getMethod();
// GET
Guzzle Test Server is made available under the MIT License (MIT). Please see License File for more information.
How can I help you explore Laravel packages today?