DoSomething / gateway

:lock_with_ink_pen: An opinionated PHP REST API client.
MIT License
2 stars 0 forks source link

Experimental: Automatically configure Gateway mocks. #106

Closed DFurnes closed 3 years ago

DFurnes commented 6 years ago

What's this PR do?

Okay - this is a kinda wild idea, but I'm pretty excited about it. We spend a fair amount of time in test suites mocking out external API calls by setting per-test mocks (when I ask for this thing, give me this instead). What if we instead swapped out the entire client with a mocked version?

This pull request introduces a WithGatewayMocks trait for PHPUnit that configures a mock version of the Northstar client, and automatically returns fake data for any calls to getUser. We seed the Faker instance based on the request, so while it's "random" data it's still completely deterministic!

For example, no matter how many times I ask for a user with ID 5543dfd6469c64ec7d8b46b3 it'll always be named "Zoe Koepp". This would make it dead-simple for an application like Rogue to mock out a ton of Northstar requests without any manual configuration.

How should this be reviewed?

This is just a proof-of-concept. If others are excited about this, I'll put some more time into it to get an MVP that we can actually merge in and start using.

Checklist