1つのプロジェクトでは、クラスのモックを作成する必要があり、コード内でこのモックを使用して動作をシミュレートする必要があります。 は私のテストクラスでは、私はこのコードを置く:他のクラスで非テストクラスでモックPHPUnitを使用
public function testExportCsv()
{
$mockObject = $this->getMockBuilder('\Client')
->setConstructorArgs(array("0"))
->getMock();
$res = $this->searchDocApiDocumentsStub();
$mockObject->method('searchDocuments')
->willReturn($res);
}
public function searchDocApiDocumentsStub()
{
$res = array();
$yml = Yaml::parse(file_get_contents("../src/ExportCSVBundle/Resources/config/generic.yml"));
$typeDoc = "FAC";
$metas[$typeDoc] = $yml["ETT"][strtoupper($typeDoc)];
foreach ($this->documents as $document) {
if ($document["type"] == "DocumentsAPI\\Model\\" . str_replace('$eq ', '', $typeDoc)) {
foreach ($metas[$typeDoc] as $field) {
$docres[] = $document["metas"][$field];
}
$res = array_merge($res, $docres);
}
}
return $res;
}
「エクスポート」を、私はこのクラスは「クライアント」のオブジェクト、クラスIモックを持っている属性に、私はモッククラスを使用する必要があります。 次に、このオブジェクトを使用する必要があります。
この "searchDocuments"を私が作成したスタブにします。
$export = new \ExportLibraryBundle\ExportLibrary\Export(//What Do I put ??);
明確であるかどうかはわかりませんが、ご協力いただきありがとうございます。
しかし、私のmockObjectは、私は私のクラス「エクスポート」で、それを注入しないか、テストクラスにいるのですか? –