-
Couldn't load subscription status.
- Fork 151
Closed
Labels
ADO to GitHub automation labelIssue caused by core project dependency modules or libraryIssue caused by core project dependency modules or libraryenhancement
Description
I don't see any obvious way of mocking API responses when using this SDK. The problem is that the guzzle client is created in the GraphRequest object, so it can't be provided to the Graph object when instantiating. That makes unit testing really difficult. A proposed solution is to:
- Add an optional argument to the
Graphconstructor and theGraphRequestconstructor, accepting an instance of\GuzzleHttp\Client - Pass the provided client (if any) to the
GraphRequestwhencreateRequestis called - Return the provided client from
GraphRequest::createGuzzleClient- if it was provided during construction at all.
Then you could do this in your unit tests:
$mockGuzzle = $this->createMock(\GuzzleHttp\Client::class);
//mock the response here or use the mock handler in guzzle
$graph = new Graph($mockGuzzle);
$myClient = new MyClient($graph);
$myClient->fetchEmails(); //example method that might be utilizing the SDK to make an API call
Apart from this, do you see other workarounds for writing unit tests that utilize this SDK? The solution with a proxy is not really acceptable for unit tests - though it may be just fine for debugging.
AB#7363
wilmardo and sarzixon
Metadata
Metadata
Assignees
Labels
ADO to GitHub automation labelIssue caused by core project dependency modules or libraryIssue caused by core project dependency modules or libraryenhancement