ygalescot/behat-swarrot-context

Behat Swarrot Context 是用于测试 AMQP 消息的 Behat 扩展,基于 Swarrot 库和 PECL AMQP php 扩展。

0.1 2018-07-19 16:11 UTC

This package is not auto-updated.

Last update: 2024-09-19 14:57:13 UTC


README

此项目是为 Behat 构建的扩展,允许您测试 AMQP 消息。

它基于 Swarrot 库和 PECL AMQP php 扩展。

设置

只需将 SwarrotContext 添加到您的 behat.yml 配置文件中

default:
    suites:
        your_suite:
            ...
            contexts:
                - ...
                - 'Ygalescot\BehatSwarrotContext\Context\SwarrotContext'
    

默认情况下,SwarrotContext 使用 RabbitMQ 的默认连接

host: localhost
port: 5672
vhost: /
login: guest
password: guest

但您可以在将 SwarrotContext 添加到 behat.yml 文件时使用自己的值覆盖此配置

default:
    suites:
        your_suite:
            ...
            contexts:
                - ...
                - 'Ygalescot\BehatSwarrotContext\Context\SwarrotContext':
                    host: your_custom_host
                    port: 5672
                    vhost: /
                    login: your_custom_login
                    password: your_custom_password

如何使用

在您的 Behat 测试场景中,您可以使用以下步骤测试您的 AMQP 消息

  • Given I purge queue :queue_name (将清除该队列中的所有消息)
  • Then I set message properties: (使用 YAML 描述的属性作为 Gherkin PyStringNode)
  • Then I set message body: (将正文作为 Gherkin PyStringNode)
  • Then I publish message with routing key :routingKey (这将使用之前设置的属性和/或正文将消息发布到 RabbitMQ)
  • 然后从队列 :queue_name 消费消息
  • 然后消息应该具有属性 :property 等于 :value
  • 然后消息应该具有标题 :header 等于 :value
  • 然后消息正文应包含 :body
  • 然后消息正文应具有 JSON 节点 :node 等于 :value
  • Then print the message body (在控制台显示消息的内容)
  • Then print the message properties (在控制台显示消息属性)

有关完整功能的示例,请参阅我们的 Behat 功能文件: features/context.feature

许可证

MIT