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.

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

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号