nicwortel/ behat-unused-step-definitions-extension
一个Behat扩展,用于检测未使用的步骤定义
Requires
- php: ^8.1
- behat/behat: ^3.9
- symfony/config: ^4.4 || ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- nicwortel/coding-standard: ^2.3
- phpstan/phpstan: ^1.8
- phpstan/phpstan-symfony: ^1.2
- phpunit/phpunit: ^10.3
- rector/rector: ^0.18.4
- symfony/process: ^6.0
README
你有大量的Behat测试套件吗?你想检查你的功能上下文中的未使用步骤定义吗?这个Behat扩展可以检测并报告在任何一个你的*.feature
文件中未使用的步骤定义。
安装
composer require --dev nicwortel/behat-unused-step-definitions-extension
在behat.yml
中激活扩展
default: extensions: NicWortel\BehatUnusedStepDefinitionsExtension\Extension: ~
用法
按照上述文档中的安装步骤进行操作后,只需运行Behat。实际上执行测试,而是进行一次干燥运行就足够收集有关未使用步骤定义的信息。
vendor/bin/behat --dry-run
请注意,如果你有多个套件,在套件完成后,每个套件将列出未使用的步骤定义。
过滤结果
包含/排除
有些项目中避免检测某些步骤定义很重要。例如,当项目想要避免从第三方包/库中扫描未使用的步骤定义,只显示自定义代码的结果时。该扩展允许在behat.yml
配置文件中配置一个正则表达式列表,以包含或排除步骤定义。表达式与FQCN + 方法名(My\Namespace\ClassName::methodName
)进行比较。
default: extensions: NicWortel\BehatUnusedStepDefinitionsExtension\Extension: filters: include: - '/MyProject\\Behat\\Contexts/' - '/OtherProject\\Behat\\(Foo|Bar)Context/' exclude: - '/MyProject\\Behat\\Contexts\\FeatureContext/' - '/::excludedMethod/' - '/OtherProject\\Behat\\FooContext::.+Method/'
忽略模式别名
示例
/** * @Then I take a screenshot * @Then I take a screenshot :name */ public function takeScreenshot(?string $name = NULL): void { // Step implementation. }
如果使用的是I take a screenshot
,但没有使用I take a screenshot :name
,启用ignorePatternAliases: true
将防止后者被报告为未使用。
default: extensions: NicWortel\BehatUnusedStepDefinitionsExtension\Extension: ignorePatternAliases: true
扩展
默认情况下,该扩展使用包中提供的unused_step_definitions_printer
打印器。打印器在控制台中显示未使用步骤定义的列表。第三方Behat扩展可能提供不同的打印器(例如,有人可能构建一个包含未使用步骤定义列表的文本文件)。自定义打印器应定义为容器服务,并实现\NicWortel\BehatUnusedStepDefinitionsExtension\UnusedStepDefinitionsPrinter
接口。通过在behat.yml
配置文件中提供其服务ID,可以使用自定义打印器。
default: extensions: NicWortel\BehatUnusedStepDefinitionsExtension\Extension: printer: my_custom_printer