Reputation: 130
I am trying to pass a variable to a Selenium PHPUnit script using the command line. Looking at the PHPUnit Help Documentation :
We can provide variables using an XML or PHP Config File, but ideally I would like to pass the variable without using an external file. The reason I am looking for this is because I want to be able to modify Timeout values without having to modify my custom config.php file.
phpunit --help
PHPUnit 3.6.0 by Sebastian Bergmann.
Usage: phpunit [switches] UnitTest [UnitTest.php]
phpunit [switches] <directory>
--log-junit <file> Log test execution in JUnit XML format to file.
--log-tap <file> Log test execution in TAP format to file.
--log-json <file> Log test execution in JSON format.
--coverage-html <dir> Generate code coverage report in HTML format.
--coverage-clover <file> Write code coverage data in Clover XML format.
--coverage-php <file> Serialize PHP_CodeCoverage object to file.
--coverage-text <file> Generate code coverage report in text format.
--testdox-html <file> Write agile documentation in HTML format to file.
--testdox-text <file> Write agile documentation in Text format to file.
--filter <pattern> Filter which tests to run.
--group ... Only runs tests from the specified group(s).
--exclude-group ... Exclude tests from the specified group(s).
--list-groups List available test groups.
--loader <loader> TestSuiteLoader implementation to use.
--printer <printer> TestSuiteListener implementation to use.
--repeat <times> Runs the test(s) repeatedly.
--tap Report test execution progress in TAP format.
--testdox Report test execution progress in TestDox format.
--colors Use colors in output.
--stderr Write to STDERR instead of STDOUT.
--stop-on-error Stop execution upon first error.
--stop-on-failure Stop execution upon first error or failure.
--stop-on-skipped Stop execution upon first skipped test.
--stop-on-incomplete Stop execution upon first incomplete test.
--strict Run tests in strict mode.
-v|--verbose Output more verbose information.
--skeleton-class Generate Unit class for UnitTest in UnitTest.php.
--skeleton-test Generate UnitTest class for Unit in Unit.php.
--process-isolation Run each test in a separate PHP process.
--no-globals-backup Do not backup and restore $GLOBALS for each test.
--static-backup Backup and restore static attributes for each test.
--syntax-check Try to check source files for syntax errors.
--bootstrap <file> A "bootstrap" PHP file that is run before the tests.
-c|--configuration <file> Read configuration from XML file.
--no-configuration Ignore default configuration file (phpunit.xml).
--include-path <path(s)> Prepend PHP's include_path with given path(s).
-d key[=value] Sets a php.ini value.
-h|--help Prints this usage information.
--version Prints the version and exits.
--debug Output debugging information.
Upvotes: 3
Views: 952
Reputation: 36542
Use -d
to set one of PHP's configuration values and read it using ini_get()
in your bootstrap.php
file. Use define()
to pass it to your test. This is a hack to be sure, but it works for your timeout scenario.
As a test I used max_execution_time
as the transfer point. If you use the same thing, you'll want to reset it so PHPUnit doesn't get killed if it takes too long. ;)
// bootstrap.php
$timeout = ini_get('max_execution_time');
set_time_limit(0); // run forever
Use -d
to pass in your desired timeout.
phpunit -d max_execution_time=5000
Update: I first tried using a made up setting my_test_timeout
, but the value didn't come through. PHP or PHPUnit must be blocking values not in the INI file or that PHP simply doesn't support. Given that the INI file can have values specific to modules that PHP cannot know about ahead of time, I wonder if you could add your custom setting to php.ini
to get it to work. It's worth a shot to avoid clobbering an otherwise useful setting. Plus it may allow you to use strings and other types.
Upvotes: 2