2017-11-10 4 views
0

値上記の例では、指定されたパラメータで要求を作成Behatシナリオ概要フロートは、

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  | 

APIテストのため次のシナリオを検討してください。

私の問題は、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(); 
+0

送信要求ステップの実装を追加できますか? – lauda

+0

オリジナルボディに追加しました。ありがとう – Valentin

+0

うーん、私はちょっと、このメソッドを乱雑に伝えることはできません、$キーが値のときに 'floatval'の呼び出しを試みてください。 – lauda

答えて

1

一つの方法あなたが正しい型を得ることを確認するには「価値」キーのためfloatval方法を使用することです。

関連する問題