我Static method "user" cannot be invoked on mock object什至没有嘲笑auth->user。
我使用 php7、cakephp2.x 和 phpunit4+ 根据 cakephp2 文档:
https://book.cakephp.org/2.0/en/development/testing.html
If you are using PHPUnit 4 or 5, staticExpects() does not exist anymore. Instead, you should insert the necessary data into the session with CakeSession::write('Auth.User', $user) before calling the action.
我尝试使用:
$user = [
'id' => 1,
'username' => 'mark'
];
CakeSession::write('Auth.User', $user);
但是在调用时:
$user = $this->Controller->Auth->user();
我仍然收到: Static method "user" cannot be invoked on mock object错误
当然,我在这里遗漏了一些东西,但我不知道是什么。你能在这里帮我正确的方法吗?
精慕HU