|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
namespace Radowoj\Yaah;
|
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase;
|
|
6
|
|
|
use Radowoj\Yaah\Config;
|
|
7
|
|
|
use Radowoj\Yaah\Client;
|
|
8
|
|
|
|
|
9
|
|
|
use SoapClient;
|
|
10
|
|
|
|
|
11
|
|
|
class ClientTest extends TestCase
|
|
12
|
|
|
{
|
|
13
|
|
|
|
|
14
|
|
|
protected $defaultConfigParams = [
|
|
15
|
|
|
'apiKey' => 'some api key',
|
|
16
|
|
|
'login' => 'someLogin',
|
|
17
|
|
|
'passwordHash' => 'passwordHash',
|
|
18
|
|
|
'isSandbox' => true,
|
|
19
|
|
|
'countryCode' => 1,
|
|
20
|
|
|
];
|
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
protected function getConfig()
|
|
24
|
|
|
{
|
|
25
|
|
|
return new Config($this->defaultConfigParams);
|
|
26
|
|
|
}
|
|
27
|
|
|
|
|
28
|
|
|
protected function getPlainPasswordConfig()
|
|
29
|
|
|
{
|
|
30
|
|
|
$params = $this->defaultConfigParams;
|
|
31
|
|
|
$params['passwordHash'] = '';
|
|
32
|
|
|
|
|
33
|
|
|
$config = new Config($params);
|
|
34
|
|
|
$config->setPasswordPlain('somePasswordPlain');
|
|
35
|
|
|
return $config;
|
|
36
|
|
|
}
|
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
View Code Duplication |
public function testLoginEncFlow()
|
|
|
|
|
|
|
40
|
|
|
{
|
|
41
|
|
|
$config = $this->getConfig();
|
|
42
|
|
|
|
|
43
|
|
|
$soapClient = $this->getMockBuilder(SoapClient::class)
|
|
44
|
|
|
->disableOriginalConstructor()
|
|
45
|
|
|
->setMethods(['doLoginEnc', 'doQuerySysStatus', 'doSomethingAfterLogin'])
|
|
46
|
|
|
->getMock();
|
|
47
|
|
|
|
|
48
|
|
|
//Allegro version key should be requested for first login per request
|
|
49
|
|
|
$soapClient->expects($this->once())
|
|
50
|
|
|
->method('doQuerySysStatus')
|
|
51
|
|
|
->willReturn((object)['verKey' => 'someVersionKey']);
|
|
52
|
|
|
|
|
53
|
|
|
//login
|
|
54
|
|
|
$soapClient->expects($this->once())
|
|
55
|
|
|
->method('doLoginEnc')
|
|
56
|
|
|
->willReturn((object)['sessionHandlePart' => 'foo', 'userId' => 'bar']);
|
|
57
|
|
|
|
|
58
|
|
|
$client = new Client($config, $soapClient);
|
|
59
|
|
|
|
|
60
|
|
|
//check session handle
|
|
61
|
|
|
$soapClient->expects($this->once())
|
|
62
|
|
|
->method('doSomethingAfterLogin')
|
|
63
|
|
|
->with($this->equalTo([
|
|
64
|
|
|
'webapiKey' => $this->defaultConfigParams['apiKey'],
|
|
65
|
|
|
'localVersion' => 'someVersionKey',
|
|
66
|
|
|
'countryId' => $this->defaultConfigParams['countryCode'],
|
|
67
|
|
|
'sessionId' => 'foo',
|
|
68
|
|
|
'countryCode' => $this->defaultConfigParams['countryCode'],
|
|
69
|
|
|
'sessionHandle' => 'foo',
|
|
70
|
|
|
'someFakeRequestParam' => 'someFakeRequestValue'
|
|
71
|
|
|
]));
|
|
72
|
|
|
|
|
73
|
|
|
$client->somethingAfterLogin(['someFakeRequestParam' => 'someFakeRequestValue']);
|
|
|
|
|
|
|
74
|
|
|
}
|
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
View Code Duplication |
public function testLoginFlow()
|
|
|
|
|
|
|
78
|
|
|
{
|
|
79
|
|
|
$config = $this->getPlainPasswordConfig();
|
|
80
|
|
|
|
|
81
|
|
|
$soapClient = $this->getMockBuilder(SoapClient::class)
|
|
82
|
|
|
->disableOriginalConstructor()
|
|
83
|
|
|
->setMethods(['doLogin', 'doQuerySysStatus', 'doSomethingAfterLogin'])
|
|
84
|
|
|
->getMock();
|
|
85
|
|
|
|
|
86
|
|
|
//Allegro version key should be requested for first login per request
|
|
87
|
|
|
$soapClient->expects($this->once())
|
|
88
|
|
|
->method('doQuerySysStatus')
|
|
89
|
|
|
->willReturn((object)['verKey' => 'someVersionKey']);
|
|
90
|
|
|
|
|
91
|
|
|
//login
|
|
92
|
|
|
$soapClient->expects($this->once())
|
|
93
|
|
|
->method('doLogin')
|
|
94
|
|
|
->willReturn((object)['sessionHandlePart' => 'foo', 'userId' => 'bar']);
|
|
95
|
|
|
|
|
96
|
|
|
$client = new Client($config, $soapClient);
|
|
97
|
|
|
|
|
98
|
|
|
//check session handle
|
|
99
|
|
|
$soapClient->expects($this->once())
|
|
100
|
|
|
->method('doSomethingAfterLogin')
|
|
101
|
|
|
->with($this->equalTo([
|
|
102
|
|
|
'webapiKey' => $this->defaultConfigParams['apiKey'],
|
|
103
|
|
|
'localVersion' => 'someVersionKey',
|
|
104
|
|
|
'countryId' => $this->defaultConfigParams['countryCode'],
|
|
105
|
|
|
'sessionId' => 'foo',
|
|
106
|
|
|
'countryCode' => $this->defaultConfigParams['countryCode'],
|
|
107
|
|
|
'sessionHandle' => 'foo',
|
|
108
|
|
|
'someFakeRequestParam' => 'someFakeRequestValue'
|
|
109
|
|
|
]));
|
|
110
|
|
|
|
|
111
|
|
|
$client->somethingAfterLogin(['someFakeRequestParam' => 'someFakeRequestValue']);
|
|
|
|
|
|
|
112
|
|
|
}
|
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
/**
|
|
116
|
|
|
* @expectedException Radowoj\Yaah\Exception
|
|
117
|
|
|
* @expectedExceptionMessage Invalid WebAPI doLogin[Enc]() response
|
|
118
|
|
|
*/
|
|
119
|
|
View Code Duplication |
public function testExceptionOnInvalidLoginResponseMissingUserId()
|
|
|
|
|
|
|
120
|
|
|
{
|
|
121
|
|
|
$config = $this->getConfig();
|
|
122
|
|
|
|
|
123
|
|
|
$soapClient = $this->getMockBuilder(SoapClient::class)
|
|
124
|
|
|
->disableOriginalConstructor()
|
|
125
|
|
|
->setMethods(['doLoginEnc', 'doQuerySysStatus', 'doSomethingAfterLogin'])
|
|
126
|
|
|
->getMock();
|
|
127
|
|
|
|
|
128
|
|
|
//Allegro version key should be requested for first login per request
|
|
129
|
|
|
$soapClient->expects($this->once())
|
|
130
|
|
|
->method('doQuerySysStatus')
|
|
131
|
|
|
->willReturn((object)['verKey' => 'someVersionKey']);
|
|
132
|
|
|
|
|
133
|
|
|
//login
|
|
134
|
|
|
$soapClient->expects($this->once())
|
|
135
|
|
|
->method('doLoginEnc')
|
|
136
|
|
|
->willReturn((object)['sessionHandlePart' => 'foo']);
|
|
137
|
|
|
|
|
138
|
|
|
$client = new Client($config, $soapClient);
|
|
|
|
|
|
|
139
|
|
|
}
|
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
/**
|
|
143
|
|
|
* @expectedException Radowoj\Yaah\Exception
|
|
144
|
|
|
* @expectedExceptionMessage Invalid WebAPI doLogin[Enc]() response
|
|
145
|
|
|
*/
|
|
146
|
|
View Code Duplication |
public function testExceptionOnInvalidLoginResponseMissingSessionHandlePart()
|
|
|
|
|
|
|
147
|
|
|
{
|
|
148
|
|
|
$config = $this->getConfig();
|
|
149
|
|
|
|
|
150
|
|
|
$soapClient = $this->getMockBuilder(SoapClient::class)
|
|
151
|
|
|
->disableOriginalConstructor()
|
|
152
|
|
|
->setMethods(['doLoginEnc', 'doQuerySysStatus', 'doSomethingAfterLogin'])
|
|
153
|
|
|
->getMock();
|
|
154
|
|
|
|
|
155
|
|
|
//Allegro version key should be requested for first login per request
|
|
156
|
|
|
$soapClient->expects($this->once())
|
|
157
|
|
|
->method('doQuerySysStatus')
|
|
158
|
|
|
->willReturn((object)['verKey' => 'someVersionKey']);
|
|
159
|
|
|
|
|
160
|
|
|
//login
|
|
161
|
|
|
$soapClient->expects($this->once())
|
|
162
|
|
|
->method('doLoginEnc')
|
|
163
|
|
|
->willReturn((object)['userId' => 'bar']);
|
|
164
|
|
|
|
|
165
|
|
|
$client = new Client($config, $soapClient);
|
|
|
|
|
|
|
166
|
|
|
}
|
|
167
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
/**
|
|
170
|
|
|
* @expectedException Radowoj\Yaah\Exception
|
|
171
|
|
|
* @expectedExceptionMessage Invalid WebAPI doQuerySysStatus() response
|
|
172
|
|
|
*/
|
|
173
|
|
|
public function testExceptionOnInvalidQuerySysStatusResponse()
|
|
174
|
|
|
{
|
|
175
|
|
|
$config = $this->getConfig();
|
|
176
|
|
|
|
|
177
|
|
|
$soapClient = $this->getMockBuilder(SoapClient::class)
|
|
178
|
|
|
->disableOriginalConstructor()
|
|
179
|
|
|
->setMethods(['doQuerySysStatus', 'doSomethingAfterLogin'])
|
|
180
|
|
|
->getMock();
|
|
181
|
|
|
|
|
182
|
|
|
//Allegro version key should be requested for first login per request
|
|
183
|
|
|
$soapClient->expects($this->once())
|
|
184
|
|
|
->method('doQuerySysStatus')
|
|
185
|
|
|
->willReturn((object)['trololo' => 'thisIsNotAVersionKey']);
|
|
186
|
|
|
|
|
187
|
|
|
$client = new Client($config, $soapClient);
|
|
|
|
|
|
|
188
|
|
|
}
|
|
189
|
|
|
|
|
190
|
|
|
|
|
191
|
|
|
|
|
192
|
|
|
}
|
|
193
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.