在命名PHPunit配置文件时,使用phpunit.xml.dist和phpunit.xml有何区别?

31

有人可以解释一下在使用PHPunit配置文件时,phpunit.xml.distphpunit.xml之间的区别吗?

官方文档中提到了这两个名称:

PHPUnit的XML配置文件(附录C)也可用于组成测试套件。示例5.1展示了一个最小的phpunit.xml文件,当递归遍历tests目录时,将添加所有在* Test.php文件中找到的* Test类。

如果没有使用configuration参数,则会给phpunit.xml加载配置文件时赋予更高优先级。

如果当前工作目录中存在phpunit.xml或phpunit.xml.dist(按照此顺序),并且未使用--configuration,则自动从该文件中读取配置。

I did find some questions (e.g. is this .xml.dist file really required to be used) relating to the fact, that .dist files usually are used as a template (distribution) which should be copied to a version without the .dist ending to activate them (e.g. .htaccess.dist). But this seems not to be the case with PHPunit as it picks up and runs the dist file as well. Other questions (Can I use phpunit.xml for credentials and phpunit.xml.dist for testsuites?) seem to deal with other weird usage ideas about these two files.
在Symfony世界中,包含一个phpunit.xml.dist文件是强制性的用于可重用的bundles,我想知道为什么不使用phpunit.xml文件。
一个测试套件不应包含AllTests.php脚本,而必须依赖于phpunit.xml.dist文件的存在。
所以如果有人能对此进行解释,我会很高兴;-)
2个回答

76
如果当前工作目录下存在phpunit.xmlphpunit.xml.dist文件(按照这个顺序),并且未使用--configuration选项,则配置信息将自动从该文件中读取。
回退机制的思想(当phpunit.xml不存在时回退到phpunit.xml.dist)是,将phpunit.xml.dist提交到版本控制中,而忽略phpunit.xml。这使得开发人员可以使用自定义配置,而不用担心意外将其提交到版本控制中。

1
我理解使用dist文件的概念以及在版本控制系统中可能会忽略它们,但我感到困惑的是两者都被执行了。 - lordrhodos
15
PHPUnit不会同时使用它们,而是选择其中之一。根据上述优先级进行选择。 - Sebastian Bergmann

4

通常情况下,例如使用git对版本进行控制时,文件.dist会被版本化,而您通常不会对phpunit.xml进行版本化,因为它是您的机器的配置文件。

文件.dist通常是包含非真实世界部署特定参数的配置文件。

如果存在phpunit.xml和phpunit.xml.dist,phpunit将采用phpunit.xml

phpunit.xml.dist是标准文件,而phpunit.xml是自定义文件,不会被版本化以避免发布个人数据。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接