PHPackages                             behastan/behastan - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. behastan/behastan

Abandoned → [rector/behastan](/?search=rector%2Fbehastan)Library[Testing &amp; Quality](/categories/testing)

behastan/behastan
=================

Static analysis for Behat definitions and context files

0.6.9(4mo ago)112082[1 PRs](https://github.com/behastan/behastan/pulls)MITPHPPHP &gt;=7.2CI passing

Since Feb 6Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/behastan/behastan)[ Packagist](https://packagist.org/packages/behastan/behastan)[ Fund](https://www.paypal.me/rectorphp)[ GitHub Sponsors](https://github.com/tomasvotruba)[ RSS](/packages/behastan-behastan/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (22)Used By (0)

Behastan - Modern Static analysis for Behat tests
=================================================

[](#behastan---modern-static-analysis-for-behat-tests)

[![Downloads total](https://camo.githubusercontent.com/3eb4391cdbb93fafacb759fb8fafaaa9dc1a73a7a9269b391780ce7289213db0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726563746f722f626568617374616e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rector/behastan/stats)

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

Install
-------

[](#install)

```
composer require rector/behastan --dev
```

Usage
-----

[](#usage)

```
vendor/bin/behastan analyse tests
```

Do you want to skip some rule? You can:

```
vendor/bin/behastan analyse tests --skip=

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

Here are the available rules:

### 1. Find duplicated definitions contents (`duplicated-contents`)

[](#1-find-duplicated-definitions-contents-duplicated-contents)

Some definitions have similar patterns, 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 pattern, to make your tests more precise and easier to maintain.

### 2. Find duplicated patterns (`duplicated-patterns`)

[](#2-find-duplicated-patterns-duplicated-patterns)

Same as services, there should be unique definition patterns:

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

[](#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.

### 4. Find duplicate scenario titles (`duplicate-scenario-titles`)

[](#4-find-duplicate-scenario-titles-duplicate-scenario-titles)

In Behat, each scenario should have a unique name to ensure clarity and avoid confusion during test execution and later debugging. This rule identifies scenarios that share the same name within your feature files:

```
Feature: User Authentication

    Scenario: User logs in successfully
        When the user enters valid credentials
        Then login should be successful

    Scenario: User logs in successfully
        When the user enters invalid credentials
        Then an error message should be displayed
```

### 5. Report redundant regex definitions (`redundant-regex-definitions`)

[](#5-report-redundant-regex-definitions-redundant-regex-definitions)

When defining step definitions in Behat, it's common to use regular expressions to match patterns. However, sometimes these regex patterns can be overly complex or redundant, making them harder to read and maintain. This rule identifies such redundant regex definitions:

```
-#[When('#I have apples#')]
+#[When('I have apples')]
 public function iHaveApples()
 {
     // ...
 }
```

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

That's it!

Happy coding!

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance78

Regular maintenance activity

Popularity19

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 79.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~16 days

Recently: every ~0 days

Total

21

Last Release

140d ago

PHP version history (3 changes)0.0.1PHP &gt;=8.2

0.0.2PHP &gt;=7.2

0.2.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/924196?v=4)[Tomas Votruba](/maintainers/TomasVotruba)[@TomasVotruba](https://github.com/TomasVotruba)

---

Top Contributors

[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (1162 commits)")[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (264 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (20 commits)")[![ruudk](https://avatars.githubusercontent.com/u/104180?v=4)](https://github.com/ruudk "ruudk (2 commits)")[![gnutix](https://avatars.githubusercontent.com/u/310134?v=4)](https://github.com/gnutix "gnutix (2 commits)")[![simbig](https://avatars.githubusercontent.com/u/26680884?v=4)](https://github.com/simbig "simbig (1 commits)")[![spawnia](https://avatars.githubusercontent.com/u/12158000?v=4)](https://github.com/spawnia "spawnia (1 commits)")[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (1 commits)")[![stchr](https://avatars.githubusercontent.com/u/166079?v=4)](https://github.com/stchr "stchr (1 commits)")[![thePanz](https://avatars.githubusercontent.com/u/226021?v=4)](https://github.com/thePanz "thePanz (1 commits)")[![carlos-granados](https://avatars.githubusercontent.com/u/1383106?v=4)](https://github.com/carlos-granados "carlos-granados (1 commits)")[![monitaurus](https://avatars.githubusercontent.com/u/1794571?v=4)](https://github.com/monitaurus "monitaurus (1 commits)")[![niji-mneute](https://avatars.githubusercontent.com/u/58166712?v=4)](https://github.com/niji-mneute "niji-mneute (1 commits)")

### Embed Badge

![Health badge](/badges/behastan-behastan/health.svg)

```
[![Health](https://phpackages.com/badges/behastan-behastan/health.svg)](https://phpackages.com/packages/behastan-behastan)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
