Aren't mocks supposed to replace methods and their parameters?
I don't understand how this works, I copy-paste examples but i run into trouble on every single example that should work out of the box..
The problem i run into is that the methods do not have their parameters removed, so if a method has a certain dependency as a parameter, i HAVE to pass it to the mock's method too..
The manual even says that by default all methods are replaced by empty methods that return null.
I'm using 5.7(php 5.6)
class SomeClass
{
public function doSomething(\Exception $e)
{
// Do something.
}
}
class StubTest extends TestCase
{
public function manualExampleDoesntWork()
{
// Create a stub for the SomeClass class.
$stub = $this->createMock(SomeClass::class);
// Configure the stub.
$stub->method('doSomething')
->willReturn('foo');
// Calling $stub->doSomething() will now return
// 'foo'.
$this->assertEquals('foo', $stub->doSomething());
}
public function ...
{
// Should be enough, doesnt work
$stub = $this->createMock(SomeClass::class);
$stub->doSomething(); // error
// Neither
$stub = $this->createMock(SomeClass::class);
$stub->method('doSomething')
->withAnyParameters()
->willReturn('foo');
$stub->doSomething(); // error
// Same for manually building with the mockbuilder..
}
}
Results in: Argument 1 passed to Mock_***95::doSomething() must be an instance of Exception, none given
This is just one example, I've tried every possible variation of creating mocks, all results in me not being able to replace the parameters..