lundi 5 octobre 2015

Phpunit check methods call order independent on other calls

I want to ensure, that in one of the mocks two methods are called in specified order: methodB() is called after methodA(). I can achieve something similar with ->at(), e.g.:

$service->expects($this->at(0))->method('activate')->with(
    $this->equalTo($activationKey)
)->willReturn(TRUE);

$service->expects($this->at(1))->method('getDetails')->with(
    $this->equalTo($activationKey)
)->willReturn($details);

But in case later in the code some call will be added before activate(), test will fail and I need to put then magic numbers into at().

In my test I don't care, what is called before, after or between these two methods. I just want to ensure, that getDetails() is called after activate().

Aucun commentaire:

Enregistrer un commentaire