dimanche 29 mai 2016

PHP Unit assert no method is called except some

Similar question to this: PHPUnit assert no method is called

How to assert that no method is called except some that I can define? The following test doesn't pass, because PHPUnit validates all expects().

//Here assert that only 'firstMethodToBeCalled' and 'secondMethodToBeCalled' are called, and no more
$mock = $this->getMockBuilder('SomeClass')->getMock();
$mock->expects($this->never())
    ->method($this->anything());
$mock->expects($this->once())
    ->method('firstMethodToBeCalled');
$mock->expects($this->once())
    ->method('secondMethodToBeCalled');

Aucun commentaire:

Enregistrer un commentaire