Я новичок в 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());
}
Итак, как мне получить фиктивный http-ответ в PurchaseRequest.php?
--- ОБНОВЛЕНИЕ ---
Оказалось, что в моем PurchaseResponse.php
use Omnipay\Common\Message\RequestInterface;
//and...
public function __construct(RequestInterface $request, $data)
{
parent::__construct($request, $data);
}
скучал.
Теперь с $httpResponse = $this->httpClient->post(null)->send();
в PurchaseRequest.php утверждения в порядке, но когда я использую httpClient, 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?