1
我正试图在下面的类中编写一个方法的测试。但是,当我运行测试时,我得到的错误get_b64
永远不会运行?我不明白这是不是运行。Mockery无法在测试方法中调用我的方法
我已经看了一些关于测试静态方法的嘲讽文档,但据我所知,这个错误不是由于这个原因造成的?
我需要改变我的测试策略,或者能够模拟模拟对象中的函数调用?
类:
namespace App\Services\Steam;
use App\Services\Steam\Utils;
class Steam
{
public function profile(string $steamID)
{
$b64 = Utils::get_b64($steamID);
if ($b64 === null) {
throw new \App\Exceptions\InvalidSteamId();
}
return new Profile($b64);
}
}
测试用例:
public function test_create_user_object()
{
$id = "123"
$utilsMock = Mockery::mock(\App\Services\Steam\Utils::class);
$utilsMock->shouldReceive('get_b64')
->once()
->with($id)
->andReturn($id);
$steam = new \App\Services\Steam\Steam();
$steam->profile($id);
}