如何在lumen框架中使用mock?我使用流明框架。Lumen的文档非常简单。我不知道如何使用嘲笑或外观来嘲笑模型。我尝试了一些方法,但没有人奏效。我想在updatePassword方法中模拟UserModel的两点。请帮我。
用户模型
use Illuminate\Database\Eloquent\Model;
class UserModel extends Model {
// connection
protected $connection = 'db_user';
// table
protected $table = 'user';
// primarykey
protected $primaryKey = 'id';
}
Run Code Online (Sandbox Code Playgroud)
用户逻辑
class UserLogic {
public static updatePassword($id, $password) {
// find user
$user = UserModel::find($id); // mock here**************************************
if (empty($user)) {
return 'not find user';
}
// update password
$res = UserModel::where('id', $id)
->update(['password' => $password]); // mock here*****************************
if (false == $res) {
return 'update failed';
}
// …Run Code Online (Sandbox Code Playgroud)