jeudi 13 juillet 2017

How to Unit Test an if Statement in PHP

I am currently attempting to unit test a get method with an if statement inside. I am not sure how to go about testing this method and I am not finding much information that is helpful.

/**
 * @var Info
 */
private $info = null;

# Not pertinent information skipped

public function getInfo()
{
    if(!$this->Info) {
        $this->Info = InfoFacade::getInfoByToken($this->getToken());
    }

    return $this->Info;
}

Then in the class InfoFacade there is a function that grabs a set of information and returns itself.

My understanding is that I need to use the shouldreceive and shouldnotreceive, but I am not sure if I should use a dataProvider and if so how to properly apply it to this situation.

My question is how do I test for an if statement like this, and if a dataProvider is the best way like I am led to believe, how do I properly set up the dataProvider?

Aucun commentaire:

Enregistrer un commentaire