The browser/platform combination to use has been specified up to now as a static property of my base TestCase class. It's a shorthand: I can set it to 'FF' for Firefox on Win7, 'IE' for Internet Explorer 10 on Win7, '8' for Firefox, IE11 and Chrome on Windows 8, or 'all' for 3 browsers across Win7 and Win8.
It's not much, but I was wanting to set this as a command line option, rather than changing the value of the property on the class manually:
$ phpunit --browser-set="FF" tests/GoTestSomeStuffTest.php
The phpunit code makes it sound like this'll be straightforward. Just subclass PHPUnit_TextUI_Command, add in a hook to the constructor and handler... easy.
The suggested code is:
Firstly, that's not quite right. Looking at the other longOptions, it's clear that the initial double hyphen shouldn't be there:
Secondly, if you want to pass an option value you need to append an equals sign to the switch name:
But how do we get to use MyCommand instead of PHPUnit_TextUI_Command? I'm not sure if this is the right answer, but it's an answer. I've copied the bash script phpunit that starts it all up (from https://github.com/sebastianbergmann/phpunit/blob/master/phpunit), and instead of
(OK it's not really called MyCommand, I'm just staying with the original docs!). Plus a chmod to 755 to get it to run.
Almost there. However, our new MyCommand constructor isn't being called still. on the original looks like this:
so the line gives us an instance of PHPUnit_TextUI_Command, because that's where we are when it gets called. So MyCommand needs this method too, just copied straight across. In the end it looks like this:
Validation and a default value, and handling it all, sit in MyTestSetup (which indirectly extends PHPUnit_Extensions_Selenium2TestCase).
Note there is a way to define $browsers in a configuration somehow - I think through phpunit.xml (I seem to remember seeing it there) but it sets it on PHPUnit_Extensions_SeleniumTestCase, but I'm using PHPUnit_Extensions_Selenium2TestCase and so don't think it'll work.
(Edit: excuse the horrible code line spacing. Another to-do for the list.)