Behat Scenario Outline Float值

时间:2017-11-10 17:09:31

标签: php automation behat

考虑以下API测试场景

Given I am using the API Service
When  I send the <request> as <method> to <endpoint> endpoint with <key> having value <value>
Then  The response status code is 200

Examples:
  | request    | method | endpoint       | key            | value          |
  | "All Keys" | "POST" | "endpointName" | "numericField" | 15             |
  | "All Keys" | "POST" | "endpointName" | "numericField" | 15.12345       |

上面的示例使用指定的参数创建请求。

我的问题是,当integer(15)值相应地传递给函数时,float(15.12345)被转换为字符串(“15.12345”)。当函数被调用时,这会直接发生;在以后的步骤中不会对其进行修改。

有没有办法让浮点值不变成字符串?

根据要求,发送请求步骤方法是:

    $data = $this->fulfilmentOptions->getDataValue($request);
    $uri = $this->getMinkParameter('base_url') . $this->setEndpoint($endpoint);

    array_walk_recursive($data, function(&$item, $originalKey) use ($key, $value) {
        if ($originalKey === $key) {
            $item = $value;
        }
    });

    try {
        $this->response = $this->client->request($method, $uri, [
            'headers' => $this->fulfilmentOptions->getDataValue('CreateOrder API Headers'),
            'body' => json_encode($data)
        ]);
    } catch (\GuzzleHttp\Exception\RequestException $e) {
        $this->response = $e->getResponse();
    }

    $this->responseContent = $this->response->getBody()->getContents();

1 个答案:

答案 0 :(得分:1)

解决问题的一种方法是使用floatval方法来识别价值&#39;确保您获得正确类型的关键。