wakeonweb/behat-contexts

提供一些 behat 上下文

v1.4.0 2019-02-21 17:22 UTC

This package is auto-updated.

Last update: 2024-09-23 21:19:12 UTC


README

提供一些简单的 behat 上下文

default:
    suites:
        default:
            contexts:
                - WakeOnWeb\BehatContexts\AmqpContext:
                    transports: 
                        # I intentionally did not use syntax %env()% because BEHAT doesn't fully
                        # support this case since Behat and Symfony kernel are not the sames.
                        async_internal: "env(MESSENGER_TRANSPORT_ASYNC_INTERNAL_DSN)"
                        my_second_queue: "DIRECT_DSN"
                    # you can define your own Adapter, it musts implements \WakeOnWeb\BehatContexts\AmqpAdapter\AdapterInterface;
                    # adapterClass: \WakeOnWeb\BehatContexts\AmqpAdapter\SymfonyMessengerAdapter
                    # Create queues if they don't exist.
                    # setupQueuesAutomatically: 1
                - WakeOnWeb\BehatContexts\FidryAliceFixturesContext:
                    # optional
                    # default is %kernel.project_dir%/tests/fixtures
                    # basepath: /var/www/.... 
                - WakeOnWeb\BehatContexts\DoctrineORMSchemaReloadContext
                - WakeOnWeb\BehatContexts\HttpMockContext:
                    # basepath is %kernel.project_dir%/
                    # optional
                    # mockServers:                    
                        - {serverName: 'user', port: 8870, host: 'localhost', basePath: '/admin'}
                        - {serverName: 'mailer'}
                    # bodyRequestPath: tests/functional/fixtures/request (default)
                - WakeOnWeb\BehatContexts\SwaggerContext:
                    # basepath is %kernel.project_dir%/
                    # swaggerFile: doc/mySwaggerFile.yaml
                - WakeOnWeb\BehatContexts\FileContext:
                    # optional
                    # basePath: 'test/funtional/fixtures/file'
            paths:
                - tests/Features

AmqpContext

如果功能/场景有 @amqp 标签,它将自动删除上下文中定义的所有队列中的消息。

FidryAliceFixturesContext

需要安装 AliceDataFixtures 和其捆绑包。

DoctrineORMSchemaReloadContext

需要安装 [DoctrineBundle]。

如果功能/场景有 @database 标签,它将自动为所有管理者删除/创建 doctrine 模式。

您必须先自行创建数据库。

HttpMockContext

需要 BehatSymfony2ExtensionInternationHttpMock

配置

  • mockServers: 模拟服务器设置列表。仅名称是必填项。
  • bodyRequestPath: 目标 json 响应文件的基础路径。

用法

您有两种方式来设置模拟列表。

  1. 使用标签进行配置

    在套件配置中添加您的模拟,并在功能或场景上使用 @mockable 标签。

  2. 步骤

    使用 "我设置模拟服务器:" 步骤,并在使用后不要忘记 "我拆除模拟服务器"。

可用的步骤

Given I set up mock servers:
    | name | port | host | basePath |
Then I tear down mock servers
Given A :method request on :path to the mock server :serverName must be return a :responseCode response
Given A :method request on :path to the mock server :serverName must be return a :responseCode response with content :body
Given A :method request on :path to the mock server :serverName must be return a :responseCode response with file :bodyFileName as content   
Given A :method request on path matching :regex to the mock server :serverName must be return a :responseCode response
Given A :method request on path matching :regex to the mock server :serverName must be return a :responseCode response with content :body
Given A :method request on path matching :regex to the mock server :serverName must be return a :responseCode response with file :bodyFileName as content

SwaggerContext

需要: BehatSymfony2ExtensionUbirakRestApiBehatExtensionSwaggerValidator

如何使用

  • 在 behat.yml 文件中将您的 yaml swagger 文件路径(仅 V2)设置。
  • 在调用 UbirakRestApi 的端点后使用该步骤。

可用的步骤

Then I validate Swagger response on :path with :method method and statusCode :statusCode

FileContext

需要: BehatSymfony2Extension

如何使用

  • 设置您的 fixture 文件夹的基础路径(可选,默认:tests/functional/fixtures/file)
  • 使用步骤
  • 使用 @clean-files-after 或 @clean-files-before 标签来清理使用 "我在 :path 从 :file 创建文件" 步骤创建的文件。
  • 如果场景生成文件,您可以使用 "我清理文件夹 :folder 中的所有文件" 步骤来清理。

可用的步骤

Given I create file in :path from :file
Then The file :file must be a copy of :fileExpected
Then One of file present in :path must be a copy of :fileExpected
Then The file :file size is less or equal to :size octet
Then The file :file size is equal to :size octet
Then The file :file mime type must be equal to :mimeType
Then The file :file mime type must be equal to one of following:
Then :number files must be present in folder :path
Then The file with name :fileName must be present in :path
Then I clean all files from folder :folder
Then I clean generated files