Need to switch to use dependency injection. I think that all APIs will extend from a new class, Bkwld\Library\Api\Container. This would have a method called setSession()
which I would pass Laravel's $app->make('session')
to. Then, all the current static session functions would be switched to instance methods. So to run one one, it woud be like:
$instagram_user = new Bkwld\Library\Api\Instagram\User();
$instagram_user->setSession($app->make('session'));
$feed = $instagram_user->feed();
To make this easier, I add to the Container class
a __callStatic
magic method. I'm hoping that I can have calls to Bkwld\Library\Api\Instagram\User::feed()
make a new instance of Bkwld\Library\Api\Instagram\User and then call the instance feed
. If not, I'll make the calls like Bkwld\Library\Api\Instagram\User::getFeed()
.
To mock the API calls, I should be able to just mock the APIs that have a PHP SDK that you invoke the API with. For APIs where I am CURLing, (like Instagram), I'll add a curl
public method to the API container (Bkwld\Library\Api\Instagram->curl($url)
) which I can mock. This method responds with a data object containing data
(the response) and code
(the http code).
Then, to actually run the tests, I'll save the JSON/XML output from the APIs to the test as a string and use that as the mocked response from the API calls.