Warm tip: This article is reproduced from serverfault.com, please click

PHPUnit: How to test a class method that uses another static classes method

发布于 2020-11-30 14:06:52

I have a class method I am trying to write a unit test for, it starts off something like this:

public function determineStatusActivity($proposal, $decisionStatusId): ?array
    {
        if (isset($proposal->contact_org_id)) {
            $this->personId = PipedriveActivityHelper::getPersonId($proposal->contact_org_id);
        }

I then have my test method which will need the response to run the check:

public function acceptedActivityTest()
{
    $activity = new CreateActivityInPipedriveForProposalStatusChange();
    $response = $activity->determineStatusActivity($this->proposal, 1);

    //Compare the response to a defined stub..
}

This class method determineStatusActivity() receives two pieces of data that I can create mocks for a pass to it, however I am at a loss at what to do when it gets to the static PipedriveActivityHelper class, is there a way to define the static class' behaviour in the test file method?

Questioner
JanPropelforwards
Viewed
0
CacheMoneyPlaya 2020-12-01 00:47:40

I believe this is what you are looking for, notice the test class decorators. TDD is always the best approach.