Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何断言动态输出_Regex_Dynamic_Output_Behat - Fatal编程技术网

Regex 如何断言动态输出

Regex 如何断言动态输出,regex,dynamic,output,behat,Regex,Dynamic,Output,Behat,我正在开发一个与本地支付提供商服务器交互的库 基本上,我首先希望它生成一个带有隐藏的的,没有包装标记 为此,我有一个功能文件,其中我指定了以下内容: # GeneratePaymentFormData.feature Feature: GeneratePaymentFormData In order to display a payment button with the corresponding `<form>` and `<input>`s to the use

我正在开发一个与本地支付提供商服务器交互的库

基本上,我首先希望它生成一个带有隐藏的
,没有包装
标记

为此,我有一个功能文件,其中我指定了以下内容:

# GeneratePaymentFormData.feature
Feature: GeneratePaymentFormData
  In order to display a payment button with the corresponding `<form>` and `<input>`s to the user
  As a developer
  I need to be able to supply specific input parameters to my library and have it returning a whole bunch of hidden `<input>` tags with specific values.

  Scenario: Send POST request to estcard.ee
    Given Parameter "private_key_file" is "private.key"
    And Parameter "merchant_id" is "11223344"
    And Parameter "feedback_url" is "http://localhost/myapp/callback.php"
    And Parameter "amount" is "0.19"
    And Parameter "currency" is "EUR"

    When I click on Pay
    Then the output should be
      """
      <input type="hidden" name="action" value="gaf"><br>
      <input type="hidden" name="ver" value="004"><br>
      <input type="hidden" name="id" value="11223344"><br>
      <input type="hidden" name="ecuno" value="201601149511"><br>
      <input type="hidden" name="eamount" value="000000000019"><br>
      <input type="hidden" name="cur" value="EUR"><br>
      <input type="hidden" name="datetime" value="20160107121111"><br>
      <input type="hidden" name="charEncoding" value="UTF-8"><br>
      <input type="hidden" name="feedBackUrl" value="http://localhost/myapp/callback.php"><br>
      <input type="hidden" name="delivery" value="S"><br>
      <input type="hidden" name="mac" value="a9502a893e014072788551a4d7420e9a67ed63782cc9aa7b4b0d4f7b402472dd725fe585f6ba537f3994e259c7b9070a24e1af06a1f87aab0d4f90826925599f6f74d5fb2ce8f79f881ef8face1af6d1913b7e020065a10e6195070f191b71fed49619547bf07e6fc762481e0b307eab0b4775fdb4c1af0cadf260eb6ba0df5c"><br>

      """
#GeneratePaymentFormData.feature
功能:GeneratePaymentFormData
为了向用户显示带有相应``和``的付款按钮
作为开发者
我需要能够为我的库提供特定的输入参数,并让它返回一大堆带有特定值的隐藏的``标记。
场景:向estcard.ee发送POST请求
给定参数“private\u key\u file”为“private.key”
参数“商户id”为“11223344”
参数“反馈url”为“http://localhost/myapp/callback.php"
参数“金额”为“0.19”
参数“货币”为“欧元”
当我点击支付
那么输出应该是
"""











"""
问题是库必须输出动态数据。例如,ecuno字段是根据当前日期和时间生成的,后跟一个随机数。字段mac是所有值(包括具有随机值的值)的串联字符串,用sha1散列,然后用
openssl\u sign()
签名,然后转换为十六进制


当库的某些部分每次都发生更改时,即使输入参数都相同,如何测试库的输出是否与预期一致?我想在验证输出时必须使用regex,但具体如何使用?

以及您要测试什么?你可以忽略使用随机数的值?这就是问题所在。我猜我应该忽略输出的动态部分,或者以某种方式模拟PHP的time()和random()函数,以便在测试中输出始终相同,或者首先在Behat测试中实现整个函数,然后将其复制粘贴到实际代码中。这首先看起来很可笑,但再次,当我重构或更改函数时,我可以确定它仍然会输出预期的输出…人们通常如何测试一个进行复杂计算的方法,其中涉及随机性?要进行随机测试,你需要第二个模型来测试。为输入谨慎地计算期望值的程序。如果你是以个人身份编码,那可能对你没什么帮助。对于单个编码,我建议您创建一个具有预期输入和输出的测试集。并使用该测试集的输入而不是随机数来验证代码。