TruckersMP / API-Client

Feature-rich PHP client for TruckersMP API
https://truckersmp.com/developers/api
MIT License
28 stars 15 forks source link

Mock API responses during tests #30

Closed bensherred closed 1 year ago

bensherred commented 2 years ago

When running the test suite, we make a call to the TruckersMP API and use the response to assert our logic. However, this is definitely not how things should be done. This could cause issues if the API is offline for example.

Instead, we should update the test suite to instead mock the response (this could be done by loading an example response/schema from a JSON file) and then test our logic.

This will need a bit of investigation into how we can mock the response as some tests call multiple endpoints.

One thing to note with this is that if the schema was to change i.e. a value changes from a string to a boolean we wouldn't catch that due to the response being mocked. However, it is definitely better to mock the response rather than calling the API.

ShawnCZek commented 1 year ago

This was marked as completed by an accident.