0

I'm implementing the server API (for geni.com) in PHP. The server requires OAuth authentication, so I need a browser because this requires user input (to permit access to their account). THIS all works fine.

Now I want to use PHPUnit to test the whole thing. My index.php calls the testsuite, and I THINK the tests are running (no errors in log, and it continues running past the call). Obviously there is no console for the output.

So HOW can I capture the test results?

10
  • 3
    As far as I am aware PHPUnit is not meant to run via a browser e.g. a “web request”. It’s inherently a cli tool. Commented May 1 at 16:32
  • 1
    absolutely what @Tyrsson commented on, and to stress this: it is not only meant to run isolated, you must only run it isolated as otherwise you will endanger the system with the high chance of an outbreak. for testing with OAUTH you need to use test or API credentials or use a test interface. also do not test against a server API but only against the interface of the API. You capture the behaviour of the API once and then interface against it, providing the captured data. this is similar how you test APIs on the same server and even within the same runtime (a.k.a. classes). Commented May 1 at 17:33
  • Not sure what you mean by "outbreak", but MY server is a toy created for this specific purpose. So I'm not particularly worried about it. IF I understand you correctly, you're talking about mocking the remote server. But I need to change data ON that server. Otherwise yeah, I'd just use the CLI. Commented May 1 at 18:06
  • 1
    It might help if you would update your question with an example of what kind of data you need to change on the server. My gut says you are conflating two different types of testing. Commented May 1 at 18:39
  • 1
    You might need to bootstrap the auth handshake manually, but you can then store the refresh token and use that in your tests. Commented May 4 at 0:51

1 Answer 1

0

Realizing how silly my question was, I took the advice of @Chris Haas.

I modified my main php script to just do the authentication, and save the tokens. I then used the phpunit CLI to run my test code, which read the saved tokens on start up.

Thanks Chris. Solved my problem and gave me more robust code. Win-win.

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

Comments

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.