0

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');
1
  • I've deleted my answer since neither of them worked, sorry about that. Commented May 29, 2016 at 11:31

1 Answer 1

1

Try to use this:

$mock = $this->getMockBuilder('SomeClass')->getMock();

$mock->expects($this->once())
    ->method('firstMethodToBeCalled');
$mock->expects($this->once())
    ->method('secondMethodToBeCalled');
$mock->expects($this->never())
    ->method(
        $this->logicalAnd(
            $this->logicalNot($this->equalTo('firstMethodToBeCalled')),
            $this->logicalNot($this->equalTo('secondMethodToBeCalled')),
        )
    );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.