I have an object, on which at least one method is called multiple times
with different arguments in another objects method, that I want to test.
I've created the mocj in PHPUnits setUp()-method with some default
behaviour, thus (I thought) I don't need to define it in any test.
| // setUp()
| $mock = \Mockery:mock('\MyClass');
| $mock->shouldReceive('exec')->zeroOrMoreTimes()->with (
| \Mockery::type('string'),
| \Mockery::type('array')
| )->andReturn(null)->byDefault();
Now I want to test some of this calls on (let's say) "MyClass" in
separate tests each on its own, for example.
| // test
| $mock->shouldReceive('exec')->once()->with(
| ClassToTest::A_CONSTANT,
| $anArray
| )->andReturn(null);
| $testClass = new ClassToTest($mock);
| $testClass->methodToTest();
It seems, that this `shouldReceive()`-call replaces the default
bevahiour completely, even if it doesn't cover it completely, because I
get a "No Matching handler"-exception. I've tried to make the setup more
concrete (would like to avoid it)
| // setUp()
| $mock = \Mockery:mock('\MyClass');
| $mock->shouldReceive('exec')->zeroOrMoreTimes()->with (
| ClassToTest::A_CONSTANT,
| \Mockery::type('array')
| )->andReturn(null)->byDefault();
| $mock->shouldReceive('exec')->zeroOrMoreTimes()->with (
| ClassToTest::ANOTHER_CONSTANT,
| \Mockery::type('array')
| )->andReturn(null)->byDefault();
I thought at least now it would only replace the first default, but I
get the same "No matching handler"-error.
The question I have: Whats the recommended way (if even possible) to
define multiple defaults on a single method, but only replace ^some^ of
them later? Or did I just something wrong?
Thanks,
Sebastian Krebs