donglinxia1541 2017-11-10 17:09 采纳率: 0%
浏览 52
已采纳

Behat Scenario Outline Float值

Consider the following scenario for API testing

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       |

The above example creates a request with the specified parameters.

My problem is that while the integer (15) value is passed to the function accordingly, the float (15.12345) is converted into a string ("15.12345"). This happens straight as the function is called; it is not modified later on during another step.

Is there a way to keep the float value from turning into a string?

As requested, the send request step method is:

    $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条回答 默认 最新

  • dongou4052 2017-11-16 08:47
    关注

    One way of fixing the issue is to use floatval method for 'value' key to make sure you get the right type.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?