我正在使用可启动模型特征来使用我的Trait为模型注册某些事件.但是,我遇到了一个试图模拟使用特征的模型的问题.具体来说,当实例化模型的Mockery版本时,它的启动代码同意它应该有bootMyTrait方法,但在尝试调用它时无法找到它.
下面的示例存储库,包含要重现的命令.
举个例子,这是一个特点:
namespace App;
trait MyTrait
{
public static function bootMyTrait()
{
print("Booting MyTrait\n");
}
}
Run Code Online (Sandbox Code Playgroud)
并使用它的模型:
namespace App;
use Illuminate\Database\Eloquent\Model;
class MyModel extends Model
{
use MyTrait;
}
Run Code Online (Sandbox Code Playgroud)
定期实例化模型工作正常.这显示了所需的输出:
$model = new MyModel();
Run Code Online (Sandbox Code Playgroud)
但是,试图模仿这个模型是不合作的.这个:
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic functional test example.
*
* @return void
*/
public function testTraitBooting()
{
$model = $this->getMock('App\MyModel');
}
}
Fails. Adding some debugging to Eloquent:
/**
* …
Run Code Online (Sandbox Code Playgroud) 标题反映了我认为正在发生的事情,但我无法证明它超出了怀疑的阴影.我已经为我们的哨兵实例添加了一些日志调用,以试图缩小正在发生的事情
背景:我们的应用程序有一个名为LoadingViewController的根VC,它有一些逻辑来确定我们是否有登录用户.如果我们这样做,它会显示主屏幕,如果我们不显示登录/注册屏幕.间歇性地,当主屏幕显示时显示登录屏幕.我们的应用程序使用JWT对我们的后端进行身份验证,但我相当自信令牌到期不是问题; 根据日志不会调用强制注销的过期令牌周围的日志记录
研究:我也审查了这些问题/问题,虽然类似,但没有解决我所看到的问题
我看到的:LoadingViewController启动.进入bootUser,没有从UserDataService返回用户,返回false,然后重置所有内容.这就是为什么我认为User对象在被查询时不存在的原因.
这通常发生在我暂时没有使用应用程序之后,而不是所有时间.我无法通过强制退出应用程序或加载一堆游戏来试图强制它内存并返回它来强制解决问题.
我有点不知所措.有什么我没有想到或可以检查?
谢谢
码
我们的LoadingViewController的子集:
class LoadingViewController: UIViewController {
override func viewDidLoad() {
breadcrumbs.append("LoadingViewController.viewDidLoad \(UserDataService.getCurrentUser()?.id) \(UserDataService.getCurrentUser()?.token)")
super.viewDidLoad()
// determine if we have a user
if self.bootUser() {
return
}
// If we got hereUser is not logged in. wipe it
NSOperationQueue().addOperationWithBlock() {
let realm = KidRealm.realm()
CacheUtils.purgeRealm(realm)
}
}
func bootUser() -> Bool {
breadcrumbs.append("LoadingViewController.bootUser 0 \(UserDataService.getCurrentUser()?.id) \(UserDataService.getCurrentUser()?.token)")
if let …
Run Code Online (Sandbox Code Playgroud) 我认为*交易刚被丢弃.这准确吗?
我正在使用mysql
例:
try {
DB::beginTransaction();
throw new Exception("something happened");
DB::commit()
} catch (Exception $e) {
Log::debug("something bad happened");
}
Run Code Online (Sandbox Code Playgroud)
谢谢