Home  >  Article  >  Backend Development  >  Error reported when using laravel for unit testing

Error reported when using laravel for unit testing

WBOY
WBOYOriginal
2016-12-01 00:56:571218browse

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>

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>

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>

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>

How should I deal with this?

Statement:
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