I have a class names AbcService
<?php
namespace AppHttp;
class AbcService
{
private string $attr;
public function __construct()
{
$this->attr = 'some text';
}
public function aMethod(): bool
{
if (empty($this->attr)) {
return true;
}
return false;
}
public function bMethod()
{
return 'what';
}
}
I’ve created a facade on top of that:
<?php
namespace AppHttp;
use IlluminateSupportFacadesFacade;
class Abc extends Facade
{
protected static function getFacadeAccessor()
{
return AbcService::class;
}
}
Now calling this code from the tink
session (php artisan tink
) outputs true
, meaning that the attr
value did not change in the constructor.
use AppHttpAbc;
Abc::partialMock();
Abc::shouldReceive('bMethod')->once()->andReturn('partialMock');
print_r(Abc::aMethod());
I’ve placed a dd
in the constructor after changing the value of attr
and we know after calling the Abc::partialMock()
the constructor executed. Is this the normal behavior of the partialMock
in the Facade
? How can I only mock the bMethod
method and use other part of the class without changes?