XML文件配置项

XML文件配置项

convertErrorsToExceptions

将PHP的错误提示转换为异常。支持转换的错误有:

  • 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_NOTICEE_USER_NOTICEE_STRICT 错误转换为异常。

convertWarningsToExceptions

此选项设置为 false 时,由 convertErrorsToExceptions 安插的错误处理函数不会将 E_WARNINGE_USER_WARNING 错误转换为异常。

forceCoversAnnotation

只记录使用了 @covers 标注的测试的代码覆盖率。

@covers相关知识

timeoutForLargeTests/timeoutForMediumTests/timeoutForSmallTests

结合有风险的测试理解。

测试套件

testsuite/testsuites/directory/file/exclude

<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>
  • exclude是排除的意思。
  • directoryfileexclude的目的都是一样的,就是指定测试套件的地址。

phpVersion/phpVersionOperator

可以用 phpVersionphpVersionOperator 属性来指定 PHP 版本需求。在以下例子中,仅当 PHP 版本至少为 5.3.0 时才会将 /path/to/*Test.php 文件与 /path/to/MyTest.php 文件添加到测试套件中。

phpVersionOperator 属性是可选的,其默认值为 >=

<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>

group/include/exclude

<groups> 元素及其 <include><exclude><group> 子元素用于从带有 @group 标注的测试中选择需要运行(或不运行)的分组。

<groups>
  <include>
    <group>name</group>
  </include>
  <exclude>
    <group>name</group>
  </exclude>
</groups>

以上配置跟命令行参数

  • --group name
  • --exclude-group name

的效果是一样的。

代码覆盖率白名单

filter/whitelist/directory/file/exclude

<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/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="junit" target="/tmp/logfile.xml" logIncompleteSkipped="false"/>
  <log type="testdox-html" target="/tmp/testdox.html"/>
  <log type="testdox-text" target="/tmp/testdox.txt"/>
</logging>

以上配置跟命令行的以下参数是一致的:

  • --coverage-html /tmp/report
  • --coverage-clover /tmp/coverage.xml
  • --coverage-php /tmp/coverage.serialized
  • --coverage-text
  • > /tmp/logfile.txt
  • --log-junit /tmp/logfile.xml
  • --testdox-html /tmp/testdox.html
  • --testdox-text /tmp/testdox.txt
  • lowUpperBound:视为“低”覆盖率的最大覆盖率百分比。
  • highLowerBound:视为“高”覆盖率的最小覆盖率百分比。
  • showUncoveredFiles:在 --coverage-text 输出中显示所有符合白名单的文件,不仅限于有覆盖率信息的那些。
  • showOnlySummary:在 --coverage-text 输出中只显示摘要。

测试监听器

关于监视器的内容没有找到,先空着吧。

listerners/listerner

<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>

设定 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';
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章