Laravel 收银台虚假用户订阅测试
Laravel Cashier fake user subscription for tests
我正在使用 Laravel 的收银台进行结算,这很棒。我正在努力做好并保持我的代码经过测试,但我遇到了问题 "faking" 订阅用户。
我试过:
$user = App\Models\User::create([
'first_name' => $this->faker->firstName,
'last_name' => $this->faker->lastName,
'email' => $this->faker->email,
'password' => 'password1234',
'stripe_plan' => 'name_of_plan',
'stripe_active' => 1
]);
$this->be($user);
但是如果我检查 $user->onPlan('name_of_plan')
我会得到 false
:(
有办法吗?我相信你会明白我真的不想启动支付系统,直到我有测试来支持它!
检查 'stripe_plan' 和 'stripe_active' 是否定义为用户可填写。如果不是,那么它可能实际上没有在 User::create() 中设置这些值,这就是您的测试失败的原因。
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, BillableContract {
use Authenticatable, CanResetPassword, Billable;
protected $table = 'users';
protected $fillable = [
'first_name',
'last_name',
'email',
'password',
'stripe_plan',
'stripe_active'
];
}
我正在使用 Laravel 的收银台进行结算,这很棒。我正在努力做好并保持我的代码经过测试,但我遇到了问题 "faking" 订阅用户。
我试过:
$user = App\Models\User::create([
'first_name' => $this->faker->firstName,
'last_name' => $this->faker->lastName,
'email' => $this->faker->email,
'password' => 'password1234',
'stripe_plan' => 'name_of_plan',
'stripe_active' => 1
]);
$this->be($user);
但是如果我检查 $user->onPlan('name_of_plan')
我会得到 false
:(
有办法吗?我相信你会明白我真的不想启动支付系统,直到我有测试来支持它!
检查 'stripe_plan' 和 'stripe_active' 是否定义为用户可填写。如果不是,那么它可能实际上没有在 User::create() 中设置这些值,这就是您的测试失败的原因。
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, BillableContract {
use Authenticatable, CanResetPassword, Billable;
protected $table = 'users';
protected $fillable = [
'first_name',
'last_name',
'email',
'password',
'stripe_plan',
'stripe_active'
];
}