12 use Magento\Framework\HTTP\ZendClientFactory;
14 use \PHPUnit_Framework_MockObject_MockObject as MockObject;
21 private static $dummy =
'dummy';
26 private $objectManager;
36 private $clientFactory;
57 $this->config = $this->getMockBuilder(Config::class)
58 ->disableOriginalConstructor()
61 $this->client = $this->getMockBuilder(ZendClient::class)
62 ->disableOriginalConstructor()
63 ->setMethods([
'setHeaders',
'setMethod',
'setUri',
'setRawData'])
66 $this->clientFactory = $this->getMockBuilder(ZendClientFactory::class)
67 ->disableOriginalConstructor()
68 ->setMethods([
'create'])
71 $this->clientFactory->expects($this->once())
73 ->willReturn($this->client);
75 $this->dataEncoder = $this->getMockBuilder(EncoderInterface::class)
76 ->disableOriginalConstructor()
79 $this->httpClient = $this->objectManager->getObject(HttpClientFactory::class, [
80 'config' => $this->config,
81 'clientFactory' => $this->clientFactory,
82 'dataEncoder' => $this->dataEncoder
88 $this->config->expects($this->once())
90 ->willReturn(
'testKey');
92 $this->config->expects($this->once())
94 ->willReturn(
'testUrl');
96 $client = $this->httpClient->create(
'url',
'method');
98 $this->assertInstanceOf(ZendClient::class, $client);
103 $param = [
'id' => 1];
107 $this->config->expects($this->once())
108 ->method(
'getApiKey')
110 ->willReturn(
'testKey');
112 $this->config->expects($this->once())
113 ->method(
'getApiUrl')
115 ->willReturn(self::$dummy);
117 $this->dataEncoder->expects($this->once())
119 ->with($this->equalTo($param))
122 $this->client->expects($this->once())
123 ->method(
'setRawData')
124 ->with($this->equalTo($json),
'application/json')
127 $client = $this->httpClient->create(
'url',
'method', $param,
$storeId);
129 $this->assertInstanceOf(ZendClient::class, $client);