pccomponentes/open-api-messaging-context
Composer 安装命令:
composer require pccomponentes/open-api-messaging-context
包简介
Behat context for validating messages with OpenApi schema
README 文档
README
Little context in behat for validate published messages and http responses according to an AsyncApi and OpenApi specification.
Installation
composer require --dev pccomponentes/open-api-messaging-context
Configuration
This package uses Friends Of Behat Symfony Extension, you must see how to configure your behat with this extension.
How to use
Define SpyMiddleware as a service in your test environment:
services: spy.message.middleware: class: PcComponentes\OpenApiMessagingContext\Messaging\SpyMiddleware
Add SpyMiddleware as a middleware in messenger.yaml configuration in test environment.
framework: messenger: buses: messenger.bus.event-broker: middleware: - spy.message.middleware messenger.bus.command: middleware: - spy.message.middleware
Configure the context in your behat.yml
default: suites: default: contexts: - PcComponentes\OpenApiMessagingContext\Behat\MessageValidatorOpenApiContext: - '%%kernel.project_dir%%' - '@spy.message.middleware'
And use the Then statement for validate messages:
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"
Your schema must be writen according to https://www.asyncapi.com/ specification.
Available for version schemas 1.2.0 and 2.0.0.
Available contexts
MessageValidatorOpenApiContext
Check the content of the dispatched message that matches with your asyncapi file:
Then the published message "pccomponentes.example.1.domain_event.resource.resource_created" should be valid according to swagger "docs/asyncapi.yml"
Check if message has dispatched:
Then the message "pccomponentes.example.1.domain_event.resource.resource_created" should be dispatched
Check if message has not been dispatched:
Then the message "pccomponentes.example.1.domain_event.resource.resource_created" should not be dispatched
Configuration:
- PcComponentes\OpenApiMessagingContext\Behat\MessageValidatorOpenApiContext: - '%%kernel.project_dir%%' - '@spy.message.middleware'
ResponseValidatorOpenApiContext
Check if http requests are documented in your openapi file:
Then the request should be valid according to OpenApi "docs/openapi.yml" with path "/your/openapi/path/"
Check if http responses are documented in your openapi file:
Then the response should be valid according to OpenApi "docs/openapi.yml" with path "/your/openapi/path/"
Additionally, you can check both the request and response with:
Then the request and response should be valid according to OpenApi "docs/openapi.yml" with path "/your/openapi/path/"
Configuration:
- PcComponentes\OpenApiMessagingContext\Behat\ResponseValidatorOpenApiContext: - '%%kernel.project_dir%%'
SimpleMessageContext
When step for SimpleMessage input:
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
This is useful to combine it with Then step in MessageValidatorOpenApiContext
Configuration:
- PcComponentes\OpenApiMessagingContext\Behat\SimpleMessageContext: - '@messenger.bus.command' ##Your command bus with spy.message.middleware - '@your.simple_message_deserializer.service'
TIP If you are using pccomponentes/messenger-bundle you can use @pccom.messenger_bundle.simple_message.serializer.stream_deserializer for deserializer service
AggregateMessageContext
When step for AggregateMessage input:
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
This is useful to combine it with Then step in MessageValidatorOpenApiContext
Configuration:
- PcComponentes\OpenApiMessagingContext\Behat\AggregateMessageContext: - '@messenger.bus.events' ## Your event bus with spy.message.middleware - '@your.aggregate_message_deserializer.service'
TIP If you are using pccomponentes/messenger-bundle you can use @pccom.messenger_bundle.aggregate_message.serializer.stream_deserializer for deserializer service
pccomponentes/open-api-messaging-context 适用场景与选型建议
pccomponentes/open-api-messaging-context 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 78.23k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2019 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 pccomponentes/open-api-messaging-context 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pccomponentes/open-api-messaging-context 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 78.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-04