PHPackages                             rdx/behat-variables - 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. rdx/behat-variables

ActiveLibrary[Testing &amp; Quality](/categories/testing)

rdx/behat-variables
===================

Store variables across Scenarios during Behat testing

1.2(8y ago)122.4M—6.7%5[1 issues](https://github.com/rudiedirkx/behat-variables/issues)2MITPHP

Since Mar 28Pushed 7y ago2 watchersCompare

[ Source](https://github.com/rudiedirkx/behat-variables)[ Packagist](https://packagist.org/packages/rdx/behat-variables)[ RSS](/packages/rdx-behat-variables/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (7)Used By (2)

Behat Variables
===============

[](#behat-variables)

[![Build Status](https://camo.githubusercontent.com/b752e3cb5344b2421111590edf8b19a5be6cb8bc85b677d7111a4af6fd15b154/68747470733a2f2f7472617669732d63692e6f72672f72756469656469726b782f62656861742d7661726961626c65732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rudiedirkx/behat-variables)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2b2dcddbe7fd48a48efe52ba1911868e5983ed279ee4d740991c98fa4339867c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72756469656469726b782f62656861742d7661726961626c65732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/rudiedirkx/behat-variables/?branch=master)

Stores your custom variables across Scenarios during Feature testing.

The idea
--------

[](#the-idea)

You're making users and profiles to test, and you want to use those creations further in the same Feature. You can't, because: 1) Behat arguments are literals, and 2) FeatureContext lives only for every Scenario, not for the entire Feature.

With behat-variables, you can save &amp; use those variables: user ids, passwords, activation tokens, etc.

```
Given a new user "Fred"           # Your custom step, with a return value
And I save it into "UID"          # A provided step that saves that return value
When I go to "/users/"     # Custom step, with dynamic argument
Then I should see "Hello, Fred!"  # Custom step, with predictable content

```

The `` part is the magic. Works for any argument, not just URIs.

Set up
------

[](#set-up)

In order to use variables in your Behat feature, you must do 2 things:

- Add the Feature Context class: `rdx\behatvars\BehatVariablesContext`
- Add the Extension class: `rdx\behatvars\BehatVariablesExtension`

See the Behat docs for where they fit in `behat.yml`, or see this repo's `behat.yml`:

```
default:
  suites:
    default:
      contexts:
        - rdx\behatvars\BehatVariablesContext
        - FeatureContext
  extensions:
      rdx\behatvars\BehatVariablesExtension: ~

```

And make sure your custom steps have a **scalar return value, or an array of scalars**:

```
/**
 * @Given a value :value
 */
public function aValue($value) {
  return $value;
}

/**
 * @Given values :value1 and :value2
 */
public function valuesAnd($value1, $value2) {
  return [$value1, $value2];
}

```

Examples
--------

[](#examples)

See `features/simple.feature` for very simple examples (with only 3 custom steps). It's the test used to test this package.

Features
--------

[](#features)

This package provides 1 step, in several formats:

```
(I|we) save (it|that|those|them) into "VARIABLE_NAME"

```

So you can make several custom step combinations:

```
Given "4" cars in the same shop                   # Custom
And we save those into "CAR1,CAR2,CAR3,CAR4"      # Provided

Given a user "Fred" in organization "McDonald's"  # Custom
And we save those into "USER,ORGANIZATION"        # Provided

```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% 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 ~119 days

Recently: every ~149 days

Total

6

Last Release

3105d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/78549c1dc5c83ec0201c9afc66762c6d5bbf770291b12bae5a7a65350f950dba?d=identicon)[rudiedirkx](/maintainers/rudiedirkx)

---

Top Contributors

[![rudiedirkx](https://avatars.githubusercontent.com/u/168024?v=4)](https://github.com/rudiedirkx "rudiedirkx (24 commits)")[![kufd](https://avatars.githubusercontent.com/u/1074793?v=4)](https://github.com/kufd "kufd (2 commits)")[![das-peter](https://avatars.githubusercontent.com/u/177531?v=4)](https://github.com/das-peter "das-peter (1 commits)")

### Embed Badge

![Health badge](/badges/rdx-behat-variables/health.svg)

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

###  Alternatives

[drupal/drupal-extension

Drupal extension for Behat

22215.1M147](/packages/drupal-drupal-extension)[friends-of-behat/symfony-extension

Integrates Behat with Symfony.

48223.4M551](/packages/friends-of-behat-symfony-extension)[friends-of-behat/variadic-extension

Variadic support for behat context arguments

2286.0M446](/packages/friends-of-behat-variadic-extension)[friends-of-behat/mink-extension

Mink extension for Behat

14034.2M467](/packages/friends-of-behat-mink-extension)[friends-of-behat/suite-settings-extension

Allows to overwrite suites' default settings.

2154.1M387](/packages/friends-of-behat-suite-settings-extension)[wp-cli/wp-cli-tests

WP-CLI testing framework

422.7M87](/packages/wp-cli-wp-cli-tests)

PHPackages © 2026

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