小编yan*_* li的帖子

如何使用 Mockery 在 Lumen 中使用模拟

如何在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)

php phpunit mockery

5
推荐指数
1
解决办法
1510
查看次数

标签 统计

mockery ×1

php ×1

phpunit ×1