pccomponentes / open-api-messaging-context
用于验证与 OpenApi 架构消息的 Behat 上下文
Requires
- php: ^8.0
- ext-json: *
- beberlei/assert: ^3.3
- behat/behat: ^3.13
- friends-of-behat/mink: ^1.10
- friends-of-behat/mink-browserkit-driver: ^1.6
- friends-of-behat/mink-extension: ^2.7
- friends-of-behat/symfony-extension: ^2.4
- justinrainbow/json-schema: ^5.2
- pccomponentes/ddd: ^3.0 || ^4.0
- symfony/cache: ^5.0 || ^6.0 || ^7.0
- symfony/messenger: ^5.0 || ^6.0 || ^7.0
- symfony/yaml: ^5.0 || ^6.0 || ^7.0
Requires (Dev)
- pccomponentes/coding-standard: ^3.0
- phpunit/phpunit: ^9.0
- symfony/var-dumper: ^5.0 || ^6.0 || ^7.0
- dev-master
- v3.3.0
- v3.2.0
- v3.1.0
- v3.0.0
- v2.11.0
- v2.10.0
- v2.9.0
- v2.8.1
- v2.8.0
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.1
- v2.0.0
- v1.0.0
- v0.1.1
- v0.1.0
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-feature/allow-symfony-7
- dev-feature/add-request-validation-using-openapi
- dev-feature/cache-schemas
- dev-feature/add-failing-messages-validation
This package is auto-updated.
Last update: 2024-09-24 15:05:21 UTC
README
在 Behat 中几乎没有上下文来验证根据 AsyncApi 和 OpenApi 规范发布的消息和 HTTP 响应。
安装
composer require --dev pccomponentes/open-api-messaging-context
配置
此包使用 Friends Of Behat Symfony 扩展,您必须查看如何使用此扩展配置您的 Behat。
如何使用
在测试环境中将 SpyMiddleware 定义为服务
services: spy.message.middleware: class: PcComponentes\OpenApiMessagingContext\Messaging\SpyMiddleware
在 test
环境的 messenger.yaml
配置中添加 SpyMiddleware 作为中间件。
framework: messenger: buses: messenger.bus.event-broker: middleware: - spy.message.middleware messenger.bus.command: middleware: - spy.message.middleware
在您的 behat.yml
中配置上下文
default: suites: default: contexts: - PcComponentes\OpenApiMessagingContext\Behat\MessageValidatorOpenApiContext: - '%%kernel.project_dir%%' - '@spy.message.middleware'
然后使用 Then
语句来验证消息
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"
您的架构必须根据 https://www.asyncapi.com/ 规范编写。
适用于版本架构 1.2.0
和 2.0.0
。
可用上下文
MessageValidatorOpenApiContext
检查与您的 asyncapi 文件匹配的已发送消息的内容
Then the published message "pccomponentes.example.1.domain_event.resource.resource_created" should be valid according to swagger "docs/asyncapi.yml"
检查消息是否已发送
Then the message "pccomponentes.example.1.domain_event.resource.resource_created" should be dispatched
检查消息是否未发送
Then the message "pccomponentes.example.1.domain_event.resource.resource_created" should not be dispatched
配置
- PcComponentes\OpenApiMessagingContext\Behat\MessageValidatorOpenApiContext: - '%%kernel.project_dir%%' - '@spy.message.middleware'
ResponseValidatorOpenApiContext
检查您的 openapi 文件中是否记录了 HTTP 请求
Then the request should be valid according to OpenApi "docs/openapi.yml" with path "/your/openapi/path/"
检查您的 openapi 文件中是否记录了 HTTP 响应
Then the response should be valid according to OpenApi "docs/openapi.yml" with path "/your/openapi/path/"
此外,您可以使用以下方式同时检查请求和响应
Then the request and response should be valid according to OpenApi "docs/openapi.yml" with path "/your/openapi/path/"
配置
- PcComponentes\OpenApiMessagingContext\Behat\ResponseValidatorOpenApiContext: - '%%kernel.project_dir%%'
SimpleMessageContext
SimpleMessage 输入的 When
步骤
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
这可以与 MessageValidatorOpenApiContext
中的 Then
步骤结合使用
配置
- PcComponentes\OpenApiMessagingContext\Behat\SimpleMessageContext: - '@messenger.bus.command' ##Your command bus with spy.message.middleware - '@your.simple_message_deserializer.service'
提示 如果您正在使用 pccomponentes/messenger-bundle,则可以使用 @pccom.messenger_bundle.simple_message.serializer.stream_deserializer
作为反序列化服务
AggregateMessageContext
AggregateMessage 输入的 When
步骤
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
这可以与 MessageValidatorOpenApiContext
中的 Then
步骤结合使用
配置
- PcComponentes\OpenApiMessagingContext\Behat\AggregateMessageContext: - '@messenger.bus.events' ## Your event bus with spy.message.middleware - '@your.aggregate_message_deserializer.service'
提示 如果您正在使用 pccomponentes/messenger-bundle,则可以使用 @pccom.messenger_bundle.aggregate_message.serializer.stream_deserializer
作为反序列化服务