it seems this mock doesn't work and I can't understand why. To me it's due to the new class
The class I'm testing:
class someClass
{
public function run()
{
$anotherClass = new AnotherClass($params);
// more code here ...
}
}
The AnotherClass class:
class AnotherClass
{
public function __construct($params) {
// more code here, not important ...
}
public function myMethod($data): bool
{
// more code here not important ...
return $aBooleanVariable;
}
}
In my someClassTest.php
I have setup a mock for AnotherClass
like that:
$anotherClassMock = $this->getMockBuilder(AnotherClass::class)
->onlyMethods(['myMethod'])
->setConstructorArgs($params)
->getMock();
$anotherClassMock->method('myMethod')
->with($data)
->willReturn(true);
\Yii::$container->set(AnotherClass::class, $anotherClassMock);
Last line it's because I'm using Yii framework.
It seems the mock doesn't work because it will never return true. What am I doing wrong?