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

v33.0.4(1w ago)0254.0k—3.4%2MITPHPPHP ^8.4

Since Mar 24Pushed 3w ago5 watchersCompare

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

READMEChangelogDependencies (15)Versions (46)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

62

—

FairBetter than 99% of packages

Maintenance97

Actively maintained with recent releases

Popularity35

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity79

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

Recently: every ~29 days

Total

45

Last Release

9d ago

Major Versions

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

v32.3.1 → v33.0.02026-02-27

PHP version history (2 changes)v18.0.0PHP ^8.1

v33.0.3PHP ^8.4

### Community

Maintainers

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

![](https://avatars.githubusercontent.com/u/5459659?v=4)[Cucumber Bot](/maintainers/cukebot)[@cukebot](https://github.com/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

[webpatser/laravel-uuid

Laravel integration for webpatser/uuid - High-performance drop-in UUID replacements (15% faster than Ramsey). Provides Str macros, HasUuids trait, facades, and casts. RFC 4122/9562 compliant.

1.8k17.9M141](/packages/webpatser-laravel-uuid)[php-ds/php-ds

Specialized data structures as alternatives to the PHP array

4109.5M170](/packages/php-ds-php-ds)[odolbeau/phone-number-bundle

Integrates libphonenumber into your Symfony application

24811.2M19](/packages/odolbeau-phone-number-bundle)[sagem-cassiopee/php-metar-decoder

METAR weather observation decoder

518.0k](/packages/sagem-cassiopee-php-metar-decoder)[assistant-engine/filament-assistant

A Filament Assistant package that enables AI features, bringing advanced assistant capabilities directly into Filament.

392.7k](/packages/assistant-engine-filament-assistant)[marcgoertz/shorten

Safely truncate HTML markup while preserving tags, handling entities, and supporting Unicode/emoji with optional word-safe truncation

129.5k1](/packages/marcgoertz-shorten)

PHPackages © 2026

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