-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update documentation for context
- Loading branch information
Showing
8 changed files
with
254 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Behat Custom Step: Verify All Messages in a Transport | ||
|
||
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. | ||
|
||
## Purpose | ||
|
||
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. | ||
|
||
## Function Overview | ||
|
||
### Signature: | ||
```gherkin | ||
Then all transport ":transportName" messages should be JSON: | ||
""" | ||
[ | ||
{ | ||
"event": "status_updated", | ||
"time": "123123123", | ||
"payload": "dqwdwdwdw" | ||
}, | ||
{ | ||
"event": "order_created", | ||
"time": "456456456", | ||
"payload": "otherPayload" | ||
} | ||
] | ||
""" | ||
``` | ||
|
||
### Parameters: | ||
- `transportName` (string): The name of the transport (e.g., 'async') where the message is expected to be found. | ||
- `expectedMessage` PyStringNode): A JSON array representing the expected content of all messages that should be present in the transport. |
41 changes: 41 additions & 0 deletions
41
docs/MessengerContext/check_all_transport_message_regexp.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Behat Custom Step: Verify All Messages in Transport with Variable Fields | ||
|
||
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. | ||
## Purpose | ||
|
||
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 | ||
|
||
### Signature: | ||
```php | ||
/** | ||
* @Then all transport :transportName messages should be JSON with variable fields :variableFields: | ||
*/ | ||
public function allTransportMessagesShouldBeJsonWithVariableFields( | ||
string $transportName, | ||
string $variableFields, | ||
PyStringNode $expectedMessageList | ||
): void | ||
``` | ||
|
||
### Parameters: | ||
- `transportName` (string): The name of the transport (e.g., 'webhook') where the message is expected to be found. | ||
- `variableFields` (string): A comma-separated list of fields where values may vary and should be compared using regular expressions. | ||
- `expectedMessage` (PyStringNode): The expected message content in JSON format, where fields marked with `~` in their values will be treated as regular expressions. | ||
|
||
```gherkin | ||
Then all transport ":transportName" messages should be JSON with variable fields ":variableFields": | ||
""" | ||
[ | ||
{ | ||
"event": "status_updated", | ||
"time": "~^\\d{13}$", | ||
"payload": "dqwdwdwdw" | ||
}, | ||
{ | ||
"event": "order_created", | ||
"time": "~^\\d{13}$", | ||
"payload": "otherPayload" | ||
} | ||
] | ||
""" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
# Behat Custom Step: Transport JSON Message Assertion | ||
|
||
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. | ||
|
||
## Purpose | ||
|
||
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. | ||
|
||
## Function Overview | ||
|
||
### Signature: | ||
```gherkin | ||
Then transport ":transportName" should contain message with JSON: | ||
""" | ||
{ | ||
"event": "status_updated", | ||
"time": "123123123", | ||
"payload": "dqwdwdwdw" | ||
} | ||
""" | ||
``` | ||
|
||
### Parameters: | ||
- `transportName` (string): The name of the transport (e.g., 'async') where the message is expected to be found. | ||
- `expectedMessage` (PyStringNode): The expected message content in JSON format that should be present in the transport. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
# Behat Custom Step: Transport JSON Message Assertion with Regexp Fields | ||
|
||
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. | ||
## Purpose | ||
|
||
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. | ||
## Function Overview | ||
|
||
### Signature: | ||
```php | ||
/** | ||
* @Then transport :transportName should contain message with JSON and variable fields :variableFields: | ||
*/ | ||
public function transportShouldContainMessageWithJsonAndVariableFields( | ||
string $transportName, | ||
string $variableFields, | ||
PyStringNode $expectedMessage | ||
): void | ||
``` | ||
|
||
### Parameters: | ||
- `transportName` (string): The name of the transport (e.g., 'webhook') where the message is expected to be found. | ||
- `variableFields` (string): A comma-separated list of field names where values should be matched using regular expressions. | ||
- `expectedMessage` (PyStringNode): The expected message content in JSON format, where fields marked with `~` in their values will be treated as regular expressions. | ||
|
||
```gherkin | ||
And transport "webhook" should contain message with JSON and variable fields "time, payload": | ||
""" | ||
{ | ||
"event": "customer_agreement_status_updated", | ||
"time": "~^\\d{13}$", | ||
"payload": "~^\\{.*\\}$" | ||
} | ||
""" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Behat Custom Step: Verify Message Count in a Transport | ||
|
||
This documentation outlines the purpose and usage of the custom Behat step definition for verifying that a specific number of messages exist in a given Symfony Messenger transport. | ||
|
||
## Purpose | ||
|
||
This function is designed to check that the number of messages in a specific transport (e.g., asynchronous queues) matches the expected count. It is useful in scenarios where you need to ensure that the correct number of messages have been dispatched into the transport during a Behat test. | ||
|
||
## Function Overview | ||
|
||
### Signature: | ||
```php | ||
/** | ||
* @Then there is :expectationMessageCount messages in transport :transportName | ||
*/ | ||
public function thereIsCountMessagesInTransport(int $expectedMessageCount, string $transportName): void | ||
``` | ||
|
||
### Parameters: | ||
- `expectedMessageCount` (int): The expected number of messages that should be present in the transport. | ||
- `transportName` (string): The name of the transport (e.g., 'async') where the messages are expected to be found. | ||
|
||
```gherkin | ||
Then there is 1 messages in transport "command" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
# Installation Guide | ||
|
||
## Step 1: Install the Bundle | ||
To begin, navigate to your project directory and use Composer to download the bundle. | ||
|
||
### For applications using Symfony Flex: | ||
Simply run the following command: | ||
|
||
```bash | ||
composer require --dev macpaw/behat-messenger-context | ||
``` | ||
|
||
### For applications without Symfony Flex: | ||
If your project doesn't use Symfony Flex, run the same command: | ||
|
||
```bash | ||
composer require --dev macpaw/behat-messenger-context | ||
``` | ||
|
||
Make sure that Composer is installed globally on your machine. If not, refer to the [Composer installation guide](https://getcomposer.org/doc/00-intro.md) for assistance. | ||
|
||
Next, you'll need to manually register the bundle in the `AppKernel.php` file. Add the following line to the `registerBundles` method: | ||
|
||
```php | ||
// app/AppKernel.php | ||
|
||
class AppKernel extends Kernel | ||
{ | ||
public function registerBundles() | ||
{ | ||
$bundles = [ | ||
// Other bundles | ||
BehatMessengerContext\BehatMessengerContextBundle::class => ['test' => true], | ||
]; | ||
} | ||
} | ||
``` | ||
|
||
## Step 2: Configure Symfony Messenger for Testing | ||
To ensure your messenger configuration is properly set up for testing, you need to copy the configuration from `config/packages/dev/messenger.yaml` to `config/packages/test/messenger.yaml`. Then, update the configuration to use in-memory transport for testing. | ||
|
||
```yaml | ||
framework: | ||
messenger: | ||
transports: | ||
async: 'in-memory://' | ||
async_priority_high: 'in-memory://' | ||
``` | ||
OR in your global config file `config/packages/messenger.yaml` | ||
```yaml | ||
framework: | ||
messenger: | ||
transports: | ||
async: 'in-memory://' | ||
async_priority_high: 'in-memory://' | ||
``` | ||
|
||
This ensures that your tests use an in-memory transport rather than actual services. | ||
|
||
## Step 3: Behat Configuration | ||
In your `behat.yml` file, make sure the Messenger context is registered: | ||
|
||
```yaml | ||
default: | ||
suites: | ||
default: | ||
contexts: | ||
- BehatMessengerContext\Context\MessengerContext | ||
``` | ||
|
||
This completes the setup for integrating Behat with Symfony Messenger in your project. Now you're ready to run tests with the in-memory transport! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters