So, I am trying to mock a class with AspectMock::Test
.
I'm running into the issue that the mock is passed as a parameter and when I do this, I get the following error:
Argument 1 passed to Foo::spamEggs() must be an instance of Bar,
instance of AspectMock\Proxy\ClassProxy given
The code in question
class Foo {
public function spamEggs(Bar $bar): Egg
{
return $bar->getEgg();
}
}
final class Bar {
public function getEgg(): Egg
{
...
}
}
The test
class TestFoo {
public function testSpamEggs()
{
$bar = Test::double('Bar', [
'getEgg' => new Egg('green'),
]);
$foo = new Foo();
$egg = $foo->spamEggs($bar); // throws the error
$this->assertEquals('green', $egg->colour);
}
}
Is there any way to make this works without me having to remove my parameter typing?
The reason why I moved to AspectMock instead of Stub is that my Bar
class is final
and as far as I know, Stub does not support final mocks.
The question is not how I should mock this final class, but what to do about the typed parameter.
Any tips are welcome.