Score:0

Mocking the response of XmlResponse::getResultCode not working

uz flag

Following is the code that I'm using to mock the response of XmlResponse::getResultCode as Ok, but it isn't working, I'm not sure what exactly is going wrong here:

$response = $this->createPartialMock('\CommerceGuys\AuthNet\Response\XmlResponse', ['getResultCode']);
$response->expects($this->any())->method('getResultCode')->will($this->returnValue('Ok'));

$client = $this->createMock('\GuzzleHttp\Client');
$client->expects($this->any())->method('request')->withAnyParameters()->will($this->returnValue($response));
$this->container->set('http_client', $client);

$clientFactory = $this->createMock('\Drupal\Core\Http\ClientFactory');
$clientFactory->expects($this->any())->method('fromOptions')->will($this->returnValue($client));
$this->container->set('http_client_factory', $clientFactory);

I've even tried the prophesize way, but that's not working either:

$response = $this->prophesize('\CommerceGuys\AuthNet\Response\XmlResponse');
$response->getResultCode()->willReturn('Ok');

My goal is to mock the response of XmlResponse::getResultCode to return string Ok.

Trying the above approach for the D8 site with PHPUnit 7.5.20 using Kernal Testcase.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.