1
아래 클래스의 메서드에 대한 테스트를 작성하려고합니다. 그러나 테스트를 실행할 때 get_b64
이 실행되지 않는다는 오류가 발생합니까? 나는 이것이 어떻게 돌아 가지 않는지 보지 못한다.테스트 메서드에서 내 메서드를 호출 할 수 없습니다.
정적 방법을 테스트하기위한 조롱 문서를 조금 보았습니다. 그러나이 오류가 그 원인이 아닌 것으로 알 수 있습니다.
테스트 전략을 변경하거나 조롱 된 객체에서 함수 호출을 모의 할 수 있어야하는 것은 무엇입니까?
등급 :
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);
}
}
의 TestCase :
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);
}