Error reported when using laravel for unit testing

WBOY
Release: 2023-03-02 07:52:02
Original
1228 people have browsed it

When using laravel for unit testing, the following error is reported:

<code>BadMethodCallException: Method Mockery_0_Illuminate_Auth_AuthManager::user() does not exist on this mock object
</code>
Copy after login
Copy after login

Part of the code where the error was reported is as follows:

<code>function writeLog($record = ''){
$data = array(
'uid' => Auth::user()->id,//调用这一行的时候报错
'ip' => $this->request->ip(),
'created_at' => Carbon::now()
);
OperateLog::create($data);
}
</code>
Copy after login
Copy after login

How should I deal with this?

Reply content:

When using laravel for unit testing, the following error is reported:

<code>BadMethodCallException: Method Mockery_0_Illuminate_Auth_AuthManager::user() does not exist on this mock object
</code>
Copy after login
Copy after login

Part of the code where the error was reported is as follows:

<code>function writeLog($record = ''){
$data = array(
'uid' => Auth::user()->id,//调用这一行的时候报错
'ip' => $this->request->ip(),
'created_at' => Carbon::now()
);
OperateLog::create($data);
}
</code>
Copy after login
Copy after login

How should I deal with this?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!