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
|
|
|
public function testLoginEncFlow()
|
29
|
|
|
{
|
30
|
|
|
$config = $this->getConfig();
|
31
|
|
|
|
32
|
|
|
$soapClient = $this->getMockBuilder(SoapClient::class)
|
33
|
|
|
->disableOriginalConstructor()
|
34
|
|
|
->setMethods(['doLoginEnc', 'doQuerySysStatus', 'doSomethingAfterLogin'])
|
35
|
|
|
->getMock();
|
36
|
|
|
|
37
|
|
|
//Allegro version key should be requested for first login per request
|
38
|
|
|
$soapClient->expects($this->once())
|
39
|
|
|
->method('doQuerySysStatus')
|
40
|
|
|
->willReturn((object)['verKey' => 'someVersionKey']);
|
41
|
|
|
|
42
|
|
|
//login
|
43
|
|
|
$soapClient->expects($this->once())
|
44
|
|
|
->method('doLoginEnc')
|
45
|
|
|
->willReturn((object)['sessionHandlePart' => 'foo', 'userId' => 'bar']);
|
46
|
|
|
|
47
|
|
|
$client = new Client($config, $soapClient);
|
48
|
|
|
|
49
|
|
|
//check session handle
|
50
|
|
|
$soapClient->expects($this->once())
|
51
|
|
|
->method('doSomethingAfterLogin')
|
52
|
|
|
->with($this->equalTo([
|
53
|
|
|
'webapiKey' => $this->defaultConfigParams['apiKey'],
|
54
|
|
|
'localVersion' => 'someVersionKey',
|
55
|
|
|
'countryId' => $this->defaultConfigParams['countryCode'],
|
56
|
|
|
'sessionId' => 'foo',
|
57
|
|
|
'countryCode' => $this->defaultConfigParams['countryCode'],
|
58
|
|
|
'sessionHandle' => 'foo',
|
59
|
|
|
'someFakeRequestParam' => 'someFakeRequestValue'
|
60
|
|
|
]));
|
61
|
|
|
|
62
|
|
|
$client->somethingAfterLogin(['someFakeRequestParam' => 'someFakeRequestValue']);
|
|
|
|
|
63
|
|
|
|
64
|
|
|
}
|
65
|
|
|
}
|
66
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: