Hi,
I have some trouble accessing an eloquent model property when the model is mocked for unit testing. In my controller I do this:
$this->user = $this->user->create($input);
if ($this->user->isSaved())
{
$activation_key = $this->user->activation_key;
// more code here
While running the tests I get the following error:
1) UsersTest::testStoreSuccess
ErrorException: Undefined property: Mockery_1::$activation_key
[PATH]\app\controllers\UsersController.php:60
Line 60 is the exact line where I try to get the $this->user->activation_key property from the new created model instance.
The mocking happens here:
$this->mock->shouldReceive('create')
->once()
->andReturn(Mockery::mock(array('isSaved' => true)));
$this->app->instance('User', $this->mock);
If you need further information, let me know. Thanks in advance!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community