问题描述
我,我想介绍一种通过API获得身份验证的方法。
这是我的课程:
class MyService
{
private $api_token;
private $uri_api;
public function __construct(string $api_token,string $uri_api){
$this->api_token = $api_token;
$this->uri_api = $uri_api;
}
public function api_authentication(){
$client = HttpClient::create();
return $client->request('GET',$this->getUri_api().'salespoints/',[
'auth_bearer' => $this->getApi_token()
]);
}
}
这是我的测试课:
class MyServiceTest extends WebTestCase
{
public function test_api_authentication(){
$client = new HttpClient();
$stub = $this->getMockBuilder(myService::class)
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
->disallowMockingUnknownTypes()
->getMock();
$stub->method('api_authentication')->willReturn($client);
$this->assertSame($client,$stub->api_authentication());
}
}
我正在使用PHPUnit here的文档(示例8.4)。
问题是我运行phpunit时我的测试通过了,但是sonarQube告诉我这不是测试范围。我是phpunit的新手,所以如果您有任何建议。
谢谢您的帮助!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)