I working on a site that will use Wordpress's Jetpack user agent class for device detection. Hey I know the many debates about the validity of such testing and don't need any help deciding not to do this. I don't have a choice but to use it.
If testing using PHPUnit on the command line how would one write tests that could capture the User_Agent strings? Any ideas if this can be done?
Wouldn't this be a case for Mocking? I'd argue you'd want to write a component/class that has a primary purpose of getting that data. Then you can mock that class and test against the mock.
Another approach would be to create a class that receives $SERVER as input, then pass in your own $SERVER (which contains HTTP_USER_AGENT) so you can pass in whatever you want for HTTP_USER_AGENT.
Yes this could be done with mocking. I think I wire it up doing this!
This topic is now closed. New replies are no longer allowed.