PHPackages                             baywa-re-lusy/behat-contexts - 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. baywa-re-lusy/behat-contexts

ActiveLibrary

baywa-re-lusy/behat-contexts
============================

BayWa r.e. Behat Contexts

2.15.5(2mo ago)01.1kproprietaryPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0

Since Apr 11Pushed 2mo agoCompare

[ Source](https://github.com/baywa-re-lusy/behat-contexts)[ Packagist](https://packagist.org/packages/baywa-re-lusy/behat-contexts)[ Docs](https://baywa-re.com)[ RSS](/packages/baywa-re-lusy-behat-contexts/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (66)Used By (0)

BayWa r.e. Behat Contexts
=========================

[](#baywa-re-behat-contexts)

[![CircleCI](https://camo.githubusercontent.com/4e220fe52649628d61f25b565383b944f894106faa1cb3ef8cb7de41d2fe22e5/68747470733a2f2f636972636c6563692e636f6d2f67682f62617977612d72652d6c7573792f62656861742d636f6e74657874732f747265652f6d61696e2e7376673f7374796c653d737667)](https://circleci.com/gh/baywa-re-lusy/behat-contexts/tree/main)

This repository provides you with different Behat Contexts containing common test steps that can be reused across different projects.

Installation
============

[](#installation)

Install the package via Composer:

```
$ composer require --dev lusy/behat-contexts
```

In your `behat.yml`, add the following:

```
default:
  ...
  suites:
    api_features:
      contexts:
        ...
        - BayWaReLusy\BehatContext\HalContext
        - BayWaReLusy\BehatContext\SqsContext
        - BayWaReLusy\BehatContext\ConsoleContext
        ...
```

HalContext
==========

[](#halcontext)

A Context to parse &amp; test API responses in HAL format:

- [https://de.wikipedia.org/wiki/Hypertext\_Application\_Language](https://de.wikipedia.org/wiki/Hypertext_Application_Language)
- [https://stateless.group/hal\_specification.html](https://stateless.group/hal_specification.html)

In your `FeatureContext`, add the following:

```
use BayWaReLusy\BehatContext\HalContext\HalContextAwareTrait;
use BayWaReLusy\BehatContext\HalContext\HalContextAwareInterface;

class FeatureContext implements
    ...
    HalContextAwareInterface
    ...
{
    use HalContextAwareTrait;

    ...

    /**
     * @BeforeScenario
     */
    public function gatherContexts(\Behat\Behat\Hook\Scope\BeforeScenarioScope $scope)
    {
        ...
        $this->gatherHalContext($scope);
        $this->getHalContext()
            ->setJsonFilesPath()
            ->setBaseUrl()
            ->setBearerToken();
        ...
    }
}
```

And when you receive a reponse from your API, pass it to the context:

```
/** @var Psr\Http\Message\ResponseInterface */
$apiResponse = ...

$this->getHalContext()->setLastResponse($apiResponse);
```

You can add placeholders to your URL by writing:

```
When I send a "GET" request to "/resource-url/{MY_PLACEHOLDER}"
```

And add the corresponding value with:

```
$this->getHalContext()->addPlaceholder('MY_PLACEHOLDER', '');
```

AuthContext
===========

[](#authcontext)

A Context to login to a generic Auth Server (OpenID Connect/OAuth2) with Login/Password or as a Machine-to-Machine client. The `HalContext` needs to be initialized first.

In your `FeatureContext`, add the following:

```
use BayWaReLusy\BehatContext\AuthContext\AuthContextAwareTrait;
use BayWaReLusy\BehatContext\AuthContext\AuthContextAwareInterface;
use BayWaReLusy\BehatContext\AuthContext\MachineToMachineCredentials;
use BayWaReLusy\BehatContext\AuthContext\UserCredentials;

class FeatureContext implements
    ...
    AuthContextAwareInterface
    ...
{
    use AuthContextAwareTrait;

    ...

    /**
     * @BeforeScenario
     */
    public function gatherContexts(\Behat\Behat\Hook\Scope\BeforeScenarioScope $scope)
    {
        ...
        $this->gatherAuthContext($scope);
        $this->getAuthContext()
            ->setHalContext($this->getHalContext())
            ->setServerAddress()
            ->setTokenEndpoint()
            ->setTokenEndpoint()
            ->addMachineToMachineCredentials(new MachineToMachineCredentials(
                '',
                '',
                ''
            ))
            ->addUserCredentials(new UserCredentials(
                '',
                '',
                ''
            ));
        ...
    }
}
```

SqsContext
==========

[](#sqscontext)

A Context to use AWS SQS compatible queues like e.g. ElasticMQ

In your `FeatureContext`, add the following:

```
use BayWaReLusy\BehatContext\SqsContext\SqsContextAwareTrait;
use BayWaReLusy\BehatContext\SqsContext\SqsContextAwareInterface;
use BayWaReLusy\BehatContext\SqsContext\QueueUrl;

class FeatureContext implements
    ...
    SqsContextAwareInterface
    ...
{
    use SqsContextAwareTrait;

    ...

    /**
     * @BeforeScenario
     */
    public function gatherContexts(\Behat\Behat\Hook\Scope\BeforeScenarioScope $scope)
    {
        ...
        $queueService = ... // gatherSqsContext($scope);
        $this->getSqsContext()
            ->setQueueService($queueService)
            ->setSqsEndpoint($sqsEndpoint) // setAwsRegion()
            ->setAwsKey()
            ->setAwsSecret()
            ->addQueue(new QueueUrl('queueName', $queueUrl));
        ...
    }
}
```

To clear the queues before each Scenario, use the following code:

```
/**
 * @BeforeScenario
 */
public function clearAllQueues(): void
{
    // Clear all queues
    $this->sqsContext->clearAllQueues();
}
```

ConsoleContext
==============

[](#consolecontext)

A Context containing steps to test console routes

In your `FeatureContext`, add the following:

```
use BayWaReLusy\BehatContext\ConsoleContext\ConsoleContextAwareTrait;
use BayWaReLusy\BehatContext\ConsoleContext\ConsoleContextAwareInterface;

class FeatureContext implements
    ...
    ConsoleContextAwareInterface
    ...
{
    use ConsoleContextAwareTrait;

    ...

    /**
     * @BeforeScenario
     */
    public function gatherContexts(\Behat\Behat\Hook\Scope\BeforeScenarioScope $scope)
    {
        ...
        $this->gatherConsoleContext($scope);
        ...
    }
}
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance86

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 89.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 ~22 days

Recently: every ~6 days

Total

64

Last Release

67d ago

Major Versions

1.13.0 → 2.0.02023-04-13

PHP version history (3 changes)1.0.0PHP &gt;=8.0

2.0.0PHP &gt;=8.1

2.13.0PHP ~8.2.0 || ~8.3.0 || ~8.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7d6584819dabfe835a6caa1826bf2716dee040714e2a769365afa84d68b144b9?d=identicon)[ppaulis](/maintainers/ppaulis)

---

Top Contributors

[![ppaulis](https://avatars.githubusercontent.com/u/1609503?v=4)](https://github.com/ppaulis "ppaulis (175 commits)")[![MaximJam](https://avatars.githubusercontent.com/u/100141314?v=4)](https://github.com/MaximJam "MaximJam (19 commits)")[![bluespuke](https://avatars.githubusercontent.com/u/1756106?v=4)](https://github.com/bluespuke "bluespuke (1 commits)")

###  Code Quality

TestsBehat

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/baywa-re-lusy-behat-contexts/health.svg)

```
[![Health](https://phpackages.com/badges/baywa-re-lusy-behat-contexts/health.svg)](https://phpackages.com/packages/baywa-re-lusy-behat-contexts)
```

PHPackages © 2026

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