0

私はOmniPayを初めて使用し、それをいじって簡単なカスタムゲートウェイを作成し、モック json http 応答を使用して単体テストを作成しようとしています。

GatewayTest.php で、モックの http 応答を設定します。

public function testPurchaseSuccess()
{
    $this->setMockHttpResponse('TransactionSuccess.txt');

    $response = $this->gateway->purchase($this->options)->send();

    echo $response->isSuccessful();

    $this->assertEquals(true, $response->isSuccessful());
}

PurchaseRequest.php で、私は何とかそれを取得しようとしています:

public function sendData($data)
{
    $httpResponse = //how do I get the mock http response set before?

    return $this->response = new PurchaseResponse($this, $httpResponse->json());
}

では、PurchaseRequest.php でモックの http 応答を取得するにはどうすればよいでしょうか?

- - アップデート - -

私の PurchaseResponse.php でそれが判明しました

use Omnipay\Common\Message\RequestInterface;

//and...

public function __construct(RequestInterface $request, $data)
{
    parent::__construct($request, $data);
}

行方不明でした。

PurchaseRequest.php ではアサーションは問題ありませんが、 httpClient$httpResponse = $this->httpClient->post(null)->send();を使用すると、Guzzle が 404 エラーをスローします。Guzzle のドキュメントを確認し、模擬応答を作成しようとしましたが、再びアサーションが失敗し、404 が残ります。

PurchaseRequest.php

public function sendData($data)
{
    $plugin = new Guzzle\Plugin\Mock\MockPlugin();
    $plugin->addResponse(new Guzzle\Http\Message\Response(200));

    $this->httpClient->addSubscriber($plugin);

    $httpResponse = $this->httpClient->post(null)->send(); 

    return $this->response = new PurchaseResponse($this, $httpResponse->json());

}

404 を取り除く方法について何か提案はありますか?

4

1 に答える 1