You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class A {
publicfunctionB()
{
$foo = $userModel->findByIdAndName(123, 'ilia');
return$foo
}
}
--------------------------
// Unit Test
public function testA()
{
$userModelMock->getMock(...);
$userModelMock->expects($this->any())->method('findByIdAndName')->with(123, 'ilia')->will($this->returnValue(true));
// some more logic
}
will pass the test.
Case #2: We have removed one argument from findByIdAndName in class A. So we have $userModel->findByIdAndName(123);
Test will failed because of too much parameters was expected, but actually got 1
Case #3: We have added one more argument to findByIdAndName in class A. So we have $userModel->findByIdAndName(123, 'ilia', 'whatdeheg');
Test will pass. So if someone will add one more parameter to a call inside a function he won't notice anything, because test will pass. But 'contract' is broken, right?
How do I make sure method is called with exact amount of arguments I expected? I want to test fail if amount of arguments more or less then expected.
The text was updated successfully, but these errors were encountered:
We don't have any built-in way for doing this at the moment, but you could use something like returnCallback() to throw an exception if the argument count is wrong.
Hi,
I have an use case:
will pass the test.
Case #2: We have removed one argument from findByIdAndName in class A. So we have $userModel->findByIdAndName(123);
Test will failed because of too much parameters was expected, but actually got 1
Case #3: We have added one more argument to findByIdAndName in class A. So we have $userModel->findByIdAndName(123, 'ilia', 'whatdeheg');
Test will pass. So if someone will add one more parameter to a call inside a function he won't notice anything, because test will pass. But 'contract' is broken, right?
How do I make sure method is called with exact amount of arguments I expected? I want to test fail if amount of arguments more or less then expected.
The text was updated successfully, but these errors were encountered: