Skip to content

Commit b2bd499

Browse files
authored
Merge pull request #42 from MacPaw/develop
Release
2 parents 43d05e2 + 3aa81f7 commit b2bd499

25 files changed

+1258
-100
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@ jobs:
1818
- '6.3.*'
1919
- '6.4.*'
2020
- '7.0.*'
21+
- '7.1.*'
2122
include:
2223
- php: '8.2'
2324
coverage: 'xdebug'
24-
symfony-versions: '7.0.*'
25+
symfony-versions: '7.1.*'
2526

2627

2728
name: PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} ${{ matrix.description }}
2829
steps:
2930
- name: Checkout
3031
uses: actions/checkout@v2
3132

32-
- uses: actions/cache@v2
33+
- uses: actions/cache@v4
3334
with:
3435
path: ~/.composer/cache/files
3536
key: ${{ matrix.php }}-${{ matrix.symfony-versions }}
@@ -48,7 +49,7 @@ jobs:
4849
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
4950

5051
- name: Cache composer
51-
uses: actions/cache@v2.1.2
52+
uses: actions/cache@v4
5253
with:
5354
path: ${{ steps.composer-cache.outputs.dir }}
5455
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer-${{ hashFiles('composer.json') }}
@@ -74,8 +75,9 @@ jobs:
7475
if: matrix.coverage == 'xdebug'
7576

7677
- name: Run codecov
77-
uses: codecov/codecov-action@v1
78+
uses: codecov/codecov-action@v4.0.1
7879
if: matrix.coverage == 'xdebug'
7980
with:
80-
file: './coverage.xml'
81-
fail_ci_if_error: true
81+
token: ${{ secrets.CODECOV_TOKEN }}
82+
file: './coverage.xml'
83+
fail_ci_if_error: true

.github/workflows/static-analysis.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@v4
1515

1616
- name: Setup PHP
1717
uses: shivammathur/setup-php@v2
@@ -27,7 +27,7 @@ jobs:
2727
runs-on: ubuntu-latest
2828
steps:
2929
- name: Checkout
30-
uses: actions/checkout@v2
30+
uses: actions/checkout@v4
3131

3232
- name: Setup PHP
3333
uses: shivammathur/setup-php@v2
@@ -43,7 +43,7 @@ jobs:
4343
runs-on: ubuntu-latest
4444
steps:
4545
- name: Checkout
46-
uses: actions/checkout@v2
46+
uses: actions/checkout@v4
4747

4848
- name: Setup PHP
4949
uses: shivammathur/setup-php@v2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
/node_modules/
66
/.idea/
77
/package-lock.json
8+
/reports
9+
/clover.xml

README.md

Lines changed: 32 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,48 @@
1-
Behat Messenger Context Bundle
2-
=================================
1+
# Behat Messenger Context Bundle
2+
[![Latest Stable Version](http://poser.pugx.org/macpaw/behat-messenger-context/v)](https://packagist.org/packages/macpaw/behat-messenger-context)
3+
[![Total Downloads](http://poser.pugx.org/macpaw/behat-messenger-context/downloads)](https://packagist.org/packages/macpaw/behat-messenger-context)
4+
[![Latest Unstable Version](http://poser.pugx.org/macpaw/behat-messenger-context/v/unstable)](https://packagist.org/packages/macpaw/behat-messenger-context)
5+
[![License](http://poser.pugx.org/macpaw/behat-messenger-context/license)](https://packagist.org/packages/macpaw/behat-messenger-context)
6+
[![PHP Version Require](http://poser.pugx.org/macpaw/behat-messenger-context/require/php)](https://packagist.org/packages/macpaw/behat-messenger-context)
37

4-
| Version | Build Status | Code Coverage |
5-
|:---------:|:-------------:|:-----:|
6-
| `master`| [![CI][master Build Status Image]][master Build Status] | [![Coverage Status][master Code Coverage Image]][master Code Coverage] |
7-
| `develop`| [![CI][develop Build Status Image]][develop Build Status] | [![Coverage Status][develop Code Coverage Image]][develop Code Coverage] |
8+
| Version | Build Status | Coverage |
9+
|------------|------------------------------------------------------------|--------------------------------------------------------------------------|
10+
| `master` | [![CI][master Build Status Image]][master Build Status] | [![Coverage Status][master Code Coverage Image]][master Code Coverage] |
11+
| `develop` | [![CI][develop Build Status Image]][develop Build Status] | [![Coverage Status][develop Code Coverage Image]][develop Code Coverage] |
812

9-
Installation
10-
============
1113

12-
Step 1: Download the Bundle
13-
----------------------------------
14-
Open a command console, enter your project directory and execute:
14+
This repository provides custom Behat step definitions for working with Symfony Messenger transports. It includes functionality for checking messages in transports, validating them against expected JSON structures, and working with variable fields.
1515

16-
### Applications that use Symfony Flex [in progress](https://github.com/MacPaw/BehatRedisContext/issues/2)
16+
## Installation
1717

18-
```console
19-
$ composer require --dev macpaw/behat-messenger-context
20-
```
18+
To install the MessengerContext and integrate it with your Behat setup, follow the instructions provided in the [Installation Guide](docs/install.md).
2119

22-
### Applications that don't use Symfony Flex
20+
## Available Features
2321

24-
Open a command console, enter your project directory and execute the
25-
following command to download the latest stable version of this bundle:
22+
### Check a Specific Message in a Transport
23+
You can verify if a specific message exists in a given transport.
24+
* Documentation: [Check Transport Message](docs/MessengerContext/check_transport_message.md)
2625

27-
```console
28-
$ composer require --dev macpaw/behat-messenger-context
29-
```
26+
### Check All Messages in a Transport
27+
Verify if all messages in a given transport match the expected JSON structure.
28+
* Documentation: [Check All Transport Messages](docs/MessengerContext/check_all_transport_message.md)
3029

31-
This command requires you to have Composer installed globally, as explained
32-
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
33-
of the Composer documentation.
30+
### Check Messages with Regular Expressions
31+
You can use regular expressions to validate messages that contain dynamic or variable data.
32+
* Documentation for specific message: [Check Transport Message with Regexp](docs/MessengerContext/check_transport_message_regexp.md)
33+
* Documentation for all messages: [Check All Transport Messages with Regexp](docs/MessengerContext/check_all_transport_message_regexp.md)
3434

35+
### Check Every Messages with Mask Regular Expressions
36+
You can use regular expression to validate all messages messages that contain dynamic or variable data.
37+
* Documentation for all specific message: [Check Transport Messages with Regexp](docs/MessengerContext/check_transport_messages_regexp_mask.md)
3538

36-
Then, enable the bundle by adding it to the list of registered bundles
37-
in the `app/AppKernel.php` file of your project:
39+
### Verify Message Count in a Transport
40+
Ensure that a specific number of messages exist in a given transport.
3841

39-
```php
40-
<?php
41-
// app/AppKernel.php
42+
### Auto clean queue messages before scenario
43+
Check details in [documentation](docs/MessengerContext/clear_transport_with_zentruck.md)
4244

43-
// ...
44-
class AppKernel extends Kernel
45-
{
46-
public function registerBundles()
47-
{
48-
$bundles = array(
49-
// ...
50-
BehatMessengerContext\BehatMessengerContextBundle::class => ['test' => true],
51-
);
52-
53-
// ...
54-
}
55-
56-
// ...
57-
}
58-
```
59-
60-
Step 2: Configure Messenger
61-
=============
62-
Copying `config/packages/dev/messenger.yaml` and pasting that into `config/packages/test/`. This gives us messenger configuration that will only be used in the test environment. Uncomment the code, and replace sync with in-memory. Do that for both of the transports.
63-
64-
```yaml
65-
framework:
66-
messenger:
67-
transports:
68-
async: 'in-memory://'
69-
async_priority_high: 'in-memory://'
70-
...
71-
...
72-
```
73-
74-
75-
Step 3: Configure Behat
76-
=============
77-
Go to `behat.yml`
78-
79-
```yaml
80-
...
81-
contexts:
82-
- BehatMessengerContext\Context\MessengerContext
83-
...
84-
```
45+
* Documentation: [Count Messages in Transport](docs/MessengerContext/count_message_transport.md)
8546

8647
[master Build Status]: https://github.com/macpaw/behat-messenger-context/actions?query=workflow%3ACI+branch%3Amaster
8748
[master Build Status Image]: https://github.com/macpaw/behat-messenger-context/workflows/CI/badge.svg?branch=master

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
"slevomat/coding-standard": "^7.0",
4141
"squizlabs/php_codesniffer": "^3.6"
4242
},
43+
"suggest": {
44+
"zenstruck/messenger-test": "To use Zentruck messages clearing"
45+
},
4346
"autoload": {
4447
"psr-4": {
4548
"BehatMessengerContext\\": "src"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Behat Custom Step: Verify All Messages in a Transport
2+
3+
This documentation outlines the purpose and usage of the custom Behat step definition for verifying that all messages in a specific Symfony Messenger transport match a list of expected JSON structures.
4+
5+
## Purpose
6+
7+
This function is designed to validate that all messages in a specific transport (e.g., asynchronous queues) match a given set of expected JSON structures. It is useful in scenarios where you need to ensure that every message in the transport adheres to a specific structure or content format.
8+
9+
## Function Overview
10+
11+
### Signature:
12+
```gherkin
13+
Then all transport ":transportName" messages should be JSON:
14+
"""
15+
[
16+
{
17+
"event": "status_updated",
18+
"time": "123123123",
19+
"payload": "dqwdwdwdw"
20+
},
21+
{
22+
"event": "order_created",
23+
"time": "456456456",
24+
"payload": "otherPayload"
25+
}
26+
]
27+
"""
28+
29+
```
30+
31+
### Parameters:
32+
- `transportName` (string): The name of the transport (e.g., 'async') where the message is expected to be found.
33+
- `expectedMessage` PyStringNode): A JSON array representing the expected content of all messages that should be present in the transport.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Behat Custom Step: Verify All Messages in Transport with Variable Fields
2+
3+
This documentation outlines the purpose and usage of the custom Behat step definition for verifying that all messages in a specific Symfony Messenger transport match a list of expected JSON structures, while allowing certain fields to vary across the messages.
4+
## Purpose
5+
6+
This function is designed to validate that all messages in a specific transport (e.g., asynchronous queues) match a given set of expected JSON structures, while allowing certain fields (e.g., timestamps, unique IDs) to have variable values. This is useful in scenarios where specific fields in the messages may differ but the overall structure and format must remain consistent.## Function Overview
7+
8+
### Signature:
9+
```php
10+
/**
11+
* @Then all transport :transportName messages should be JSON with variable fields :variableFields:
12+
*/
13+
public function allTransportMessagesShouldBeJsonWithVariableFields(
14+
string $transportName,
15+
string $variableFields,
16+
PyStringNode $expectedMessageList
17+
): void
18+
```
19+
20+
### Parameters:
21+
- `transportName` (string): The name of the transport (e.g., 'webhook') where the message is expected to be found.
22+
- `variableFields` (string): A comma-separated list of fields where values may vary and should be compared using regular expressions.
23+
- `expectedMessage` (PyStringNode): The expected message content in JSON format, where fields marked with `~` in their values will be treated as regular expressions.
24+
25+
```gherkin
26+
Then all transport ":transportName" messages should be JSON with variable fields ":variableFields":
27+
"""
28+
[
29+
{
30+
"event": "status_updated",
31+
"time": "~^\\d{13}$",
32+
"payload": "dqwdwdwdw"
33+
},
34+
{
35+
"event": "order_created",
36+
"time": "~^\\d{13}$",
37+
"payload": "otherPayload"
38+
}
39+
]
40+
"""
41+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
# Behat Custom Step: Transport JSON Message Assertion
3+
4+
This documentation outlines the purpose and usage of the custom Behat step definition for verifying if a Symfony Messenger transport contains a message with a specific JSON structure.
5+
6+
## Purpose
7+
8+
This function is designed to check if a given transport (such as an asynchronous queue) contains a message that matches a particular JSON structure. It is useful in scenarios where you need to validate that a message was correctly dispatched with the expected content during Behat tests.
9+
10+
## Function Overview
11+
12+
### Signature:
13+
```gherkin
14+
Then transport ":transportName" should contain message with JSON:
15+
"""
16+
{
17+
"event": "status_updated",
18+
"time": "123123123",
19+
"payload": "dqwdwdwdw"
20+
}
21+
"""
22+
```
23+
24+
### Parameters:
25+
- `transportName` (string): The name of the transport (e.g., 'async') where the message is expected to be found.
26+
- `expectedMessage` (PyStringNode): The expected message content in JSON format that should be present in the transport.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
# Behat Custom Step: Transport JSON Message Assertion with Regexp Fields
3+
4+
This documentation outlines the purpose and usage of the custom Behat step definition for verifying if a Symfony Messenger transport contains a message with a specific JSON structure, using regular expressions to handle dynamic fields.
5+
6+
## Purpose
7+
8+
This function is designed to check if a given transport (such as an asynchronous queue) contains a message that matches a particular JSON structure, while allowing certain fields to be validated using regular expressions. It is particularly useful when testing messages with dynamic data, such as timestamps, unique identifiers, or payloads, where the exact value cannot be guaranteed.
9+
## Function Overview
10+
11+
### Signature:
12+
```php
13+
/**
14+
* @Then transport :transportName should contain message with JSON and variable fields :variableFields:
15+
*/
16+
public function transportShouldContainMessageWithJsonAndVariableFields(
17+
string $transportName,
18+
string $variableFields,
19+
PyStringNode $expectedMessage
20+
): void
21+
```
22+
23+
### Parameters:
24+
- `transportName` (string): The name of the transport (e.g., 'webhook') where the message is expected to be found.
25+
- `variableFields` (string): A comma-separated list of field names where values should be matched using regular expressions.
26+
- `expectedMessage` (PyStringNode): The expected message content in JSON format, where fields marked with `~` in their values will be treated as regular expressions.
27+
28+
```gherkin
29+
And transport "webhook" should contain message with JSON and variable fields "time, payload":
30+
"""
31+
{
32+
"event": "customer_agreement_status_updated",
33+
"time": "~^\\d{13}$",
34+
"payload": "~^\\{.*\\}$"
35+
}
36+
"""
37+
```
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
# Behat Custom Step: Transport JSON Message Assertion with Regexp Fields
3+
4+
This documentation outlines the purpose and usage of the custom Behat step definition for verifying if a Symfony Messenger transport contains a message with a specific JSON mask for every message, using regular expressions to handle dynamic fields.
5+
6+
## Purpose
7+
8+
This function is designed to check if a given transport (such as an asynchronous queue) contains a message that matches a message with a specific JSON mask for every message, while allowing certain fields to be validated using regular expressions. It is particularly useful when testing messages with dynamic data, such as timestamps, unique identifiers, or payloads, where the exact value cannot be guaranteed.
9+
## Function Overview
10+
11+
### Signature:
12+
```php
13+
/**
14+
* @Then all transport :transportName messages have JSON by :fields with mask :mask:
15+
*/
16+
public function allTransportMessagesHaveJsonByFieldsWithMask(
17+
string $transportName,
18+
string $variableFields,
19+
PyStringNode $expectedMessageList,
20+
): void {
21+
```
22+
23+
### Parameters:
24+
- `transportName` (string): The name of the transport (e.g., 'webhook') where the message is expected to be found.
25+
- `variableFields` (string): A comma-separated list of field names where values should be matched using regular expressions.
26+
- `expectedMessage` (PyStringNode): The expected message content in JSON format, where fields marked with `~` in their values will be treated as regular expressions.
27+
28+
```gherkin
29+
And all transport "webhook" messages should contain message with JSON and variable fields "time, payload" by mask:
30+
"""
31+
{
32+
"event": "customer_agreement_status_updated",
33+
"time": "~^\\d{13}$",
34+
"payload": "~^\\{.*\\}$"
35+
}
36+
"""
37+
```

0 commit comments

Comments
 (0)