Behat 场景大纲浮点值

Behat Scenario Outline Float values

考虑以下场景进行 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       |

上面的例子创建了一个带有指定参数的请求。

我的问题是,当整数 (15) 值相应地传递给函数时,浮点数 (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();

解决此问题的一种方法是对 'value' 密钥使用 floatval 方法,以确保您获得正确的类型。