-
Notifications
You must be signed in to change notification settings - Fork 0
Testing
The Marketstack PHP SDK comes with a comprehensive test suite to ensure code quality and reliability. This guide covers how to run the tests and how to write tests for your own application that uses this package.
To run the built-in test suite, you can use the following Composer script:
composer testTo run the tests with code coverage, you can use:
composer test -- --coverageWhen writing tests for your application, you should mock the API responses from the Marketstack API to avoid making actual HTTP requests. This makes your tests faster, more reliable, and independent of network conditions.
Laravel's Http::fake() provides a convenient way to do this. You can fake the responses for any URL matching the Marketstack API endpoints.
use Illuminate\Support\Facades\Http;
use Tigusigalpa\Marketstack\Facades\Marketstack;
Http::fake([
'api.marketstack.com/*' => Http::response(['data' => [/* mock data */]], 200)
]);
$data = Marketstack::eod()->symbols('AAPL')->collect();
// Assert that the data is what you expect
$this->assertCount(1, $data);By faking the HTTP responses, you can test how your application handles different API scenarios, including successful responses, errors, and empty results, without ever hitting the actual API.