如何使用 PHPUnit 的 --filter 选项按 "ends with" 进行过滤?

How can I filter by "ends with" using PHPUnit's --filter option?

我正在尝试过滤 PHPUnit 测试套件。当我尝试使用 --filter 按测试名称过滤时,会执行 完全匹配 指定字符串的测试,但 字符串.

例如。如果我有两个测试,testExample 和 testExampleTwo,下面的 运行s 两个测试:

phpunit --filter testExample tests/Example.php

如何让 phpunit 严格遵守我给它的字符串?我试过 /testExample$/ 但 运行 没有任何测试。我正在使用 PHPUnit 3.7。

完全限定的测试名称因测试是否有数据提供者而异。

当没有数据提供者时,测试的名称只是Example::testExample,将使用/testExample$/执行。

phpunit --filter '/testExample$/' tests/Example.php

/**
 * No data provider.
 */
public function testExample() {

}

但是,对于数据提供者,测试变为 Example::testExample with data set [dataset],与模式 /testExample$/.

不匹配

我必须使用以下模式才能使其按预期工作,它匹配字符串的末尾或 space 字符。

phpunit --filter '/testExample\b/' tests/Example.php

/**
 * @dataProvider  exampleData
 */
public function testExample($data) {

}

要添加到上面的信息中,当测试有数据提供者时,过滤器正则表达式也可以用于 select 哪个测试用例循环到 运行。例如 --filter='thisTest\b.*#3' 将 运行 thisTest 与数据集编号 3。过滤似乎不适用于传递的数据值,只有 # 号。