Just wanted to open an issue here to let people know that I am currently working on a mocking system for Saloon. It's going to introduce two ways to mock in Saloon, one way would be the "Larvel" way - inspired by the wonderful testing that is provided by Illuminate/Http. The other way would require a bit more intervention but I hope would still be useful especially when writing SDKs.
Laravel Mocking
Laravel mocking will have slightly more features than the standard PHP mocking that can be used within SDKs. This is because Laravel has a super powerful service container. See the testing page for the HTTP Client in the Laravel docs. I will recreate how it works there.
Mocking for SDKs
SDK mocking is slightly different, but the idea is that you will be able to tell Saloon to send a fake response when a request has been created.
$mockClient = new SaloonMockClient();
$mockClient->addResponse(200, $data, $headers);
$mockClient->addResponse(500, $data, $headers);
$response = (new SaloonRequest)->send($mockClient); // 200
$response = (new SaloonRequest)->send($mockClient); // 500
Here's an example of how it could be implemented
$sdk = new ForgeSdk($token, $saloonMockClient);
$sdk->getServers(); // Internally sends $saloonRequest->send($this->mockClient);
Extra Features
Interceptors and handlers to have a new argument to specify if they can be run during tests
Saloon plugins to have a new argument to specify if they can be run during tests
Just wanted to open an issue here to let people know that I am currently working on a mocking system for Saloon. It's going to introduce two ways to mock in Saloon, one way would be the "Larvel" way - inspired by the wonderful testing that is provided by
Illuminate/Http
. The other way would require a bit more intervention but I hope would still be useful especially when writing SDKs.Laravel Mocking
Laravel mocking will have slightly more features than the standard PHP mocking that can be used within SDKs. This is because Laravel has a super powerful service container. See the testing page for the HTTP Client in the Laravel docs. I will recreate how it works there.
Mocking for SDKs
SDK mocking is slightly different, but the idea is that you will be able to tell Saloon to send a fake response when a request has been created.
Here's an example of how it could be implemented
Extra Features