16 use Psr\Log\LoggerInterface;
23 private $signUpCommand;
28 private $analyticsTokenMock;
33 private $integrationManagerMock;
38 private $integrationToken;
48 private $httpClientMock;
58 private $responseResolverMock;
65 $this->analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class)
66 ->disableOriginalConstructor()
68 $this->integrationManagerMock = $this->getMockBuilder(IntegrationManager::class)
69 ->disableOriginalConstructor()
71 $this->integrationToken = $this->getMockBuilder(IntegrationToken::class)
72 ->disableOriginalConstructor()
74 $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class)
75 ->disableOriginalConstructor()
77 $this->httpClientMock = $this->getMockBuilder(ClientInterface::class)
78 ->disableOriginalConstructor()
80 $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
81 ->disableOriginalConstructor()
83 $this->responseResolverMock = $this->getMockBuilder(ResponseResolver::class)
84 ->disableOriginalConstructor()
88 $this->analyticsTokenMock,
89 $this->integrationManagerMock,
91 $this->httpClientMock,
93 $this->responseResolverMock
103 $this->integrationManagerMock->expects($this->once())
104 ->method(
'generateToken')
105 ->willReturn($this->integrationToken);
106 $this->integrationManagerMock->expects($this->once())
107 ->method(
'activateIntegration')
109 $data = $this->getTestData();
111 $this->configMock->expects($this->any())
113 ->willReturn(
$data[
'url']);
114 $this->integrationToken->expects($this->any())
117 ->willReturn(
$data[
'integration-token']);
118 $httpResponse = new \Zend_Http_Response(201, [],
'{"access-token": "' .
$data[
'access-token'] .
'"}');
119 $this->httpClientMock->expects($this->once())
126 ->willReturn($httpResponse);
127 $this->responseResolverMock->expects($this->any())
128 ->method(
'getResult')
129 ->with($httpResponse)
131 $this->assertTrue($this->signUpCommand->execute());
139 $this->integrationManagerMock->expects($this->once())
140 ->method(
'generateToken')
142 $this->integrationManagerMock->expects($this->never())
143 ->method(
'activateIntegration');
144 $this->assertFalse($this->signUpCommand->execute());
153 $this->integrationManagerMock->expects($this->once())
154 ->method(
'generateToken')
155 ->willReturn($this->integrationToken);
156 $this->integrationManagerMock->expects($this->once())
157 ->method(
'activateIntegration')
159 $httpResponse = new \Zend_Http_Response(0, []);
160 $this->httpClientMock->expects($this->once())
162 ->willReturn($httpResponse);
163 $this->responseResolverMock->expects($this->any())
164 ->method(
'getResult')
166 $this->assertFalse($this->signUpCommand->execute());
174 private function getTestData()
177 'url' =>
'http://www.mystore.com',
178 'access-token' =>
'thisisaccesstoken',
179 'integration-token' =>
'thisisintegrationtoken',
181 'body'=> [
'token' =>
'thisisintegrationtoken',
'url' =>
'http://www.mystore.com'],
testExecuteFailureCannotGenerateToken()
testExecuteFailureResponseIsEmpty()