考慮以下測試:Laravel 5.1不允許您在網址參數傳遞(有配置)
public function it_should_contain_a_list_of_investors_who_belong_to_one_or_more_investment() {
$this->createInvestment();
$investor = factory(User::class)->create([
'role_id' => 4
]);
$response = $this->actingAs($investor)
->call('GET', 'api/v1/investors?include=investments');
dd(json_decode($response->getContent()));
$this->assertNotEmpty(json_decode($response->getContent()));
}
現在考慮下面的動作本次測試致電:
public function getAllInvestorsForCompany($slug)
{
$users = $this->investorEntity->usersForCompany($slug);
$resource = new Collection($users, new InvestorTransformer, 'investor');
dd($_GET);
if (isset($_GET['include'])) {
$usersData = $this->manager->parseIncludes($_GET['include'])->createData($resource)->toArray();
} else {
$usersData = $this->manager->createData($resource)->toArray();
}
return response()->json($usersData);
}
注dd
,$_GET
返回[]
讓我們在瀏覽器中做相同的測試:
array:1 [▼
"include" => "investments.offering.company"
]
好了,所以在瀏覽器中我回去investments.offering.company,因爲這是我傳遞的?include=
但在測試中它像laravel忽略?包括和移動上。
這是laravel 5.1測試的默認行爲,如果是這樣,我該如何關閉它?
'$ _GET'在控制檯請求期間不會被填充,因爲您的控制檯應用程序實際上沒有_make_請求。它改爲通過應用程序運行請求的操作 –