gpt4 book ai didi

laravel - 如何为 Laravel Facade 指定部分模型?

转载 作者:行者123 更新时间:2023-12-05 01:05:41 24 4
gpt4 key购买 nike

首先我试过这个

$mock = m::mock('Cartalyst\Sentry\Facades\Laravel\Sentry');
$mock->shouldReceive('getUser')->once()->andReturn($userInst);

但它给了我
Fatal error: Cannot redeclare Mockery_1964315998_Cartalyst_Sentry_Facades_Laravel_Sentry::shouldReceive()

然后我发现 Laravel Facades 已经实现了 Mockery,所以我直接在 Facade 上尝试。
Sentry::shouldReceive('getUser')->once()->andReturn($userInst);

但现在的问题是它没有找到该对象的其他函数,本质上我需要一个部分模型的行为,但我不知道如何告诉它。
BadMethodCallException: Method Mockery_2115409749_Cartalyst_Sentry_Sentry::check() does not exist on this mock object

这就是我需要的
A traditional partial mock defined ahead of time which methods of a class are to be mocked and which are to left unmocked (i.e. callable as normal). The syntax for creating traditional mocks is:

$mock = \Mockery::mock('MyClass[foo,bar]');
In the above example, the foo() and bar() methods of MyClass will be mocked but no other MyClass methods are touched. You will need to define expectations for the foo() and bar() methods to dictate their mocked behaviour.

最佳答案

你可以尝试添加

Sentry::getFacadeRoot()->makePartial();


Sentry::shouldReceive('getUser')
->once()
->andReturn($userInst);

关于laravel - 如何为 Laravel Facade 指定部分模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21107231/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com