Вызов методов класса serviuce из того же класса с издевкой

#laravel #mockery

Вопрос:

Я пытаюсь понять, как я могу имитировать вызов метода employOrUpdateEmployment в своем классе обслуживания. Я не хочу, чтобы он запускал метод, но просто проверьте, что он был вызван. В настоящее время я создал экземпляр класса службы и протестировал все остальное, я просто хочу убедиться, что в ходе теста, когда он выполнит проверку, чтобы увидеть, что установлен параметр started_at, он должен вызывать метод employOrUpdateEmployment. Причина, по которой я не хочу, чтобы он запускался, заключается в том, что я хочу отдельно протестировать фактический метод employorupdatemployment.

 public function it_can_update_a_manager()
{
    $data = [
        'first_name' => 'Joe',
        'last_name' => 'Smith',
    ];
    $manager = Manager::factory()->make();
    $repositoryMock = $this->mock(ManagerRepository::class);
    $service = new ManagerService($repositoryMock);

    $repositoryMock->expects()->update($manager, $data)->once()->andReturns($manager);
    

    $service->update($manager, $data);
}
 

Служба менеджеров

 public function update(Manager $manager, array $data)
{
    $this->managerRepository->update($manager, $data);

    if (isset($data['started_at'])) {
        $this->employOrUpdateEmployment($manager, $data['started_at']);
    }

    return $manager;
}

public function employOrUpdateEmployment(Manager $manager, $employmentDate)
{
    if ($manager->isNotInEmployment()) {
        return app()->make(ManagerEmploymentStrategy::class)->setEmployable($manager)->employ($employmentDate);
    }

    if ($manager->hasFutureEmployment() amp;amp; ! $manager->employedOn($employmentDate)) {
        return $this->managerRepository->updateEmployment($manager, $employmentDate);
    }
}