behastan/behastan 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

behastan/behastan

最新稳定版本:0.6.9

Composer 安装命令:

composer require behastan/behastan

包简介

Static analysis for Behat definitions and context files

README 文档

README

Downloads total

Find unused and duplicated definitions easily – without running Behat tests.


Install

composer require rector/behastan --dev

Usage

vendor/bin/behastan analyse tests

Do you want to skip some rule? You can:

vendor/bin/behastan analyse tests --skip=<rule-identifier>

# e.g.
vendor/bin/behastan analyse tests --skip=duplicated-contents

Here are the available rules:

1. Find duplicated definitions contents (duplicated-contents)

Some definitions have similar masks, even identical contents:

use Behat\Step\When;

#[When('load a user profile')]
public function loadAUserProfile()
{
    $this->loadRoute('/user-profile');
}

#[When('load user profile')]
public function loadUserProfile()
{
    $this->loadRoute('/user-profile');
}

Better use a one definition with single mask, to make your tests more precise and easier to maintain.


2. Find duplicated masks (duplicated-masks)

Same as services, there should be unique definition masks:

use Behat\Step\When;

#[When('load homepage')]
public function loadUserProfile()
{
    $this->loadRoute('/homepage');
}

#[When('load homepage')]
public function loadUserProfile()
{
    $this->loadRoute('/homepage/default');
}

Make them unique with different behavior, or merge them and use one definition instead.


3. Find unused definitions (unused-definitions)

Behat uses @When(), @Then() and @Given() annotations or attributes to define a class method that is called in *.feature files. Sometimes test change and lines from *.feature files are deleted. But what about definitions?

# some *.feature file
 Scenario: Load admin dashboard
-  When load admin dashboard
+  When load homepage

use Behat\Step\When;

#[When('load admin dashboard')]
public function loadAdminDashboard()
{
    $this->loadRoute('/admin/dashboard');
}

This rule spots definitions that are no longer needed, so you can remove them.


Protip: Add this command to your CI, to get instant feedback of any changes in every pull-request.

That's it!


Happy coding!

统计信息

  • 总下载量: 181
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-05