0

Example: I have repository A inside __construct(repo B, repo C) and I want make unit test for function inside repo A but inside it has call b->func_b1 and C->func_c1, how to make? thank you so much!

#Repo A

 public function __construct(
    CandidateStepMasterInterface $stepMasterRepo,
    CandidateProcessInterface $processRepo,
    CandidateInterface $candidateRepo
) {
    parent::__construct();
    $this->stepMasterRepo = $stepMasterRepo;
    $this->processRepo    = $processRepo;
    $this->candidateRepo  = $candidateRepo;
}

I make unit test for func here

    public function funcA($itemExample) {
    //code here
    $processes           = $this->stepMasterRepo->func_b1();
    $dataProcess         = $this->processRepo->func_c1($itemExample);
    $result = $this->candidateRepo->func_d1($itemExample);
    // code here
    return $result
}

Unit test file

protected function setUp(): void
{
    $this->stepMasterRepo = m::mock(CandidateStepMasterInterface::class)->makePartial();
    $this->processRepo = m::mock(CandidateProcessInterface::class)->makePartial();
    $this->candidateRepo = m::mock(CandidateInterface::class)->makePartial();

    $this->candidatePhaseMasterMock = m::mock(CandidatePhaseMasterRepository::class)->makePartial();

    $this->candidatePhaseMasterRepo = new CandidatePhaseMasterRepository(
        $this->stepMasterRepo,
        $this->processRepo,
        $this->candidateRepo,
    );

    parent::setUp(); // TODO: Change the autogenerated stub
}
public function test_funcA() {
    $dataExample = [];
    $result = $this->candidatePhaseMasterRepo->funcA(1);
    $this->assertEquals($dataExample, $result);
}

Run unit test::: Mockery\Exception\BadMethodCallException: Received Mockery_0_App_Repositories_SaltCrm_Interfaces_CandidateStepMasterInterface::func_b1(), but no expectations were specified

Luân Tào
  • 11
  • 3

0 Answers0