Mocking Laravel Eloquent models - how to set a public property with Mockery
问题 I want to use a mock object (Mockery) in my PHPUnit test. The mock object needs to have both some public methods and some public properties set. The class is a Laravel Eloquent model. I tried this: $mock = Mockery::mock('User'); $mock->shouldReceive('hasRole')->once()->andReturn(true); //works fine $mock->roles = 2; //how to do this? currently returns an error $this->assertTrue(someTest($mock)); ... but setting the public property returns this error: BadMethodCallException: Method Mockery_0