1
我正在使用CakePHP的測試框架來測試我的控制器。我有一個註銷功能,會在用戶使用該網站時創建各種Cookie。我正在嘗試讀取所述cookie以確定測試是否應該通過,即測試cookie是否正確過期。我確定cookie組件已正確實例化,但我無法從應該在那裏的cookie讀取任何值。這是構成我運行測試代碼:無法從Cakephp讀取cookie數據phpunit test
public function testLogout() {
// setup the cookie component
$collection = new ComponentCollection();
$this->Cookie = new CookieComponent($collection);
$result = $this->testAction('/users/logout');
$cookie_name = Configure::read('tech_cookie_name');
$cookie_data = $this->Cookie->read($cookie_name);
debug($cookie_name);
// cookie data is returning as NULL but I'm expecting some type of value.
debug($cookie_data);
debug($result);
exit;
}
我認識到,退出是早期查殺測試,但我用它來看看是否有什麼是發送從cookie回來。我不確定爲什麼我不能從我知道的cookie中讀取任何數據。有誰知道爲什麼會這樣,或者有一個解決方案,以便在單元測試中如何正確讀取cookie。