XmlRPC-Api の低レベルの実装を作成しましたが、通信をテストするのに苦労しました。
これが私のコードです。
abstract class BaseClient
{
protected function call($method, array $params = array())
{
$request = xmlrpc_encode_request($method, $parameters);
$file = file_get_contents($this->getDSN(), false, $context);
$response = xmlrpc_decode($file);
if ($response && xmlrpc_is_fault(array($response))) {
trigger_error("xmlrpc: {$response[faultString]} ({$response[faultCode]})");
}
return $response;
}
}
Client extends BaseClient
{
public function testCall($msg)
{
return $this->call('testMethid', array($msg));
}
}
そして、これが私のテストです。
ClientTest extends PHPUnit_FrameWork_TestCase
{
public function testTestCall()
{
$c = new Client();
$resp = $c->testCall('Hello World');
$this->assertEquals('Hello World', $resp);
}
}
テスト環境内で API にアクセスできないため、このテストは毎回クラッシュします。関数をモックして注入する解決策がわかりませんcall
。私に何ができる?私のオブジェクト構造が悪くてテストできないのかもしれませんが、どうすればこの構造を改善できますか (これが起こった場合)?
乾杯。