PHPUnit-附录 C. XML 配置文件
【http://www.phpunit.cn/manual/5.7/zh_cn/appendixes.configuration.html】
PHPUnit
<phpunit>
元素的属性用于配置 PHPUnit 的核心功能。
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
<!--bootstrap="/path/to/bootstrap.php"-->
cacheTokens="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
<!--printerFile="/path/to/ResultPrinter.php"-->
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
<!--testSuiteLoaderFile="/path/to/StandardTestSuiteLoader.php"-->
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="false">
<!-- ... -->
</phpunit>
以上 XML 配置对应于在“命令行选项”一节描述过的 TextUI 测试执行器的默认行为。
其他那些不能用命令行选项来配置的选项有:
convertErrorsToExceptions
-
默认情况下,PHPUnit 将会安插一个错误处理函数来将以下错误转换为异常:
E_WARNING
E_NOTICE
E_USER_ERROR
E_USER_WARNING
E_USER_NOTICE
E_STRICT
E_RECOVERABLE_ERROR
E_DEPRECATED
E_USER_DEPRECATED
将
convertErrorsToExceptions
设为false
可以禁用此功能。 convertNoticesToExceptions
-
此选项设置为
false
时,由convertErrorsToExceptions
安插的错误处理函数不会将E_NOTICE
、E_USER_NOTICE
、E_STRICT
错误转换为异常。 convertWarningsToExceptions
-
此选项设置为
false
时,由convertErrorsToExceptions
安插的错误处理函数不会将E_WARNING
或E_USER_WARNING
错误转换为异常。 forceCoversAnnotation
-
只记录使用了
@covers
标注(文档参见“@covers”一节)的测试的代码覆盖率。 timeoutForLargeTests
-
如果实行了基于测试规模的时间限制,那么此属性为所有标记为
@large
的测试设定超时限制。在配置的时间限制内未执行完毕的测试将视为失败。 timeoutForMediumTests
-
如果实行了基于测试规模的时间限制,那么此属性为所有标记为
@medium
的测试设定超时限制。在配置的时间限制内未执行完毕的测试将视为失败。 timeoutForSmallTests
-
如果实行了基于测试规模的时间限制,那么此属性为所有未标记为
@medium
或@large
的测试设定超时限制。在配置的时间限制内未执行完毕的测试将视为失败。
测试套件
带有一个或多个 <testsuite>
子元素的 <testsuites>
元素用于将测试套件及测试用例组合出新的测试套件。
<testsuites>
<testsuite name="My Test Suite">
<directory>/path/to/*Test.php files</directory>
<file>/path/to/MyTest.php</file>
<exclude>/path/to/exclude</exclude>
</testsuite>
</testsuites>
可以用 phpVersion
和 phpVersionOperator
属性来指定 PHP 版本需求。在以下例子中,仅当 PHP 版本至少为 5.3.0 时才会将 /path/to/*Test.php
文件与 /path/to/MyTest.php
文件添加到测试套件中。
<testsuites>
<testsuite name="My Test Suite">
<directory suffix="Test.php" phpVersion="5.3.0" phpVersionOperator=">=">/path/to/files</directory>
<file phpVersion="5.3.0" phpVersionOperator=">=">/path/to/MyTest.php</file>
</testsuite>
</testsuites>
phpVersionOperator
属性是可选的,其默认值为 >=
。
分组
<groups>
元素及其 <include>
、<exclude>
、<group>
子元素用于从带有 @group
标注(相关文档参见 “@group”一节)的测试中选择需要运行(或不运行)的分组。
<groups>
<include>
<group>name</group>
</include>
<exclude>
<group>name</group>
</exclude>
</groups>
以上 XML 配置对应于以如下选项调用 TextUI 测试执行器:
--group name
--exclude-group name
Whitelisting Files for Code Coverage
<filter>
元素及其子元素用于配置代码覆盖率报告所使用的白名单。
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">/path/to/files</directory>
<file>/path/to/file</file>
<exclude>
<directory suffix=".php">/path/to/files</directory>
<file>/path/to/file</file>
</exclude>
</whitelist>
</filter>
Logging (日志记录)
<logging>
元素及其 <log>
子元素用于配置测试执行期间的日志记录。
<logging>
<log type="coverage-html" target="/tmp/report" lowUpperBound="35"
highLowerBound="70"/>
<log type="coverage-clover" target="/tmp/coverage.xml"/>
<log type="coverage-php" target="/tmp/coverage.serialized"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
<log type="json" target="/tmp/logfile.json"/>
<log type="tap" target="/tmp/logfile.tap"/>
<log type="junit" target="/tmp/logfile.xml" logIncompleteSkipped="false"/>
<log type="testdox-html" target="/tmp/testdox.html"/>
<log type="testdox-text" target="/tmp/testdox.txt"/>
</logging>
以上 XML 配置对应于以如下选项调用 TextUI 测试执行器:
--coverage-html /tmp/report
--coverage-clover /tmp/coverage.xml
--coverage-php /tmp/coverage.serialized
--coverage-text
--log-json /tmp/logfile.json
> /tmp/logfile.txt
--log-tap /tmp/logfile.tap
--log-junit /tmp/logfile.xml
--testdox-html /tmp/testdox.html
--testdox-text /tmp/testdox.txt
lowUpperBound
、highLowerBound
、logIncompleteSkipped
及 showUncoveredFiles
属性没有等价的 TextUI 测试执行器选项。
lowUpperBound
:视为“低”覆盖率的最大覆盖率百分比。highLowerBound
:视为“高”覆盖率的最小覆盖率百分比。showUncoveredFiles
:在--coverage-text
输出中显示所有符合白名单的文件,不仅限于有覆盖率信息的那些。showOnlySummary
:在--coverage-text
输出中只显示摘要。
测试监听器
<listeners>
元素及其 <listener>
子元素用于在测试执行期间附加额外的测试监听器。
<listeners>
<listener class="MyListener" file="/optional/path/to/MyListener.php">
<arguments>
<array>
<element key="0">
<string>Sebastian</string>
</element>
</array>
<integer>22</integer>
<string>April</string>
<double>19.78</double>
<null/>
<object class="stdClass"/>
</arguments>
</listener>
</listeners>
以上 XML 配置对应于将 $listener
对象(见下文)附到测试执行过程上。
$listener = new MyListener(
['Sebastian'],
22,
'April',
19.78,
null,
new stdClass
);
设定 PHP INI 设置、常量、全局变量
<php>
元素及其子元素用于配置 PHP 设置、常量以及全局变量。同时也可用于向 include_path
前部置入内容。
<php>
<includePath>.</includePath>
<ini name="foo" value="bar"/>
<const name="foo" value="bar"/>
<var name="foo" value="bar"/>
<env name="foo" value="bar"/>
<post name="foo" value="bar"/>
<get name="foo" value="bar"/>
<cookie name="foo" value="bar"/>
<server name="foo" value="bar"/>
<files name="foo" value="bar"/>
<request name="foo" value="bar"/>
</php>
以上 XML 配置对应于如下 PHP 代码:
ini_set('foo', 'bar');
define('foo', 'bar');
$GLOBALS['foo'] = 'bar';
$_ENV['foo'] = 'bar';
$_POST['foo'] = 'bar';
$_GET['foo'] = 'bar';
$_COOKIE['foo'] = 'bar';
$_SERVER['foo'] = 'bar';
$_FILES['foo'] = 'bar';
$_REQUEST['foo'] = 'bar';
最新文章
- Vijos1404遭遇战[最短路建模]
- mysql 查询数据时按照A-Z顺序排序返回结果集
- codeforces gym 100286 I iSharp (字符串模拟)
- SPOJ ONEZERO(搜索)
- 如何将NTFS格式的移动硬盘挂接到Mac OS上进行读写(Read/Write)操作
- PHP中常用正则表达式大全
- 表连接到底咋回事,就是产生中间结果啊!用于给select/insert等操作用
- xmbc 资源
- 工作中EF遇到的问题
- Linux学习----gdb调试(指针的指针)
- thinkphp模板继承
- HTML5 — 地理定位
- 前端开发面试题-CSS(转载)
- centos7 安装mysql的正确姿势
- python的ConfigParser模块
- sql注入学习心得与sqlmap使用心得
- set_magic_quotes_runtime
- 常用移动web开发框架--转载
- CFE Bootloader详解 — 引导过程
- Daily Scrum 9