twentytwo-labs / behat-amqp
Behat Amqp Context to test AMQP messages, based on Swarrot library and PECL AMQP php extension.
Installs: 160
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/twentytwo-labs/behat-amqp
Requires
- ext-amqp: *
- ext-json: *
- behat/behat: ^3.4
- swarrot/swarrot: ^2.4 || ^3.0 || ^4.0
- symfony/yaml: ^3.4 || ^4.0 || ^5.0 || ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- phpmd/phpmd: ^2.6
- phpmetrics/phpmetrics: ^2.4
- squizlabs/php_codesniffer: ^3.4
- twentytwo-labs/array-comparator: ^1.0
README
This project is an extension built for Behat that allows you to test AMQP messages.
It is based on Swarrot library and PECL AMQP php extension.
Setup
Simply add the
- AmqpContext to your behat.yml config:
default: suites: your_suite: ... contexts: - ... - 'TwentytwoLabs\BehatAmqpExtension\Context\AmqpContext'
- BehatAmqpExtension to your behat.yml config:
default: extension: ... TwentytwoLabs\BehatAmqpExtension: ~
By default the BehatAmqpExtension uses the default connection to RabbitMQ:
host: localhost port: 5672 vhost: / login: guest password: guest
But you can override this configuration with your own values when you add the AmqpContext to your behat.yml file:
default: extension: ... TwentytwoLabs\BehatAmqpExtension: host: your_custom_host port: 5672 vhost: / login: your_custom_login password: your_custom_password
How to use
In your Behat test scenarios you can use these steps to test your AMQP Messages:
Then I set message properties:(with properties described as YAML in a Gherkin PyStringNode)Then I set message body:(with body as a Gherkin PyStringNode)Then I publish message with routing key :routingKey(this will publish a message to RabbitMQ with previously set properties and/or body)Then I purge queue :queue_name(will purge all messages in that queue)Given I have :count message(s) in amqp :transport queueGiven I have messages in amqp :transport queueGiven I wait :sleep second(s)Then I consume a message from queue :queue_nameThen the message should have property :property equal to :valueThen the message should have header :header equal to :valueThen the message body should contain :bodyThen the message body should be equal to :bodyThen the message body should be match to :bodyThen the message body should have JSON node :node equal to :valueThen print the message body(to display the content of your message in console)Then print the message properties(to display the message properties in console)
For a fully functional example see our Behat feature file: features/context.feature
Licence
MIT