phpunit×嘲弄|添加@runinseparateProcess @preserveglobalstate禁用,但类已经存在错误仍未解决
我想模拟静态方法。
这是要测试的方法。
Use App\Model\MyModel
class User extends Model
{
public static function search($id)
{
try {
User::toDo($id);
} catch (\Exception $e) {
MyModel::staticMethod('test', ['foo' => 'bar']);
}
}
我想模拟myModel并测试一次staticmethod()一次。 所以我嘲笑了以下内容。
public function search_test($id)
{
$mock = \Mockery::mock('overload:'. \App\Model\MyModel::class);
$mock->shouldReceive('staticMethod')->once();
User::search($id);
}
The result was
Mockery\Exception\RuntimeException: Could not load mock App\Model\MyModel , class already exists
So I added
* @runInSeparateProcess
* @preserveGlobalState disabled
, but still the class already exists error is not resolved. 在UserModel中没有位置新的MyModel,但是我应该在哪里检查?
先感谢您。
I would like to mock static method.
Here is the method to be tested.
Use App\Model\MyModel
class User extends Model
{
public static function search($id)
{
try {
User::toDo($id);
} catch (\Exception $e) {
MyModel::staticMethod('test', ['foo' => 'bar']);
}
}
I would like to mock MyModel and test that staticMethod() is called once.
So I mocked the following.
public function search_test($id)
{
$mock = \Mockery::mock('overload:'. \App\Model\MyModel::class);
$mock->shouldReceive('staticMethod')->once();
User::search($id);
}
The result was
Mockery\Exception\RuntimeException: Could not load mock App\Model\MyModel , class already exists
So I added
* @runInSeparateProcess
* @preserveGlobalState disabled
, but still the class already exists error is not resolved.
There is no place in the UserModel where the new MyModel, but where should I check?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论