Passing parameters to PHPUnit

后端 未结 9 623
我寻月下人不归
我寻月下人不归 2020-12-24 11:03

I\'m starting to write PHPUnit tests and I\'d like the tests to be run from developers machines as well as from our servers. Developers machines are set up differently than

9条回答
  •  不思量自难忘°
    2020-12-24 11:24

    Passing arguments on the command line would make sense if you want to vary the test parameters per test run. Running host-specific tests on different machines is not the best justification for this solution.

    For that, the PHPUnit configuration file may prove to be more suitable. It gives you control over host- and even request-specific variables including manipulating php.ini settings as well as defining constants, global variables, $_ENV, $_SERVER, and even $_GET, $_POST, etc. This is all done under the node of the configuration file, see Setting PHP INI settings, Constants and Global Variables

    Symfony2 uses this approach and provides both a phpunit.xml.dist (default config) and a phpunit.xml with your unit tests. The latter is gitignored to allow you to customize it for each machine without affecting the repo. You would then run your tests with:

    phpunit -c /path/to/phpunit.xml
    

提交回复
热议问题