2011-11-04 85 views
3

我想通過命令行將變量傳遞給Selenium PHPUnit腳本。 查看PHPUnit幫助文檔:Selenium PHPUnit在ubuntu命令行上傳遞變量

我們可以使用XML或PHP配置文件提供變量,但理想情況下我想在不使用外部文件的情況下傳遞變量。 我正在尋找這個原因是因爲我想能夠修改超時值而不必修改我的自定義config.php文件。

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. 

回答

2

使用-d設置PHP的配置價值之一,並在bootstrap.php文件中使用ini_get()閱讀。使用define()將其傳遞給您的測試。這確實是一種駭客,但它適用於您的超時場景。

作爲一個測試,我用max_execution_time作爲轉移點。如果你使用相同的東西,你會想重置它,所以PHPUnit不會被殺死,如果它需要很長時間。 ;)

// bootstrap.php 

$timeout = ini_get('max_execution_time'); 
set_time_limit(0); // run forever 

使用-d傳遞您想要的超時。

phpunit -d max_execution_time=5000 

更新:我第一次使用由設置my_test_timeout試過,但價值沒有來過。 PHP或PHPUnit必須阻止不在INI文件中的值或者PHP不支持。鑑於INI文件可以具有特定於PHP提前未知的模塊的值,我想知道是否可以將自定義設置添加到php.ini以使其正常工作。值得一試,以避免破壞其他有用的設置。另外它可以讓你使用字符串和其他類型。