【发布时间】:2015-10-01 21:05:05
【问题描述】:
考虑以下测试:
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 一样忽略了 ?include 并继续前进。
这是 laravel 5.1 测试的默认行为吗?如果是,我该如何关闭它?
【问题讨论】:
-
$_GET在控制台请求期间不会被填充,因为您的控制台应用程序实际上并没有发出请求。而是通过应用程序运行请求的操作
标签: php unit-testing laravel testing laravel-5.1