ec-europa/oe-poetry-behat

Poetry 客户端 Behat 扩展。

0.3.4 2022-01-28 12:48 UTC

README

Build Status Packagist

欧洲委员会 Poetry 客户端 的 Behat 扩展。

使用 Docker Compose 安装

需求

docker-compose.yml.dist 复制到 docker-compose.yml

您可以根据本地的 Docker 配置进行任何必要的修改。但是,默认设置应该足以设置项目。注意,docker-compose.yml.dist 中有针对 mac 的特定设置。

运行

$ docker-compose up -d
$ docker-compose exec web composer install

设置

加载 Poetry 上下文并按以下方式配置扩展

default:
  suites:
    default:
      contexts:
        - 'EC\Behat\PoetryExtension\Context\PoetryContext'
  extensions:
    EC\Behat\PoetryExtension:
      application:
        base_url: 'http://local.dev'  # Required: application base URL running Poetry Client library.
        endpoint: '/my-endpoint'      # Required: notification endpoint on your application.

以下详细的配置允许您进一步调整扩展的行为

default:
  suites:
    default:
      contexts:
        - 'EC\Behat\PoetryExtension\Context\PoetryContext'
  extensions:
    EC\Behat\PoetryExtension:
      application:
        base_url: 'http://local.dev'  # Required: application base URL running the Poetry Client library.
        endpoint: '/my-endpoint'      # Required: notification endpoint for your application.
      service:
        host: 'localhost'             # Optional: host where mock Poetry service will be running, defaults to `localhost`.
        port: '28080'                 # Optional: mock Poetry service port, defaults to `28080`.
        endpoint: '/service'          # Optional: mock Poetry service endpoint, defaults to `/service`.
        wsdl: '/wsdl'                 # Optional: mock Poetry service WSDL endpoint, defaults to `/wsdl`.
        username: 'username'          # Optional: username used by the mock service to authenticate on your application, defaults to `username`.
        password: 'password'          # Optional: password used by the mock service to authenticate on your application, defaults to `password`.

服务参数也可以在 Behat 场景中进行覆盖(见下文)。

用法

希望使用扩展步骤的所有场景和/或功能都需要使用 @poetry 标记。

要使用重新定义的设置实例化测试 Poetry 客户端,请使用

Given the Poetry client uses the following settings:
"""
  identifier.code: STSI
  identifier.year: 2017
  identifier.number: 40017
  identifier.version: 0
  identifier.part: 11
  client.wsdl: http://my-client.eu/wsdl
  notification.username: foo
  notification.password: bar
"""

要向客户端端点发送原始 XML 通知消息,请使用

When Poetry notifies the client with the following XML:
"""
<?xml version="1.0" encoding="UTF-8"?>
...
"""

或者,如果您想以 withArray() 格式表达消息,请使用

When Poetry notifies the client with the following "notification.translation_received" message:
"""
identifier:
  code: "WEB"
  year: "2017"
  number: "40012"
  ...
"""

要为 Poetry 服务器设置测试响应,请使用

Given Poetry will return the following XML response:
"""
<?xml version="1.0" encoding="utf-8"?><POETRY xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://intragate.ec.europa.eu/DGT/poetry_services/poetry.xsd">
    <request communication="synchrone" id="WEB/2017/40029/0/0/TRA" type="status">
        <demandeId>
            <codeDemandeur>WEB</codeDemandeur>
            <annee>2017</annee>
            ...
"""

或者,如果您想以 withArray() 格式表达消息,请使用

Given Poetry will return the following "response.status" message response:
"""
identifier:
  code: WEB
  year: 2017
  number: 40029
  version: 0
  ...
"""

可以使用以下步骤断言客户端响应

Then client response contains the following text:
  | <codeDemandeur>WEB</codeDemandeur> |
  | <annee>2017</annee>                |
  | <statusMessage>OK</statusMessage>  |

或者,如果您想断言 XML 部分,请使用

And Poetry service received request should contain the following XML portion:
"""
<documentSource format="HTML" legiswrite="No">
    <documentSourceName>content.html</documentSourceName>
    <documentSourceFile>BASE64ENCODEDFILECONTENT</documentSourceFile>
    <documentSourceLang lgCode="EN">
        <documentSourceLangPages>1</documentSourceLangPages>
    </documentSourceLang>
</documentSource>
"""

可以使用以下步骤覆盖应用程序参数

When Poetry service uses the following settings:
"""
  username: foo
  password: bar
"""

有关更详细的示例,请参阅 Poetry Behat 扩展的 测试功能,注意以 Given the test application... 开头的步骤仅用于测试扩展本身,因此不可用扩展用户。

令牌替换

Behat 扩展设置和当前 Poetry 客户端设置都可以在 Behat 步骤中用作替换令牌。以下令牌将被自动替换

  • 以点符号表示的 Behat 扩展设置,前缀为 !,如 !service.host!service.port
  • 以点符号表示的 Poetry 客户端字符串设置,前缀为 !poetry.,如 !poetry.client.wsdl

可以使用以下方式使用令牌替换

And Poetry service received request should contain the following XML portion:
"""
<retour type="webService" action="UPDATE">
   <retourUser>foo</retourUser>
   <retourPassword>bar</retourPassword>
   <retourAddress>!poetry.client.wsdl</retourAddress>
   <retourPath>handle</retourPath>
</retour>
"""