PHPUnit × Mockery | add @runInSeparateProcess @preserveGlobalState disabled , but the class already exists error is still not resolved

Viewed 117

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.

0 Answers
Related