0

I'm wondering if there is some way to do unit testing using the Google API for authentication using the Google API PHP Client.

Here is the kind of code example that I want to use around my unit testing case. (but i want to do more complicated things around it of course that is why i need to do unit testing)

http://code.google.com/p/google-api-php-client/source/browse/trunk/examples/userinfo/index.php

1 Answer 1

2

It is messy, but possible. It is not going to be exactly unit testing, but still...

You need to

  • either write stubs for the parts of your code which do actual requests to the google api, which would return predefined responses which your code needs to be ready for.
  • or create a simple separate service in your local network which would behave like google api web service. It is easier than it sounds - a simple php script with a switch and a readfile(responseFileNumberN)...

Either way you need to decide which of google's behaviours/errors you need to emulate. Testing on live service is a bad idea. This way you are going to test google's api which is out of your control or your network connection, not your app.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks kgb, i'm gonna give a try to this :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.