PHPackages                             pccomponentes/open-api-messaging-context - 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. pccomponentes/open-api-messaging-context

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

pccomponentes/open-api-messaging-context
========================================

Behat context for validating messages with OpenApi schema

v4.0.0(3mo ago)974.7k—9.3%2[1 PRs](https://github.com/PcComponentes/open-api-messaging-context/pulls)MITPHPPHP ^8.0

Since Apr 4Pushed 3mo ago4 watchersCompare

[ Source](https://github.com/PcComponentes/open-api-messaging-context)[ Packagist](https://packagist.org/packages/pccomponentes/open-api-messaging-context)[ RSS](/packages/pccomponentes-open-api-messaging-context/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (35)Used By (0)

Little context in behat for validate published messages and http responses according to an AsyncApi and OpenApi specification.

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

[](#installation)

```
composer require --dev pccomponentes/open-api-messaging-context

```

Configuration
=============

[](#configuration)

This package uses [Friends Of Behat Symfony Extension](https://github.com/FriendsOfBehat/SymfonyExtension), you must see how to configure your behat with this extension.

How to use
==========

[](#how-to-use)

Define SpyMiddleware as a service in your test environment:

```
services:
  spy.message.middleware:
    class: PcComponentes\OpenApiMessagingContext\Messaging\SpyMiddleware
```

Add SpyMiddleware as a middleware in `messenger.yaml` configuration in `test` environment.

```
framework:
  messenger:
    buses:
      messenger.bus.event-broker:
        middleware:
          - spy.message.middleware
      messenger.bus.command:
        middleware:
          - spy.message.middleware
```

Configure the context in your `behat.yml`

```
default:
  suites:
    default:
      contexts:
        - PcComponentes\OpenApiMessagingContext\Behat\MessageValidatorOpenApiContext:
          - '%%kernel.project_dir%%'
          - '@spy.message.middleware'
```

And use the `Then` statement for validate messages:

```
Scenario: My awesome scenario
  Given the environment is clean
  When I send a "POST" request to "/resource/" with body:
  """
  {
    "my-awesome-data": "foo",
  }
  """
  Then the published message "pccomponentes.example.1.domain_event.resource.resource_created" should be valid according to swagger "docs/asyncapi.yml"
```

Your schema must be writen according to  specification.

Available for version schemas `1.2.0` and `2.0.0`.

Available contexts
==================

[](#available-contexts)

MessageValidatorOpenApiContext
------------------------------

[](#messagevalidatoropenapicontext)

Check the content of the dispatched message that matches with your asyncapi file:

```
Then the published message "pccomponentes.example.1.domain_event.resource.resource_created" should be valid according to swagger "docs/asyncapi.yml"
```

Check if message has dispatched:

```
Then the message "pccomponentes.example.1.domain_event.resource.resource_created" should be dispatched
```

Check if message has not been dispatched:

```
Then the message "pccomponentes.example.1.domain_event.resource.resource_created" should not be dispatched
```

Configuration:

```
- PcComponentes\OpenApiMessagingContext\Behat\MessageValidatorOpenApiContext:
  - '%%kernel.project_dir%%'
  - '@spy.message.middleware'
```

ResponseValidatorOpenApiContext
-------------------------------

[](#responsevalidatoropenapicontext)

Check if http requests are documented in your openapi file:

```
Then the request should be valid according to OpenApi "docs/openapi.yml" with path "/your/openapi/path/"
```

Check if http responses are documented in your openapi file:

```
Then the response should be valid according to OpenApi "docs/openapi.yml" with path "/your/openapi/path/"
```

Additionally, you can check both the request and response with:

```
Then the request and response should be valid according to OpenApi "docs/openapi.yml" with path "/your/openapi/path/"
```

Configuration:

```
- PcComponentes\OpenApiMessagingContext\Behat\ResponseValidatorOpenApiContext:
  - '%%kernel.project_dir%%'
```

SimpleMessageContext
--------------------

[](#simplemessagecontext)

`When` step for SimpleMessage input:

```
When I receive a simple message with payload:
"""
{
  "data": {
    "message_id": "d2439fd8-be54-4233-ba59-fe3187620505",
    "type": "pccomponentes.example.1.command.resource.create_resource",
    "attributes": {
      "id": "3c44e76e-1369-4a95-84ac-3a78f9c1f354",
      "my_awesome_data": "foo",
    }
  }
}
"""
Then the message "pccomponentes.example.1.domain_event.resource.resource_created" should be dispatched
```

This is useful to combine it with `Then` step in `MessageValidatorOpenApiContext`

Configuration:

```
- PcComponentes\OpenApiMessagingContext\Behat\SimpleMessageContext:
  - '@messenger.bus.command' ##Your command bus with spy.message.middleware
  - '@your.simple_message_deserializer.service'
```

*TIP* If you are using [pccomponentes/messenger-bundle](https://github.com/PcComponentes/messenger-bundle) you can use `@pccom.messenger_bundle.simple_message.serializer.stream_deserializer` for deserializer service

AggregateMessageContext
-----------------------

[](#aggregatemessagecontext)

`When` step for AggregateMessage input:

```
When I receive an aggregate message with payload:
"""
{
  "data": {
    "message_id": "2b8c7e00-219e-4d12-8b0e-dac2cc432410",
    "type": "pccomponentes.example.1.domain_event.resource.resource_created",
    "occurred_on": "1554900327",
    "attributes": {
      "aggregate_id": "0e7c57f8-d679-4605-ba27-3008b9636a0a",
      "status": "OPEN"
    }
  }
}
"""
Then the message "pccomponentes.example.1.command.resource.create_resource_projection" should be dispatched
```

This is useful to combine it with `Then` step in `MessageValidatorOpenApiContext`

Configuration:

```
- PcComponentes\OpenApiMessagingContext\Behat\AggregateMessageContext:
  - '@messenger.bus.events' ## Your event bus with spy.message.middleware
  - '@your.aggregate_message_deserializer.service'
```

*TIP* If you are using [pccomponentes/messenger-bundle](https://github.com/PcComponentes/messenger-bundle) you can use `@pccom.messenger_bundle.aggregate_message.serializer.stream_deserializer` for deserializer service

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance79

Regular maintenance activity

Popularity37

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor2

2 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 ~86 days

Recently: every ~228 days

Total

30

Last Release

108d ago

Major Versions

v0.1.1 → v1.0.02020-05-01

v1.0.0 → v2.0.02020-07-22

v2.11.0 → v3.0.02023-07-31

v3.3.0 → v4.0.02026-01-30

PHP version history (6 changes)v0.0.1PHP ^7.2

v0.1.1PHP ^7.3

v1.0.0PHP ^7.4

v2.3.0PHP ^7.4|^8.0

v2.6.0PHP ^7.4 || ^8.0

v3.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c4eb3322c15a9344e9c086a7de11c3204bf5aab5321b562bf9193f5ee8cd420?d=identicon)[zoilomora](/maintainers/zoilomora)

---

Top Contributors

[![AaronBernabeu](https://avatars.githubusercontent.com/u/3294776?v=4)](https://github.com/AaronBernabeu "AaronBernabeu (34 commits)")[![zoilomora](https://avatars.githubusercontent.com/u/4701956?v=4)](https://github.com/zoilomora "zoilomora (19 commits)")[![calmohallag](https://avatars.githubusercontent.com/u/34070946?v=4)](https://github.com/calmohallag "calmohallag (13 commits)")[![jgmullor](https://avatars.githubusercontent.com/u/1301633?v=4)](https://github.com/jgmullor "jgmullor (5 commits)")[![ladbsoft](https://avatars.githubusercontent.com/u/30509719?v=4)](https://github.com/ladbsoft "ladbsoft (1 commits)")[![raulalmeidatarazona](https://avatars.githubusercontent.com/u/61455658?v=4)](https://github.com/raulalmeidatarazona "raulalmeidatarazona (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pccomponentes-open-api-messaging-context/health.svg)

```
[![Health](https://phpackages.com/badges/pccomponentes-open-api-messaging-context/health.svg)](https://phpackages.com/packages/pccomponentes-open-api-messaging-context)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[orchestra/workbench

Workbench Companion for Laravel Packages Development

8017.0M43](/packages/orchestra-workbench)[acquia/orca

A tool for testing a company's software packages together in the context of a realistic, functioning, best practices Drupal build

32902.4k](/packages/acquia-orca)

PHPackages © 2026

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