0
私は自分のプロジェクトでPOSTメソッドをテストしており、多次元配列をパラメータとして呼び出します。これをLaravelのpost()
メソッドに渡すにはどうすればよいですか?私はまたpostJson()
メソッドを試しています。LaravelでPOST呼び出しをテストする際に多次元配列を渡す方法は?
public function testExcludeFilter()
{
$json = '
{
"northLatitude":45.123456,
"southLatitude":45.123456,
"eastLongitude":9.1234567,
"westLongitude":9.1234567,
"filters": {
"excludes": [
1
]
}
}
';
$response = $this->postJson('api/v1/getHotels', $json)
->dontSeeJson([
'id' => 1,
'name' => 'Hotel-1',
'latitude' => 45.123456,
'longitude' => 9.1234567
]);
$response->assertResponseStatus(200);
}
エラーを受信:私がテストしてるマルチアレイは、フィルタ[「除外」]である私も配列として私のデータを渡そうとしました
ErrorException: Argument 2 passed to Illuminate\Foundation\Testing\TestCase::postJson() must be of the type array, string given
が、それはしませんでした除外フィルターに注意を払う:
postJson('api/v1/getHotels', ['northLatitude' => '45.123456', 'southLatitude' => '45.123456', 'westLongitude' => '9.1234567', 'eastLongitude' => '9.1234567', 'filters["excludes"]' => [1]]
'$ response = $ this-> postJson( 'api/v1/getHotels'、json_decode($ json、true))'これはjsonを配列に変換します –
ありがとう、これは答えです – f7n
@MASIDDIQUI答えにコメントを付けて、質問に回答としてマークすることができます –