我的问题是如何发送参数到我的端点。
测试public function test_upgrade()
{
$billingChange3 = factory(Plan::class)->create([
'user_id' => 1,
'previous_price' => 150,
'current_price' => 100,
]);
$url = route(
'users.filters'
);
$response = $this->actingAs($this->admin)->getJson($url,['search'=>'upgrade']);
$response->assertStatus(200);
//till here correct
//but here it should return 2 since I have upgrade count 2 as correct it gives error
my api response is wrapped within data, so i have used data below
$response->assertJsonCount(2,'data');
}
我的搜索关键字可以是任何东西,如升级,降级etc. upgrade is when
current_price>previous_price ' ' ',我在控制器
中有逻辑我的vue开发工具显示url如下:第一:"https://localhost:800/users/plan?filter=upgrade&page=1"
在测试中,我将参数传递为getJson($url,['search'=>'upgrade'])这是传递参数的正确方法吗?
不正确。参见函数签名-你传递头:
public function getJson($uri, array $headers = [])
{
return $this->json('GET', $uri, [], $headers);
}
正确的方法:
$response = $this
->actingAs($this->admin)
->getJson(route('users.filters', ['search'=>'upgrade']));