serverstorm — 2013-06-06T13:34:55-04:00 — #1
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?
cpradio — 2013-06-06T13:47:52-04:00 — #2
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.
serverstorm — 2013-06-06T13:53:38-04:00 — #3
Yes this could be done with mocking. I think I wire it up doing this!