SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)

    Unit Test Device Detection

    Hi,

    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?

    Regards,
    Steve
    ictus==""

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,121
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Yes this could be done with mocking. I think I wire it up doing this!

    Thanks
    Steve
    ictus==""


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •