Devs.tw 是讓工程師寫筆記、網誌的平台。歡迎您隨手紀錄、寫作,方便日後搜尋!
找這 bug 找了很久 最後終於發現
因為我不只是寫 unit test,還有寫 application test
$response = $this->get('/');
$response->assertStatus(200);
這種發 request 的動作 後面對應的是
// Illuminate\Foundation\Testing\Concerns\MakesHttpRequests
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
$kernel = $this->app->make(HttpKernel::class);
$files = array_merge($files, $this->extractFilesFromDataArray($parameters));
$symfonyRequest = SymfonyRequest::create(
$this->prepareUrlForRequest($uri), $method, $parameters,
$cookies, $files, array_replace($this->serverVariables, $server), $content
);
$response = $kernel->handle(
$request = Request::createFromBase($symfonyRequest)
);
$kernel->terminate($request, $response);
return $this->createTestResponse($response);
}
因為不在測試程式的 transaction 裡面了 所以不起作用
雖然有點不懂 但需要去看 HttpKernel
以及 SymfonyRequest
的實作才可以
最後我只好這樣做