@kboyd @grmpyprogrammer yep.
1. write abstraction wrapper layer
2. write tests (of the consumers) with mocks for that layer
3. write integration tests for that layer that call the other API.
The tests in 2 run all the time as part of your automated tests of your consuming code, the tests in 3 run periodically, maybe not even automatically, and confirm that your integration with the 3rd party still works.
(and no, that's NOT how some of our tests work, but if I had a magic wand....)
If wishes were horses, I'd be making a killing in the manure market.
@grmpyprogrammer Occasionally simple override when I don't care (and there are few points of injection), but mostly API adapter & test double implementing my own port (could be multiple for same library).
It often comes with a bonus of encapsulating redundant arguments. Especially when API is used in different contexts (multiple specialized adapters)
@grmpyprogrammer API itself (adapter) is tested on itegration level (with their mocks/fakes if provided).
Oh, and for libraries without side effects I usually don't bother and test them together until decomposition when test cases multiply on branching logic.
@afilina @grmpyprogrammer
I have an implementation where the simple built in PHP server is started (using symfony process component) before the integration tests, for my crawler package here: https://github.com/crwlrsoft/crawler/blob/main/tests/Pest.php#L24
If you can swap out the base URL for the API in your consumer, this could be a solution. Mocking could maybe be a bit easier, but I more and more like to avoid mocking as much as possible.
@grmpyprogrammer How extensive is the API interaction? Mocking could be an option unless it means completely reimplementing stone else's platform.
Is it feasible to build a fixture/testing implementation of the API that you can launch/run locally? Might be more efficient and/or less annoying than mocking frameworks.