PHPackages                             cucumber/messages - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. cucumber/messages

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cucumber/messages
=================

JSON schema-based messages for Cucumber's inter-process communication

v32.2.0(2mo ago)0191.7k—5.6%2MITPHPPHP ^8.1

Since Mar 24Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/cucumber/messages-php)[ Packagist](https://packagist.org/packages/cucumber/messages)[ RSS](/packages/cucumber-messages/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (10)Versions (39)Used By (2)

Cucumber Messages
=================

[](#cucumber-messages)

This is a PHP implementation of the [Cucumber Messages protocol](https://github.com/cucumber/messages)

Requirements
------------

[](#requirements)

- PHP 8.1
- Ext-JSON

Installation
------------

[](#installation)

Install using [composer](https://getcomposer.org).

```
composer require cucumber/messages
```

Usage
-----

[](#usage)

### Consuming messages

[](#consuming-messages)

Cucumber Messages are contained in a top-level Envelope object when serialised. Members are exposed via public readonly properties. Because many properties are nullable, it may be convenient to use the [nullsafe operator](https://www.php.net/releases/8.0/en.php#nullsafe-operator) to access them:

```
/** @var string|null $line */
$line = $envelope->gherkinDocument?->feature?->keyword;
```

#### Decoding JSON strings

[](#decoding-json-strings)

You can construct an Envelope from a JSON string:

```
use Cucumber\Messages\DecodingException;
use Cucumber\Messages\Envelope;

try {
    $envelope = Envelope::fromJson($json);
}
catch (DecodingException $e) {
    // handle the error
}
```

#### Handling NDJSON Streams

[](#handling-ndjson-streams)

Cucumber Messages are streamed as Newline Delimited JSON (NDJSON).

You can use the `NdJsonStreamReader` to obtain a Generator that produces Envelopes. It's important to remember that any decoding errors will be thrown as the generator is consumed, not when it's returned.

```
use Cucumber\Messages\DecodingException;
use Cucumber\Messages\Streams\NdJson\NdJsonStreamReader;
use Cucumber\Messages\Envelope;

$fh = fopen('messages.ndjson', 'r');
$reader = new NdJsonStreamReader($fh);

/** @var Generator $envelopes */
$envelopes = $reader->envelopes();

try {
    foreach ($envelopes as $envelope) {
        /** @var Envelope $envelope */
        // process the message
    }
}
catch (DecodingException $e) {
    // handle any errors here
}
```

### Producing messages

[](#producing-messages)

All arguments of a Cucumber Message are optional, but any non-nullable fields will have default values.

Because Messages tend to have a large number of arguments, it's recommended to use named fields to construct them:

```
use Cucumber\Messages\Envelope;
use Cucumber\Messages\TestCaseFinished;
use Cucumber\Messages\Timestamp;

$envelope = new Envelope(
    testCaseFinished: new TestCaseFinished(
        timestamp: new Timestamp(
            seconds: 100
        )
    )
);
```

#### Encoding a JSON string

[](#encoding-a-json-string)

An Envelope can be encoded as a JSON string:

```
$json = $envelope->asJson();
```

Do *not* `json_encode()` the object externally, as the correct encoding options may not be set.

#### Producing JSON streams

[](#producing-json-streams)

Cucumber Messages are streamed as Newline Delimited JSON (NDJSON).

You can use the NdJsonStreamReader to write the contents of list of Envelopes to a stream.

```
use Cucumber\Messages\Streams\NdJson\NdJsonStreamReader;

$fh = fopen('php://stdout', 'w');

$writer = new NdJsonStreamWriter($fh)

// write a fixed array of envelopes
$envArray = [
    new Envelope(gherkinDocument: new GherkinDocument()),
    new Envelope(gherkinDocument: new GherkinDocument()),
];
$writer->write($envArray);

// write lazily-evaluated envelopes
$envGenerator = (function() {
    while ($envelope = Database::fetchNextEnvelope()) {
        yield $envelope;
    }
})();
$writer->write($envGenerator);
```

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance84

Actively maintained with recent releases

Popularity34

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

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 ~39 days

Recently: every ~25 days

Total

38

Last Release

80d ago

Major Versions

v27.2.0 → v28.0.02025-07-07

v28.1.0 → v29.0.02025-09-08

v29.0.1 → v30.0.02025-09-08

v30.1.0 → v31.0.02025-11-18

v31.2.0 → v32.0.02026-01-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/e7c4612e19ba73b517d8c3e15890af6687f8a206eb56676c1714209534378429?d=identicon)[ciaranmcnulty](/maintainers/ciaranmcnulty)

![](https://www.gravatar.com/avatar/d3f305e1cf8ad4e72ed15a6f9b77ba5f665843bb1713cfd4ff1c6b702eb078f6?d=identicon)[cukebot](/maintainers/cukebot)

---

Top Contributors

[![mpkorstanje](https://avatars.githubusercontent.com/u/6946919?v=4)](https://github.com/mpkorstanje "mpkorstanje (14 commits)")[![ciaranmcnulty](https://avatars.githubusercontent.com/u/237866?v=4)](https://github.com/ciaranmcnulty "ciaranmcnulty (12 commits)")[![davidjgoss](https://avatars.githubusercontent.com/u/3192745?v=4)](https://github.com/davidjgoss "davidjgoss (11 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (8 commits)")[![aurelien-reeves](https://avatars.githubusercontent.com/u/24386780?v=4)](https://github.com/aurelien-reeves "aurelien-reeves (7 commits)")[![jkronegg](https://avatars.githubusercontent.com/u/2843894?v=4)](https://github.com/jkronegg "jkronegg (2 commits)")[![luke-hill](https://avatars.githubusercontent.com/u/20105237?v=4)](https://github.com/luke-hill "luke-hill (1 commits)")[![ehuelsmann](https://avatars.githubusercontent.com/u/2326559?v=4)](https://github.com/ehuelsmann "ehuelsmann (1 commits)")[![clrudolphi](https://avatars.githubusercontent.com/u/1702962?v=4)](https://github.com/clrudolphi "clrudolphi (1 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[ngfw/recipe

Small Collection of useful PHP functions

6744.9k](/packages/ngfw-recipe)[unicodeveloper/laravel-identify

A Laravel 5 Package Provider to Identify/detect a user's browser, device, operating system and Language

19322.0k](/packages/unicodeveloper-laravel-identify)[goalgorilla/social_template

Social project template for composer based Open Social projects.

3444.8k](/packages/goalgorilla-social-template)[rick20/ppob

PPOB Multi Pulsa API PHP Library.

356.0k](/packages/rick20-ppob)

PHPackages © 2026

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