I am mocking this sample class with fluent methods that doesn't have return type declaration:
<?php
class Foo
{
private string $x;
private string $y;
public function setX(string $x)
{
$this->x = $x;
return $this;
}
public function setY(string $y)
{
$this->y = $y;
return $this;
}
}
Using PhpUnit:
$mock = $this->getMockBuilder(Foo::class)
->getMock();
By default, this will not work on fluent methods without return type declaration so I need to add the ff.:
$mock->method('setX')->will($this->returnSelf());
$mock->method('setY')->will($this->returnSelf());
This works but cumbersome to write if there are a lot fluent methods. My question is, is there a way to set this for the entire class instead of per method?