mercredi 6 mai 2015

Mockery mock method inside loop in laravel 4

I am new in unit testing and decide to give it a try. I have problem mocking method inside foreach, example :

$expiredUsers = $this->user->expired(); // eloquent scopes which bunch wheres
foreach ($expiredUsers->get() as $user) {
   $this->reminder->expiredUser($user);
}

how can I mock method expiredUser() from $this->reminder which injected from another class?

example from my test file :

public function userMock()
{
    return Mockery::mock('Acme\Repositories\User');
}
public function reminderMock()
{
    return Mockery::mock('Acme\Repositories\Reminder');
}
public function testExpiredUserReminder()
{
    $this->collection = Mockery::mock('Illuminate\Database\Eloquent\Collection')->shouldDeferMissing();
    $userMock = $this->userMock();
    $userMock->shouldReceive('expired->get')->andReturn($this->collection);
    // code below seems ignored
    $reminderMock = $this->reminderMock();
    $reminderMock->shouldReceive('expiredUser')->with($userMock);
}

Aucun commentaire:

Enregistrer un commentaire